Skip to content

Commit bd90199

Browse files
authored
fix #8312 --hints:off and --warnings:off now honored everywhere (#13489)
1 parent 94b0d6b commit bd90199

File tree

9 files changed

+26
-22
lines changed

9 files changed

+26
-22
lines changed

compiler/ccgstmts.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
14121412
proc genStmts(p: BProc, t: PNode) =
14131413
var a: TLoc
14141414

1415-
let isPush = hintExtendedContext in p.config.notes
1415+
let isPush = p.config.hasHint(hintExtendedContext)
14161416
if isPush: pushInfoContext(p.config, t.info)
14171417
expr(p, t, a)
14181418
if isPush: popInfoContext(p.config)

compiler/extccomp.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var
715715
if optCompileOnly notin conf.globalOptions:
716716
cmds.add(compileCmd)
717717
let (_, name, _) = splitFile(it.cname)
718-
prettyCmds.add(if hintCC in conf.notes: "CC: " & demanglePackageName(name) else: "")
718+
prettyCmds.add(if conf.hasHint(hintCC): "CC: " & demanglePackageName(name) else: "")
719719
if optGenScript in conf.globalOptions:
720720
script.add(compileCmd)
721721
script.add("\n")

compiler/hlo.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
1717
# awful to semcheck before macro invocation, so we don't and treat
1818
# templates and macros as immediate in this context.
1919
var rule: string
20-
if optHints in c.config.options and hintPattern in c.config.notes:
20+
if c.config.hasHint(hintPattern):
2121
rule = renderTree(n, {renderNoComments})
2222
let s = n[0].sym
2323
case s.kind
@@ -27,7 +27,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
2727
result = semTemplateExpr(c, n, s, {efFromHlo})
2828
else:
2929
result = semDirectOp(c, n, {})
30-
if optHints in c.config.options and hintPattern in c.config.notes:
30+
if c.config.hasHint(hintPattern):
3131
message(c.config, orig.info, hintPattern, rule & " --> '" &
3232
renderTree(result, {renderNoComments}) & "'")
3333

compiler/msgs.nim

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ proc log*(s: string) =
340340
close(f)
341341

342342
proc quit(conf: ConfigRef; msg: TMsgKind) {.gcsafe.} =
343-
if defined(debug) or msg == errInternal or hintStackTrace in conf.notes:
343+
if defined(debug) or msg == errInternal or conf.hasHint(hintStackTrace):
344344
{.gcsafe.}:
345345
if stackTraceAvailable() and isNil(conf.writelnHook):
346346
writeStackTrace()
@@ -410,17 +410,15 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
410410
color = ErrorColor
411411
of warnMin..warnMax:
412412
sev = Severity.Warning
413-
if optWarns notin conf.options: return
414-
if msg notin conf.notes: return
413+
if not conf.hasWarn(msg): return
415414
writeContext(conf, unknownLineInfo)
416415
title = WarningTitle
417416
color = WarningColor
418417
kind = WarningsToStr[ord(msg) - ord(warnMin)]
419418
inc(conf.warnCounter)
420419
of hintMin..hintMax:
421420
sev = Severity.Hint
422-
if optHints notin conf.options: return
423-
if msg notin conf.notes: return
421+
if not conf.hasHint(msg): return
424422
title = HintTitle
425423
color = HintColor
426424
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@@ -500,15 +498,15 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
500498
conf.m.lastError = info
501499
of warnMin..warnMax:
502500
sev = Severity.Warning
503-
ignoreMsg = optWarns notin conf.options or msg notin conf.notes
501+
ignoreMsg = not conf.hasWarn(msg)
504502
if not ignoreMsg: writeContext(conf, info)
505503
title = WarningTitle
506504
color = WarningColor
507505
kind = WarningsToStr[ord(msg) - ord(warnMin)]
508506
inc(conf.warnCounter)
509507
of hintMin..hintMax:
510508
sev = Severity.Hint
511-
ignoreMsg = optHints notin conf.options or msg notin conf.notes
509+
ignoreMsg = not conf.hasHint(msg)
512510
title = HintTitle
513511
color = HintColor
514512
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@@ -526,7 +524,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
526524
KindColor, `%`(KindFormat, kind))
527525
else:
528526
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
529-
if hintSource in conf.notes:
527+
if conf.hasHint(hintSource):
530528
conf.writeSurroundingSrc(info)
531529
handleError(conf, msg, eh, s)
532530

compiler/nim.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
9393

9494
self.processCmdLineAndProjectPath(conf)
9595
if not self.loadConfigsAndRunMainCommand(cache, conf): return
96-
if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics())
96+
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
9797
#echo(GC_getStatistics())
9898
if conf.errorCounter != 0: return
9999
when hasTinyCBackend:

