Skip to content

Commit

Permalink
fixes push warnings for sempass2 (#23603)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Sep 3, 2024
1 parent 538603e commit 4bf323d
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 37 deletions.
25 changes: 0 additions & 25 deletions compiler/backendpragmas.nim

This file was deleted.

4 changes: 2 additions & 2 deletions compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,9 @@ proc genPragma(p: BProc, n: PNode) =
case whichPragma(it)
of wEmit: genEmit(p, it)
of wPush:
processPushBackendOption(p.optionsStack, p.options, n, i+1)
processPushBackendOption(p.config, p.optionsStack, p.options, n, i+1)
of wPop:
processPopBackendOption(p.optionsStack, p.options)
processPopBackendOption(p.config, p.optionsStack, p.options)
else: discard


Expand Down
2 changes: 1 addition & 1 deletion compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import
ccgutils, ropes, wordrecg, treetab, cgmeth,
rodutils, renderer, cgendata, aliases,
lowerings, ndi, lineinfos, pathutils, transf,
injectdestructors, astmsgs, modulepaths, backendpragmas,
injectdestructors, astmsgs, modulepaths, pushpoppragmas,
mangleutils

from expanddefaults import caseObjDefaultBranch
Expand Down
2 changes: 1 addition & 1 deletion compiler/cgendata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type
options*: TOptions # options that should be used for code
# generation; this is the same as prc.options
# unless prc == nil
optionsStack*: seq[TOptions]
optionsStack*: seq[(TOptions, TNoteKinds)]
module*: BModule # used to prevent excessive parameter passing
withinLoop*: int # > 0 if we are within a loop
splitDecls*: int # > 0 if we are in some context for C++ that
Expand Down
8 changes: 4 additions & 4 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import
nversion, msgs, idents, types,
ropes, wordrecg, renderer,
cgmeth, lowerings, sighashes, modulegraphs, lineinfos,
transf, injectdestructors, sourcemap, astmsgs, backendpragmas,
transf, injectdestructors, sourcemap, astmsgs, pushpoppragmas,
mangleutils

import pipelineutils
Expand Down Expand Up @@ -103,7 +103,7 @@ type
prc: PSym
globals, locals, body: Rope
options: TOptions
optionsStack: seq[TOptions]
optionsStack: seq[(TOptions, TNoteKinds)]
module: BModule
g: PGlobals
beforeRetNeeded: bool
Expand Down Expand Up @@ -2824,9 +2824,9 @@ proc genPragma(p: PProc, n: PNode) =
case whichPragma(it)
of wEmit: genAsmOrEmitStmt(p, it[1])
of wPush:
processPushBackendOption(p.optionsStack, p.options, n, i+1)
processPushBackendOption(p.config, p.optionsStack, p.options, n, i+1)
of wPop:
processPopBackendOption(p.optionsStack, p.options)
processPopBackendOption(p.config, p.optionsStack, p.options)
else: discard

proc genCast(p: PProc, n: PNode, r: var TCompRes) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
proc processNote(c: PContext, n: PNode) =
template handleNote(enumVals, notes) =
let x = findStr(enumVals.a, enumVals.b, n[0][1].ident.s, errUnknown)
if x != errUnknown:
if x != errUnknown:
nk = TNoteKind(x)
let x = c.semConstBoolExpr(c, n[1])
n[1] = x
Expand Down
54 changes: 54 additions & 0 deletions compiler/pushpoppragmas.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pragmas, options, ast, trees, lineinfos, idents, wordrecg
import std/assertions

import renderer


proc processNote(config: ConfigRef, n: PNode) =
template handleNote(enumVals, notes) =
let x = findStr(enumVals.a, enumVals.b, n[0][1].ident.s, errUnknown)
assert x != errUnknown
assert n[1].kind == nkIntLit

nk = TNoteKind(x)
if n[1].intVal != 0: incl(notes, nk)
else: excl(notes, nk)

var nk: TNoteKind
case whichKeyword(n[0][0].ident)
of wHint: handleNote(hintMin .. hintMax, config.notes)
of wWarning: handleNote(warnMin .. warnMax, config.notes)
of wWarningAsError: handleNote(warnMin .. warnMax, config.warningAsErrors)
of wHintAsError: handleNote(hintMin .. hintMax, config.warningAsErrors)
else: discard

proc pushBackendOption(optionsStack: var seq[(TOptions, TNoteKinds)], options: TOptions, notes: TNoteKinds) =
optionsStack.add (options, notes)

proc popBackendOption(config: ConfigRef, optionsStack: var seq[(TOptions, TNoteKinds)], options: var TOptions) =
let entry = optionsStack[^1]
options = entry[0]
config.notes = entry[1]
optionsStack.setLen(optionsStack.len-1)

proc processPushBackendOption*(config: ConfigRef, optionsStack: var seq[(TOptions, TNoteKinds)], options: var TOptions,
n: PNode, start: int) =
pushBackendOption(optionsStack, options, config.notes)
for i in start..<n.len:
let it = n[i]
if it.kind in nkPragmaCallKinds and it.len == 2:
if it[0].kind == nkBracketExpr and
it[0].len == 2 and
it[0][1].kind == nkIdent and it[0][0].kind == nkIdent:
processNote(config, it)
elif it[1].kind == nkIntLit:
let sw = whichPragma(it[0])
let opts = pragmaToOptions(sw)
if opts != {}:
if it[1].intVal != 0:
options.incl opts
else:
options.excl opts

template processPopBackendOption*(config: ConfigRef, optionsStack: var seq[(TOptions, TNoteKinds)], options: var TOptions) =
popBackendOption(config, optionsStack, options)
14 changes: 11 additions & 3 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import
ast, astalgo, msgs, renderer, magicsys, types, idents, trees,
wordrecg, options, guards, lineinfos, semfold, semdata,
modulegraphs, varpartitions, typeallowed, nilcheck, errorhandling,
semstrictfuncs, suggestsymdb
semstrictfuncs, suggestsymdb, pushpoppragmas

import std/[tables, intsets, strutils, sequtils]

Expand Down Expand Up @@ -85,6 +85,7 @@ type
isInnerProc: bool
inEnforcedNoSideEffects: bool
currOptions: TOptions
optionsStack: seq[(TOptions, TNoteKinds)]
config: ConfigRef
graph: ModuleGraph
c: PContext
Expand Down Expand Up @@ -615,9 +616,16 @@ proc trackPragmaStmt(tracked: PEffects, n: PNode) =
for i in 0..<n.len:
var it = n[i]
let pragma = whichPragma(it)
if pragma == wEffects:
case pragma
of wEffects:
# list the computed effects up to here:
listEffects(tracked)
of wPush:
processPushBackendOption(tracked.c.config, tracked.optionsStack, tracked.currOptions, n, i+1)
of wPop:
processPopBackendOption(tracked.c.config, tracked.optionsStack, tracked.currOptions)
else:
discard

template notGcSafe(t): untyped = {tfGcSafe, tfNoSideEffect} * t.flags == {}

Expand Down Expand Up @@ -1594,7 +1602,7 @@ proc initEffects(g: ModuleGraph; effects: PNode; s: PSym; c: PContext): TEffects
result = TEffects(exc: effects[exceptionEffects], tags: effects[tagEffects],
forbids: effects[forbiddenEffects], owner: s, ownerModule: s.getModule,
init: @[], locked: @[], graph: g, config: g.config, c: c,
currentBlock: 1
currentBlock: 1, optionsStack: @[(g.config.options, g.config.notes)]
)
result.guards.s = @[]
result.guards.g = g
Expand Down
13 changes: 13 additions & 0 deletions tests/pragmas/tpushnotes.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
discard """
matrix: "--warningAsError:HoleEnumConv"
"""

type
e = enum
a = 0
b = 2

var i: int
{.push warning[HoleEnumConv]:off.}
discard i.e
{.pop.}

0 comments on commit 4bf323d

Please sign in to comment.