Skip to content

Commit

Permalink
fix nim-lang#8312 --hints:off and --warnings:off now honored everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 25, 2020
1 parent 1cf5c28 commit 61c9d10
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
proc genStmts(p: BProc, t: PNode) =
var a: TLoc

let isPush = hintExtendedContext in p.config.notes
let isPush = p.config.hasHint(hintExtendedContext)
if isPush: pushInfoContext(p.config, t.info)
expr(p, t, a)
if isPush: popInfoContext(p.config)
Expand Down
2 changes: 1 addition & 1 deletion compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var
if optCompileOnly notin conf.globalOptions:
cmds.add(compileCmd)
let (_, name, _) = splitFile(it.cname)
prettyCmds.add(if hintCC in conf.notes: "CC: " & demanglePackageName(name) else: "")
prettyCmds.add(if conf.hasHint(hintCC): "CC: " & demanglePackageName(name) else: "")
if optGenScript in conf.globalOptions:
script.add(compileCmd)
script.add("\n")
Expand Down
4 changes: 2 additions & 2 deletions compiler/hlo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
# awful to semcheck before macro invocation, so we don't and treat
# templates and macros as immediate in this context.
var rule: string
if optHints in c.config.options and hintPattern in c.config.notes:
if c.config.hasHint(hintPattern):
rule = renderTree(n, {renderNoComments})
let s = n[0].sym
case s.kind
Expand All @@ -27,7 +27,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
result = semTemplateExpr(c, n, s, {efFromHlo})
else:
result = semDirectOp(c, n, {})
if optHints in c.config.options and hintPattern in c.config.notes:
if c.config.hasHint(hintPattern):
message(c.config, orig.info, hintPattern, rule & " --> '" &
renderTree(result, {renderNoComments}) & "'")

Expand Down
14 changes: 6 additions & 8 deletions compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ proc log*(s: string) =
close(f)

proc quit(conf: ConfigRef; msg: TMsgKind) {.gcsafe.} =
if defined(debug) or msg == errInternal or hintStackTrace in conf.notes:
if defined(debug) or msg == errInternal or conf.hasHint(hintStackTrace):
{.gcsafe.}:
if stackTraceAvailable() and isNil(conf.writelnHook):
writeStackTrace()
Expand Down Expand Up @@ -410,17 +410,15 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
color = ErrorColor
of warnMin..warnMax:
sev = Severity.Warning
if optWarns notin conf.options: return
if msg notin conf.notes: return
if not conf.hasWarn(msg): return
writeContext(conf, unknownLineInfo)
title = WarningTitle
color = WarningColor
kind = WarningsToStr[ord(msg) - ord(warnMin)]
inc(conf.warnCounter)
of hintMin..hintMax:
sev = Severity.Hint
if optHints notin conf.options: return
if msg notin conf.notes: return
if not conf.hasHint(msg): return
title = HintTitle
color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
Expand Down Expand Up @@ -500,15 +498,15 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
conf.m.lastError = info
of warnMin..warnMax:
sev = Severity.Warning
ignoreMsg = optWarns notin conf.options or msg notin conf.notes
ignoreMsg = not conf.hasWarn(msg)
if not ignoreMsg: writeContext(conf, info)
title = WarningTitle
color = WarningColor
kind = WarningsToStr[ord(msg) - ord(warnMin)]
inc(conf.warnCounter)
of hintMin..hintMax:
sev = Severity.Hint
ignoreMsg = optHints notin conf.options or msg notin conf.notes
ignoreMsg = not conf.hasHint(msg)
title = HintTitle
color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
Expand All @@ -526,7 +524,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
KindColor, `%`(KindFormat, kind))
else:
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
if hintSource in conf.notes:
if conf.hasHint(hintSource):
conf.writeSurroundingSrc(info)
handleError(conf, msg, eh, s)

Expand Down
2 changes: 1 addition & 1 deletion compiler/nim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =

self.processCmdLineAndProjectPath(conf)
if not self.loadConfigsAndRunMainCommand(cache, conf): return
if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics())
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
#echo(GC_getStatistics())
if conf.errorCounter != 0: return
when hasTinyCBackend:
Expand Down
6 changes: 6 additions & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ type
severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string

proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
optHints in conf.options and note in conf.notes

proc hasWarn*(conf: ConfigRef, note: TNoteKind): bool =
optWarns in conf.options and note in conf.notes

proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions

template depConfigFields*(fn) {.dirty.} =
Expand Down
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
result = semExpr(c, result)

proc semExprNoType(c: PContext, n: PNode): PNode =
let isPush = hintExtendedContext in c.config.notes
let isPush = c.config.hasHint(hintExtendedContext)
if isPush: pushInfoContext(c.config, n.info)
result = semExpr(c, n, {efWantStmt})
discardCheck(c, result, {})
Expand Down
14 changes: 7 additions & 7 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ proc useVar(a: PEffects, n: PNode) =
if s.guard != nil: guardGlobal(a, n, s.guard)
if {sfGlobal, sfThread} * s.flags == {sfGlobal} and
(tfHasGCedMem in s.typ.flags or s.typ.isGCedMem):
#if warnGcUnsafe in gNotes: warnAboutGcUnsafe(n)
#if a.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n)
markGcUnsafe(a, s)
markSideEffect(a, s)
else:
Expand Down Expand Up @@ -463,7 +463,7 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
mergeTags(tracked, tagSpec, n)

if notGcSafe(s.typ) and sfImportc notin s.flags:
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
markGcUnsafe(tracked, s)
if tfNoSideEffect notin s.typ.flags:
markSideEffect(tracked, s)
Expand Down Expand Up @@ -544,15 +544,15 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode)
assumeTheWorst(tracked, n, op)
# assume GcUnsafe unless in its type; 'forward' does not matter:
if notGcSafe(op) and not isOwnedProcVar(a, tracked.owner):
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
markGcUnsafe(tracked, a)
elif tfNoSideEffect notin op.flags and not isOwnedProcVar(a, tracked.owner):
markSideEffect(tracked, a)
else:
mergeEffects(tracked, effectList[exceptionEffects], n)
mergeTags(tracked, effectList[tagEffects], n)
if notGcSafe(op):
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
markGcUnsafe(tracked, a)
elif tfNoSideEffect notin op.flags:
markSideEffect(tracked, a)
Expand Down Expand Up @@ -584,7 +584,7 @@ proc trackCase(tracked: PEffects, n: PNode) =
let stringCase = skipTypes(n[0].typ,
abstractVarRange-{tyTypeDesc}).kind in {tyFloat..tyFloat128, tyString}
let interesting = not stringCase and interestingCaseExpr(n[0]) and
warnProveField in tracked.config.notes
tracked.config.hasWarn(warnProveField)
var inter: TIntersection = @[]
var toCover = 0
for i in 1..<n.len:
Expand Down Expand Up @@ -678,7 +678,7 @@ proc track(tracked: PEffects, n: PNode) =
if notGcSafe(op) and not importedFromC(a):
# and it's not a recursive call:
if not (a.kind == nkSym and a.sym == tracked.owner):
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
markGcUnsafe(tracked, a)
if tfNoSideEffect notin op.flags and not importedFromC(a):
# and it's not a recursive call:
Expand Down Expand Up @@ -779,7 +779,7 @@ proc track(tracked: PEffects, n: PNode) =
for i in 0..<n.len: track(tracked, n[i])
of nkCheckedFieldExpr:
track(tracked, n[0])
if warnProveField in tracked.config.notes:
if tracked.config.hasWarn(warnProveField):
checkFieldAccess(tracked.guards, n, tracked.config)
of nkTryStmt: trackTryStmt(tracked, n)
of nkPragma: trackPragmaStmt(tracked, n)
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntaxes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ proc applyFilter(p: var TParsers, n: PNode, filename: AbsoluteFile,
result = filterReplace(p.config, stdin, filename, n)
if f != filtNone:
assert p.config != nil
if hintCodeBegin in p.config.notes:
if p.config.hasHint(hintCodeBegin):
rawMessage(p.config, hintCodeBegin, [])
msgWriteln(p.config, result.s)
rawMessage(p.config, hintCodeEnd, [])
Expand Down

0 comments on commit 61c9d10

Please sign in to comment.