From bd90199a2fd37568a5f5a6c7c394b160b229e90c Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 26 Feb 2020 01:26:47 -0800 Subject: [PATCH] fix #8312 --hints:off and --warnings:off now honored everywhere (#13489) --- compiler/ccgstmts.nim | 2 +- compiler/extccomp.nim | 2 +- compiler/hlo.nim | 4 ++-- compiler/msgs.nim | 14 ++++++-------- compiler/nim.nim | 2 +- compiler/options.nim | 6 ++++++ compiler/semexprs.nim | 2 +- compiler/sempass2.nim | 14 +++++++------- compiler/syntaxes.nim | 2 +- 9 files changed, 26 insertions(+), 22 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index b9e26789f783..c430dd0628b0 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -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) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 7cc43d56ed91..c6f062c781d2 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -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") diff --git a/compiler/hlo.nim b/compiler/hlo.nim index 6756bdc2a38c..bb69a1477691 100644 --- a/compiler/hlo.nim +++ b/compiler/hlo.nim @@ -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 @@ -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}) & "'") diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 91fad9ac1aeb..6d1ecb2b14e4 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -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() @@ -410,8 +410,7 @@ 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 @@ -419,8 +418,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) = 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)] @@ -500,7 +498,7 @@ 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 @@ -508,7 +506,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string, 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)] @@ -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) diff --git a/compiler/nim.nim b/compiler/nim.nim index cc1dc2fe7499..b916f0d85f12 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -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: diff --git a/compiler/options.nim b/compiler/options.nim index c39ffa792b0f..7a7ab0bcd8cd 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -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.} = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 375ea1cb149b..f75642bcb9a8 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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, {}) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 82287c67584b..98ef8cf8582a 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -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: @@ -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) @@ -544,7 +544,7 @@ 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) @@ -552,7 +552,7 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode) 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) @@ -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..