mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-12 12:19:40 +00:00
fixes #25949 track still walks both branches of preserved when nimvm, but it now sets a small inNimvmBranch flag while visiting the VM branch, and trackCall skips sfCompileTime marking only when that flag is set.
This commit is contained in:
@@ -93,6 +93,7 @@ type
|
||||
graph: ModuleGraph
|
||||
c: PContext
|
||||
escapingParams: IntSet
|
||||
inNimvmBranch: int
|
||||
PEffects = var TEffects
|
||||
|
||||
const
|
||||
@@ -1127,7 +1128,7 @@ proc trackCall(tracked: PEffects; n: PNode) =
|
||||
# sfCompileTime` path in `semProcAux`.
|
||||
if a.kind == nkSym and a.sym.magic in {mNLen..mNError, mSlurp..mQuoteAst} and
|
||||
tracked.owner != nil and tracked.owner.kind in routineKinds and
|
||||
tracked.config.cmd != cmdNimscript:
|
||||
tracked.config.cmd != cmdNimscript and tracked.inNimvmBranch == 0:
|
||||
# ...but NOT under `nim e`: nimscript has no codegen backend to protect, and
|
||||
# marking a routine `sfCompileTime` makes `semExpr` eagerly fold calls to it
|
||||
# at sem time (emConst), where module-level globals it reads have no VM slot
|
||||
@@ -1483,7 +1484,9 @@ proc track(tracked: PEffects, n: PNode) =
|
||||
of nkCaseStmt: trackCase(tracked, n)
|
||||
of nkWhen: # This should be a "when nimvm" node.
|
||||
let oldState = tracked.init.len
|
||||
inc tracked.inNimvmBranch
|
||||
track(tracked, n[0][1])
|
||||
dec tracked.inNimvmBranch
|
||||
tracked.init.setLen(oldState)
|
||||
track(tracked, n[1][0])
|
||||
of nkIfStmt, nkIfExpr: trackIf(tracked, n)
|
||||
|
||||
@@ -855,3 +855,17 @@ block:
|
||||
var r = Obj(x: 10)
|
||||
r.value = 42
|
||||
doAssert r.x == 42
|
||||
|
||||
block: # bug #25949
|
||||
template loadFile(filename: string): auto =
|
||||
when nimvm:
|
||||
staticRead(filename)
|
||||
else:
|
||||
"something"
|
||||
|
||||
proc roundTrip(): bool =
|
||||
let content = loadFile("tests/tomls/case.toml")
|
||||
content == "something"
|
||||
|
||||
doAssert roundTrip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user