Skip to content

Commit

Permalink
improvements to hint:processing: show import stack, distinguish nims,…
Browse files Browse the repository at this point in the history
… show includes etc (nim-lang#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
  • Loading branch information
timotheecour authored and PMunch committed Mar 28, 2022
1 parent f86a3d8 commit 4fe2dd8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
5 changes: 3 additions & 2 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type
hintXDeclaredButNotUsed = "XDeclaredButNotUsed", hintDuplicateModuleImport = "DuplicateModuleImport",
hintXCannotRaiseY = "XCannotRaiseY", hintConvToBaseNotNeeded = "ConvToBaseNotNeeded",
hintConvFromXtoItselfNotNeeded = "ConvFromXtoItselfNotNeeded", hintExprAlwaysX = "ExprAlwaysX",
hintQuitCalled = "QuitCalled", hintProcessing = "Processing", hintCodeBegin = "CodeBegin",
hintQuitCalled = "QuitCalled", hintProcessing = "Processing", hintProcessingStmt = "ProcessingStmt", hintCodeBegin = "CodeBegin",
hintCodeEnd = "CodeEnd", hintConf = "Conf", hintPath = "Path",
hintConditionAlwaysTrue = "CondTrue", hintConditionAlwaysFalse = "CondFalse", hintName = "Name",
hintPattern = "Pattern", hintExecuting = "Exec", hintLinking = "Link", hintDependency = "Dependency",
Expand Down Expand Up @@ -163,6 +163,7 @@ const
hintExprAlwaysX: "expression evaluates always to '$1'",
hintQuitCalled: "quit() called",
hintProcessing: "$1",
hintProcessingStmt: "$1",
hintCodeBegin: "generated code listing:",
hintCodeEnd: "end of listing",
hintConf: "used config file '$1'",
Expand Down Expand Up @@ -202,7 +203,7 @@ type

proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
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,
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin, hintPerformance}
Expand Down
12 changes: 12 additions & 0 deletions compiler/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,15 @@ proc moduleFromRodFile*(g: ModuleGraph; fileIdx: FileIndex;

proc configComplete*(g: ModuleGraph) =
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])
11 changes: 6 additions & 5 deletions compiler/modules.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
partialInitModule(result, graph, fileIdx, filename)
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
if fileIdx == graph.config.projectMainIdx2: flags.incl sfMainModule
result = graph.getModule(fileIdx)

template processModuleAux =
template processModuleAux(moduleStatus) =
onProcessing(graph, fileIdx, moduleStatus, fromModule = fromModule)
var s: PLLStream
if sfMainModule in flags:
if graph.config.projectIsStdin: s = stdin.llStreamOpen
Expand All @@ -103,7 +104,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): P
result = newModule(graph, fileIdx)
result.flags.incl flags
registerModule(graph, result)
processModuleAux()
processModuleAux("import")
else:
if sfSystemModule in flags:
graph.systemModule = result
Expand All @@ -117,13 +118,13 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): P
# reset module fields:
initStrTables(graph, result)
result.ast = nil
processModuleAux()
processModuleAux("import(dirty)")
graph.markClientsDirty(fileIdx)

proc importModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PSym =
# this is called by the semantic checking phase
assert graph.config != nil
result = compileModule(graph, fileIdx, {})
result = compileModule(graph, fileIdx, {}, s)
graph.addDep(s, fileIdx)
# keep track of import relationships
if graph.config.hcrOn:
Expand Down
13 changes: 4 additions & 9 deletions compiler/passaux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ type
config: ConfigRef

proc verboseOpen(graph: ModuleGraph; s: PSym; idgen: IdGenerator): PPassContext =
let conf = graph.config
result = VerboseRef(config: conf, idgen: idgen)
let path = toFilenameOption(conf, s.position.FileIndex, conf.filenameOption)
rawMessage(conf, hintProcessing, path)
# xxx consider either removing this or keeping for documentation for how to add a pass
result = VerboseRef(config: graph.config, idgen: idgen)

proc verboseProcess(context: PPassContext, n: PNode): PNode =
# called from `process` in `processTopLevelStmt`.
result = n
let v = VerboseRef(context)
if v.config.verbosity == 3:
# 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[])
message(v.config, n.info, hintProcessingStmt, $v.idgen[])

const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)
1 change: 1 addition & 0 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
var f = checkModuleName(c.config, it)
if f != InvalidFileIdx:
addIncludeFileDep(c, f)
onProcessing(c.graph, f, "include", c.module)
if containsOrIncl(c.includedFiles, f.int):
localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
else:
Expand Down
2 changes: 1 addition & 1 deletion nimsuggest/tests/tchk1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc main =
discard """
$nimsuggest --tester $file
>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;;14;;0;;"nestable statement requires indentation";;0
chk;;skUnknown;;;;Error;;$file;;12;;0;;"implementation of \'foo\' expected";;0
Expand Down
2 changes: 1 addition & 1 deletion nimsuggest/tests/tchk_compiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ discard compiles(2 + "hello")
discard """
$nimsuggest --tester $file
>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
"""
2 changes: 1 addition & 1 deletion nimsuggest/tests/ttempl_inst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ foo()
discard """
$nimsuggest --tester $file
>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;;;;Warning;;$file;;2;;11;;"foo [User]";;0
"""

0 comments on commit 4fe2dd8

Please sign in to comment.