add --declaredlocs (#15666)

This commit is contained in:
Timothee Cour 2020-10-21 06:37:29 -07:00 • committed by GitHub
commit 05752cd5d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 11 deletions

View file

@ -11,7 +11,7 @@
## Compiler changes ## Compiler changes
add `--declaredlocs` to show symbol declaration location in messages
## Tool changes ## Tool changes

View file

@ -794,6 +794,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
processOnOffSwitchG(conf, {optStdout}, arg, pass, info) processOnOffSwitchG(conf, {optStdout}, arg, pass, info)
of "listfullpaths": of "listfullpaths":
processOnOffSwitchG(conf, {optListFullPaths}, arg, pass, info) processOnOffSwitchG(conf, {optListFullPaths}, arg, pass, info)
of "declaredlocs":
processOnOffSwitchG(conf, {optDeclaredLocs}, arg, pass, info)
of "dynliboverride": of "dynliboverride":
dynlibOverride(conf, switch, arg, pass, info) dynlibOverride(conf, switch, arg, pass, info)
of "dynliboverrideall": of "dynliboverrideall":

View file

@ -69,6 +69,7 @@ type
hintUser, hintUserRaw, hintUser, hintUserRaw,
hintExtendedContext, hintExtendedContext,
hintMsgOrigin, # since 1.3.5 hintMsgOrigin, # since 1.3.5
hintDeclaredLoc, # since 1.5.1
const const
MsgKindToStr*: array[TMsgKind, string] = [ MsgKindToStr*: array[TMsgKind, string] = [
@ -159,6 +160,7 @@ const
hintUserRaw: "$1", hintUserRaw: "$1",
hintExtendedContext: "$1", hintExtendedContext: "$1",
hintMsgOrigin: "$1", hintMsgOrigin: "$1",
hintDeclaredLoc: "$1",
] ]
const const
@ -186,7 +188,7 @@ const
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf", "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency", "Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro", "Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
"User", "UserRaw", "ExtendedContext", "MsgOrigin", "User", "UserRaw", "ExtendedContext", "MsgOrigin", "DeclaredLoc"
] ]
const const
@ -215,7 +217,7 @@ type
proc computeNotesVerbosity(): array[0..3, TNoteKinds] = proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores} result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores}
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext} result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext, hintDeclaredLoc}
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} hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}

View file

@ -81,6 +81,7 @@ type # please make sure we have under 32 options
optDocInternal # generate documentation for non-exported symbols optDocInternal # generate documentation for non-exported symbols
optMixedMode # true if some module triggered C++ codegen optMixedMode # true if some module triggered C++ codegen
optListFullPaths # use full paths in toMsgFilename optListFullPaths # use full paths in toMsgFilename
optDeclaredLocs # show declaration locations in messages
optNoNimblePath optNoNimblePath
optHotCodeReloading optHotCodeReloading
optDynlibOverrideAll optDynlibOverrideAll

View file

@ -208,6 +208,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
{renderNoBody, renderNoComments, renderNoPragmas})) {renderNoBody, renderNoComments, renderNoPragmas}))
else: else:
candidates.add(getProcHeader(c.config, err.sym, prefer)) candidates.add(getProcHeader(c.config, err.sym, prefer))
candidates.addDeclaredLocMaybe(c.config, err.sym)
candidates.add("\n") candidates.add("\n")
let nArg = if err.firstMismatch.arg < n.len: n[err.firstMismatch.arg] else: nil let nArg = if err.firstMismatch.arg < n.len: n[err.firstMismatch.arg] else: nil
let nameParam = if err.firstMismatch.formal != nil: err.firstMismatch.formal.name.s else: "" let nameParam = if err.firstMismatch.formal != nil: err.firstMismatch.formal.name.s else: ""
@ -230,9 +231,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
doAssert err.firstMismatch.formal != nil doAssert err.firstMismatch.formal != nil
candidates.add("\n required type for " & nameParam & ": ") candidates.add("\n required type for " & nameParam & ": ")
candidates.add typeToString(wanted) candidates.add typeToString(wanted)
when false:
if wanted.sym != nil: if wanted.sym != nil:
candidates.add "(" & (c.config $ wanted.sym.info) & ")" candidates.addDeclaredLocMaybe(c.config, wanted.sym)
candidates.add "\n but expression '" candidates.add "\n but expression '"
if err.firstMismatch.kind == kVarNeeded: if err.firstMismatch.kind == kVarNeeded:
candidates.add renderNotLValue(nArg) candidates.add renderNotLValue(nArg)
@ -242,9 +242,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
candidates.add "' is of type: " candidates.add "' is of type: "
var got = nArg.typ var got = nArg.typ
candidates.add typeToString(got) candidates.add typeToString(got)
when false:
if got.sym != nil: if got.sym != nil:
candidates.add "(" & (c.config $ got.sym.info) & ")" candidates.addDeclaredLocMaybe(c.config, got.sym)
doAssert wanted != nil doAssert wanted != nil
if got != nil: effectProblem(wanted, got, candidates, c) if got != nil: effectProblem(wanted, got, candidates, c)

View file

@ -123,8 +123,13 @@ proc isIntLit*(t: PType): bool {.inline.} =
proc isFloatLit*(t: PType): bool {.inline.} = proc isFloatLit*(t: PType): bool {.inline.} =
result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit
proc addDeclaredLoc(result: var string, conf: ConfigRef; sym: PSym) = proc addDeclaredLoc*(result: var string, conf: ConfigRef; sym: PSym) =
result.add " [declared in " & conf$sym.info & "]" # result.add " [declared in " & conf$sym.info & "]"
result.add " [declared in " & toFileLineCol(conf, sym.info) & "]"
proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; sym: PSym) =
if optDeclaredLocs in conf.globalOptions:
addDeclaredLoc(result, conf, sym)
proc addTypeHeader*(result: var string, conf: ConfigRef; typ: PType; prefer: TPreferedDesc = preferMixed; getDeclarationPath = true) = proc addTypeHeader*(result: var string, conf: ConfigRef; typ: PType; prefer: TPreferedDesc = preferMixed; getDeclarationPath = true) =
result.add typeToString(typ, prefer) result.add typeToString(typ, prefer)

View file

@ -35,6 +35,7 @@ Advanced options:
--stdout:on|off output to stdout --stdout:on|off output to stdout
--colors:on|off turn compiler messages coloring on|off --colors:on|off turn compiler messages coloring on|off
--listFullPaths:on|off list full paths in messages --listFullPaths:on|off list full paths in messages
--declaredlocs:on|off show declaration locations in messages
-w:on|off|list, --warnings:on|off|list -w:on|off|list, --warnings:on|off|list
turn all warnings on|off or list all available turn all warnings on|off or list all available
--warning[X]:on|off turn specific warning X on|off --warning[X]:on|off turn specific warning X on|off