improvements to hint:processing: show import stack, distinguish nims, show includes etc (#18372)
* improvements to hint:processing * fix tests; do not show hintProcessing for nimscript unless given -d:nimHintProcessingNims * fix trunner and avoid need for -d:nimHintProcessingNims * fix some tests
This commit is contained in:
parent
afe5eb569b
commit
0483a5ffaf
8 changed files with 29 additions and 19 deletions
|
|
@ -75,7 +75,7 @@ type
|
||||||
hintXDeclaredButNotUsed = "XDeclaredButNotUsed", hintDuplicateModuleImport = "DuplicateModuleImport",
|
hintXDeclaredButNotUsed = "XDeclaredButNotUsed", hintDuplicateModuleImport = "DuplicateModuleImport",
|
||||||
hintXCannotRaiseY = "XCannotRaiseY", hintConvToBaseNotNeeded = "ConvToBaseNotNeeded",
|
hintXCannotRaiseY = "XCannotRaiseY", hintConvToBaseNotNeeded = "ConvToBaseNotNeeded",
|
||||||
hintConvFromXtoItselfNotNeeded = "ConvFromXtoItselfNotNeeded", hintExprAlwaysX = "ExprAlwaysX",
|
hintConvFromXtoItselfNotNeeded = "ConvFromXtoItselfNotNeeded", hintExprAlwaysX = "ExprAlwaysX",
|
||||||
hintQuitCalled = "QuitCalled", hintProcessing = "Processing", hintCodeBegin = "CodeBegin",
|
hintQuitCalled = "QuitCalled", hintProcessing = "Processing", hintProcessingStmt = "ProcessingStmt", hintCodeBegin = "CodeBegin",
|
||||||
hintCodeEnd = "CodeEnd", hintConf = "Conf", hintPath = "Path",
|
hintCodeEnd = "CodeEnd", hintConf = "Conf", hintPath = "Path",
|
||||||
hintConditionAlwaysTrue = "CondTrue", hintConditionAlwaysFalse = "CondFalse", hintName = "Name",
|
hintConditionAlwaysTrue = "CondTrue", hintConditionAlwaysFalse = "CondFalse", hintName = "Name",
|
||||||
hintPattern = "Pattern", hintExecuting = "Exec", hintLinking = "Link", hintDependency = "Dependency",
|
hintPattern = "Pattern", hintExecuting = "Exec", hintLinking = "Link", hintDependency = "Dependency",
|
||||||
|
|
@ -163,6 +163,7 @@ const
|
||||||
hintExprAlwaysX: "expression evaluates always to '$1'",
|
hintExprAlwaysX: "expression evaluates always to '$1'",
|
||||||
hintQuitCalled: "quit() called",
|
hintQuitCalled: "quit() called",
|
||||||
hintProcessing: "$1",
|
hintProcessing: "$1",
|
||||||
|
hintProcessingStmt: "$1",
|
||||||
hintCodeBegin: "generated code listing:",
|
hintCodeBegin: "generated code listing:",
|
||||||
hintCodeEnd: "end of listing",
|
hintCodeEnd: "end of listing",
|
||||||
hintConf: "used config file '$1'",
|
hintConf: "used config file '$1'",
|
||||||
|
|
@ -202,7 +203,7 @@ type
|
||||||
|
|
||||||
proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
||||||
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores, warnResultUsed}
|
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores, warnResultUsed}
|
||||||
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext, hintDeclaredLoc}
|
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext, hintDeclaredLoc, hintProcessingStmt}
|
||||||
result[1] = result[2] - {warnProveField, warnProveIndex,
|
result[1] = result[2] - {warnProveField, warnProveIndex,
|
||||||
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
||||||
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin, hintPerformance}
|
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin, hintPerformance}
|
||||||
|
|
|
||||||
|
|
@ -582,3 +582,15 @@ proc moduleFromRodFile*(g: ModuleGraph; fileIdx: FileIndex;
|
||||||
|
|
||||||
proc configComplete*(g: ModuleGraph) =
|
proc configComplete*(g: ModuleGraph) =
|
||||||
rememberStartupConfig(g.startupPackedConfig, g.config)
|
rememberStartupConfig(g.startupPackedConfig, g.config)
|
||||||
|
|
||||||
|
from std/strutils import repeat, `%`
|
||||||
|
|
||||||
|
proc onProcessing*(graph: ModuleGraph, fileIdx: FileIndex, moduleStatus: string, fromModule: PSym, ) =
|
||||||
|
let conf = graph.config
|
||||||
|
let isNimscript = conf.isDefined("nimscript")
|
||||||
|
if (not isNimscript) or hintProcessing in conf.cmdlineNotes:
|
||||||
|
let path = toFilenameOption(conf, fileIdx, conf.filenameOption)
|
||||||
|
let indent = ">".repeat(graph.importStack.len)
|
||||||
|
let fromModule2 = if fromModule != nil: $fromModule.name.s else: "(toplevel)"
|
||||||
|
let mode = if isNimscript: "(nims) " else: ""
|
||||||
|
rawMessage(conf, hintProcessing, "$#$# $#: $#: $#" % [mode, indent, fromModule2, moduleStatus, path])
|
||||||
|
|
|
||||||
|
|
@ -84,12 +84,13 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
|
||||||
partialInitModule(result, graph, fileIdx, filename)
|
partialInitModule(result, graph, fileIdx, filename)
|
||||||
graph.registerModule(result)
|
graph.registerModule(result)
|
||||||
|
|
||||||
proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): PSym =
|
proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags, fromModule: PSym = nil): PSym =
|
||||||
var flags = flags
|
var flags = flags
|
||||||
if fileIdx == graph.config.projectMainIdx2: flags.incl sfMainModule
|
if fileIdx == graph.config.projectMainIdx2: flags.incl sfMainModule
|
||||||
result = graph.getModule(fileIdx)
|
result = graph.getModule(fileIdx)
|
||||||
|
|
||||||
template processModuleAux =
|
template processModuleAux(moduleStatus) =
|
||||||
|
onProcessing(graph, fileIdx, moduleStatus, fromModule = fromModule)
|
||||||
var s: PLLStream
|
var s: PLLStream
|
||||||
if sfMainModule in flags:
|
if sfMainModule in flags:
|
||||||
if graph.config.projectIsStdin: s = stdin.llStreamOpen
|
if graph.config.projectIsStdin: s = stdin.llStreamOpen
|
||||||
|
|
@ -103,7 +104,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): P
|
||||||
result = newModule(graph, fileIdx)
|
result = newModule(graph, fileIdx)
|
||||||
result.flags.incl flags
|
result.flags.incl flags
|
||||||
registerModule(graph, result)
|
registerModule(graph, result)
|
||||||
processModuleAux()
|
processModuleAux("import")
|
||||||
else:
|
else:
|
||||||
if sfSystemModule in flags:
|
if sfSystemModule in flags:
|
||||||
graph.systemModule = result
|
graph.systemModule = result
|
||||||
|
|
@ -117,13 +118,13 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): P
|
||||||
# reset module fields:
|
# reset module fields:
|
||||||
initStrTables(graph, result)
|
initStrTables(graph, result)
|
||||||
result.ast = nil
|
result.ast = nil
|
||||||
processModuleAux()
|
processModuleAux("import(dirty)")
|
||||||
graph.markClientsDirty(fileIdx)
|
graph.markClientsDirty(fileIdx)
|
||||||
|
|
||||||
proc importModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PSym =
|
proc importModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PSym =
|
||||||
# this is called by the semantic checking phase
|
# this is called by the semantic checking phase
|
||||||
assert graph.config != nil
|
assert graph.config != nil
|
||||||
result = compileModule(graph, fileIdx, {})
|
result = compileModule(graph, fileIdx, {}, s)
|
||||||
graph.addDep(s, fileIdx)
|
graph.addDep(s, fileIdx)
|
||||||
# keep track of import relationships
|
# keep track of import relationships
|
||||||
if graph.config.hcrOn:
|
if graph.config.hcrOn:
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,13 @@ type
|
||||||
config: ConfigRef
|
config: ConfigRef
|
||||||
|
|
||||||
proc verboseOpen(graph: ModuleGraph; s: PSym; idgen: IdGenerator): PPassContext =
|
proc verboseOpen(graph: ModuleGraph; s: PSym; idgen: IdGenerator): PPassContext =
|
||||||
let conf = graph.config
|
# xxx consider either removing this or keeping for documentation for how to add a pass
|
||||||
result = VerboseRef(config: conf, idgen: idgen)
|
result = VerboseRef(config: graph.config, idgen: idgen)
|
||||||
let path = toFilenameOption(conf, s.position.FileIndex, conf.filenameOption)
|
|
||||||
rawMessage(conf, hintProcessing, path)
|
|
||||||
|
|
||||||
proc verboseProcess(context: PPassContext, n: PNode): PNode =
|
proc verboseProcess(context: PPassContext, n: PNode): PNode =
|
||||||
|
# called from `process` in `processTopLevelStmt`.
|
||||||
result = n
|
result = n
|
||||||
let v = VerboseRef(context)
|
let v = VerboseRef(context)
|
||||||
if v.config.verbosity == 3:
|
message(v.config, n.info, hintProcessingStmt, $v.idgen[])
|
||||||
# system.nim deactivates all hints, for verbosity:3 we want the processing
|
|
||||||
# messages nonetheless, so we activate them again (but honor cmdlineNotes)
|
|
||||||
v.config.setNote(hintProcessing)
|
|
||||||
message(v.config, n.info, hintProcessing, $v.idgen[])
|
|
||||||
|
|
||||||
const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)
|
const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)
|
||||||
|
|
|
||||||
|
|
@ -2158,6 +2158,7 @@ proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
|
||||||
var f = checkModuleName(c.config, it)
|
var f = checkModuleName(c.config, it)
|
||||||
if f != InvalidFileIdx:
|
if f != InvalidFileIdx:
|
||||||
addIncludeFileDep(c, f)
|
addIncludeFileDep(c, f)
|
||||||
|
onProcessing(c.graph, f, "include", c.module)
|
||||||
if containsOrIncl(c.includedFiles, f.int):
|
if containsOrIncl(c.includedFiles, f.int):
|
||||||
localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
|
localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ proc main =
|
||||||
discard """
|
discard """
|
||||||
$nimsuggest --tester $file
|
$nimsuggest --tester $file
|
||||||
>chk $1
|
>chk $1
|
||||||
chk;;skUnknown;;;;Hint;;???;;0;;-1;;"tests/tchk1.nim [Processing]";;0
|
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tchk1.nim [Processing]";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;12;;0;;"identifier expected, but got \'keyword template\'";;0
|
chk;;skUnknown;;;;Error;;$file;;12;;0;;"identifier expected, but got \'keyword template\'";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;14;;0;;"nestable statement requires indentation";;0
|
chk;;skUnknown;;;;Error;;$file;;14;;0;;"nestable statement requires indentation";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;12;;0;;"implementation of \'foo\' expected";;0
|
chk;;skUnknown;;;;Error;;$file;;12;;0;;"implementation of \'foo\' expected";;0
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ discard compiles(2 + "hello")
|
||||||
discard """
|
discard """
|
||||||
$nimsuggest --tester $file
|
$nimsuggest --tester $file
|
||||||
>chk $1
|
>chk $1
|
||||||
chk;;skUnknown;;;;Hint;;???;;0;;-1;;"tests/tchk_compiles.nim [Processing]";;0
|
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tchk_compiles.nim [Processing]";;0
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ foo()
|
||||||
discard """
|
discard """
|
||||||
$nimsuggest --tester $file
|
$nimsuggest --tester $file
|
||||||
>chk $1
|
>chk $1
|
||||||
chk;;skUnknown;;;;Hint;;???;;0;;-1;;"tests/ttempl_inst.nim [Processing]";;0
|
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/ttempl_inst.nim [Processing]";;0
|
||||||
chk;;skUnknown;;;;Hint;;$file;;4;;3;;"template/generic instantiation from here";;0
|
chk;;skUnknown;;;;Hint;;$file;;4;;3;;"template/generic instantiation from here";;0
|
||||||
chk;;skUnknown;;;;Warning;;$file;;2;;11;;"foo [User]";;0
|
chk;;skUnknown;;;;Warning;;$file;;2;;11;;"foo [User]";;0
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue