Skip to content

Commit 1056f9e

Browse files
timotheecourAraq
authored andcommitted
properly handle note override logic/verbosity/config/cmdline using modifiedyNotes, cmdlineNotes
1 parent c1cbf94 commit 1056f9e

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

compiler/commands.nim

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,21 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
199199
let x = findStr(lineinfos.WarningsToStr, id)
200200
if x >= 0: n = TNoteKind(x + ord(warnMin))
201201
else: localError(conf, info, "unknown warning: " & id)
202-
case substr(arg, i).normalize
203-
of "on":
204-
incl(conf.notes, n)
205-
incl(conf.mainPackageNotes, n)
206-
incl(conf.enableNotes, n)
207-
if pass == passCmd1:
208-
incl(conf.cmdLineNotes, n)
209-
excl(conf.cmdLineDisabledNotes, n)
210-
of "off":
211-
excl(conf.notes, n)
212-
excl(conf.mainPackageNotes, n)
213-
incl(conf.disableNotes, n)
214-
excl(conf.foreignPackageNotes, n)
215-
if pass == passCmd1:
216-
incl(conf.cmdLineDisabledNotes, n)
217-
excl(conf.cmdLineNotes, n)
218-
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)
202+
203+
let val = substr(arg, i).normalize
204+
if val notin ["on", "off"]:
205+
localError(conf, info, errOnOrOffExpectedButXFound % arg)
206+
elif n notin conf.cmdlineNotes or pass == passCmd1:
207+
if pass == passCmd1: incl(conf.cmdlineNotes, n)
208+
incl(conf.modifiedyNotes, n)
209+
case val
210+
of "on":
211+
incl(conf.notes, n)
212+
incl(conf.mainPackageNotes, n)
213+
of "off":
214+
excl(conf.notes, n)
215+
excl(conf.mainPackageNotes, n)
216+
excl(conf.foreignPackageNotes, n)
219217

220218
proc processCompile(conf: ConfigRef; filename: string) =
221219
var found = findFile(conf, filename)
@@ -598,7 +596,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
598596
of "deadcodeelim": discard # deprecated, dead code elim always on
599597
of "threads":
600598
processOnOffSwitchG(conf, {optThreads}, arg, pass, info)
601-
#if optThreads in conf.globalOptions: incl(conf.notes, warnGcUnsafe)
599+
#if optThreads in conf.globalOptions: conf.setNote(warnGcUnsafe)
602600
of "tlsemulation": processOnOffSwitchG(conf, {optTlsEmulation}, arg, pass, info)
603601
of "taintmode": processOnOffSwitchG(conf, {optTaintMode}, arg, pass, info)
604602
of "implicitstatic":
@@ -710,9 +708,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
710708
if verbosity notin {0..3}:
711709
localError(conf, info, "invalid verbosity level: '$1'" % arg)
712710
conf.verbosity = verbosity
713-
conf.notes = NotesVerbosity[conf.verbosity]
714-
incl(conf.notes, conf.enableNotes)
715-
excl(conf.notes, conf.disableNotes)
711+
var verb = NotesVerbosity[conf.verbosity]
712+
## We override the default `verb` by explicitly modified (set/unset) notes.
713+
conf.notes = (conf.modifiedyNotes * conf.notes + verb) -
714+
(conf.modifiedyNotes * verb - conf.notes)
716715
conf.mainPackageNotes = conf.notes
717716
of "parallelbuild":
718717
expectArg(conf, switch, arg, pass, info)

compiler/msgs.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
418418
inc(conf.warnCounter)
419419
of hintMin..hintMax:
420420
sev = Severity.Hint
421-
if msg in conf.cmdLineDisabledNotes: return # eg: `--hints:conf:off` passed on cmdline
422-
# handle `--hints:off` (regardless of cmdline/cfg file)
423-
# handle `--hints:conf:on` on cmdline
424-
if not conf.hasHint(msg) and not (optHints in conf.options and msg in conf.cmdLineNotes): return
421+
if not conf.hasHint(msg): return
425422
title = HintTitle
426423
color = HintColor
427424
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]

compiler/options.nim

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ type
226226
ideCmd*: IdeCmd
227227
oldNewlines*: bool
228228
cCompiler*: TSystemCC
229-
enableNotes*: TNoteKinds
230-
disableNotes*: TNoteKinds
229+
modifiedyNotes*: TNoteKinds # notes that have been set/unset from either cmdline/configs
230+
cmdlineNotes*: TNoteKinds # notes that have been set/unset from cmdline
231231
foreignPackageNotes*: TNoteKinds
232-
notes*: TNoteKinds
232+
notes*: TNoteKinds # notes after resolving all logic(defaults, verbosity)/cmdline/configs
233233
mainPackageNotes*: TNoteKinds
234-
cmdLineNotes*: TNoteKinds
235-
cmdLineDisabledNotes*: TNoteKinds
236234
mainPackageId*: int
237235
errorCounter*: int
238236
hintCounter*: int
@@ -289,6 +287,10 @@ type
289287
severity: Severity) {.closure, gcsafe.}
290288
cppCustomNamespace*: string
291289

290+
proc setNote*(conf: ConfigRef, note: TNoteKind, enabled = true) =
291+
if note notin conf.cmdlineNotes:
292+
if enabled: incl(conf.notes, note) else: excl(conf.notes, note)
293+
292294
proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
293295
optHints in conf.options and note in conf.notes
294296

compiler/passaux.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ proc verboseProcess(context: PPassContext, n: PNode): PNode =
2828
let v = VerboseRef(context)
2929
if v.config.verbosity == 3:
3030
# system.nim deactivates all hints, for verbosity:3 we want the processing
31-
# messages nonetheless, so we activate them again unconditionally:
32-
incl(v.config.notes, hintProcessing)
31+
# messages nonetheless, so we activate them again (but honor cmdlineNotes)
32+
v.config.setNote(hintProcessing)
3333
message(v.config, n.info, hintProcessing, $idgen.gFrontEndId)
3434

3535
const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)

compiler/pragmas.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ proc processNote(c: PContext, n: PNode) =
328328
n[1] = x
329329
if x.kind == nkIntLit and x.intVal != 0: incl(c.config.notes, nk)
330330
else: excl(c.config.notes, nk)
331+
# checkme: honor cmdlineNotes with: c.setNote(nk, x.kind == nkIntLit and x.intVal != 0)
331332
else:
332333
invalidPragma(c, n)
333334

0 commit comments

Comments
 (0)