compiler/options.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ type
287287
severity: Severity) {.closure, gcsafe.}
288288
cppCustomNamespace*: string
289289

290+
proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
291+
optHints in conf.options and note in conf.notes
292+
293+
proc hasWarn*(conf: ConfigRef, note: TNoteKind): bool =
294+
optWarns in conf.options and note in conf.notes
295+
290296
proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions
291297

292298
template depConfigFields*(fn) {.dirty.} =

compiler/semexprs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
990990
result = semExpr(c, result)
991991

992992
proc semExprNoType(c: PContext, n: PNode): PNode =
993-
let isPush = hintExtendedContext in c.config.notes
993+
let isPush = c.config.hasHint(hintExtendedContext)
994994
if isPush: pushInfoContext(c.config, n.info)
995995
result = semExpr(c, n, {efWantStmt})
996996
discardCheck(c, result, {})

compiler/sempass2.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ proc useVar(a: PEffects, n: PNode) =
262262
if s.guard != nil: guardGlobal(a, n, s.guard)
263263
if {sfGlobal, sfThread} * s.flags == {sfGlobal} and
264264
(tfHasGCedMem in s.typ.flags or s.typ.isGCedMem):
265-
#if warnGcUnsafe in gNotes: warnAboutGcUnsafe(n)
265+
#if a.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n)
266266
markGcUnsafe(a, s)
267267
markSideEffect(a, s)
268268
else:
@@ -463,7 +463,7 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
463463
mergeTags(tracked, tagSpec, n)
464464

465465
if notGcSafe(s.typ) and sfImportc notin s.flags:
466-
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
466+
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
467467
markGcUnsafe(tracked, s)
468468
if tfNoSideEffect notin s.typ.flags:
469469
markSideEffect(tracked, s)
@@ -544,15 +544,15 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode)
544544
assumeTheWorst(tracked, n, op)
545545
# assume GcUnsafe unless in its type; 'forward' does not matter:
546546
if notGcSafe(op) and not isOwnedProcVar(a, tracked.owner):
547-
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
547+
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
548548
markGcUnsafe(tracked, a)
549549
elif tfNoSideEffect notin op.flags and not isOwnedProcVar(a, tracked.owner):
550550
markSideEffect(tracked, a)
551551
else:
552552
mergeEffects(tracked, effectList[exceptionEffects], n)
553553
mergeTags(tracked, effectList[tagEffects], n)
554554
if notGcSafe(op):
555-
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
555+
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
556556
markGcUnsafe(tracked, a)
557557
elif tfNoSideEffect notin op.flags:
558558
markSideEffect(tracked, a)
@@ -584,7 +584,7 @@ proc trackCase(tracked: PEffects, n: PNode) =
584584
let stringCase = skipTypes(n[0].typ,
585585
abstractVarRange-{tyTypeDesc}).kind in {tyFloat..tyFloat128, tyString}
586586
let interesting = not stringCase and interestingCaseExpr(n[0]) and
587-
warnProveField in tracked.config.notes
587+
tracked.config.hasWarn(warnProveField)
588588
var inter: TIntersection = @[]
589589
var toCover = 0
590590
for i in 1..<n.len:
@@ -678,7 +678,7 @@ proc track(tracked: PEffects, n: PNode) =
678678
if notGcSafe(op) and not importedFromC(a):
679679
# and it's not a recursive call:
680680
if not (a.kind == nkSym and a.sym == tracked.owner):
681-
if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
681+
if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
682682
markGcUnsafe(tracked, a)
683683
if tfNoSideEffect notin op.flags and not importedFromC(a):
684684
# and it's not a recursive call:
@@ -779,7 +779,7 @@ proc track(tracked: PEffects, n: PNode) =
779779
for i in 0..<n.len: track(tracked, n[i])
780780
of nkCheckedFieldExpr:
781781
track(tracked, n[0])
782-
if warnProveField in tracked.config.notes:
782+
if tracked.config.hasWarn(warnProveField):
783783
checkFieldAccess(tracked.guards, n, tracked.config)
784784
of nkTryStmt: trackTryStmt(tracked, n)
785785
of nkPragma: trackPragmaStmt(tracked, n)

compiler/syntaxes.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ proc applyFilter(p: var TParsers, n: PNode, filename: AbsoluteFile,
120120
result = filterReplace(p.config, stdin, filename, n)
121121
if f != filtNone:
122122
assert p.config != nil
123-
if hintCodeBegin in p.config.notes:
123+
if p.config.hasHint(hintCodeBegin):
124124
rawMessage(p.config, hintCodeBegin, [])
125125
msgWriteln(p.config, result.s)
126126
rawMessage(p.config, hintCodeEnd, [])

0 commit comments

Comments
 (0)