Revert "fixes #24997; {.global.} variable in recursive function (#25016)"

This reverts commit 3ce38f2959.
This commit is contained in:
ringabout
2025-06-27 21:45:11 +08:00
committed by GitHub
parent 6bdb069a66
commit 900b6de6ff
2 changed files with 7 additions and 29 deletions

View File

@@ -2420,20 +2420,6 @@ proc addHcrInitGuards(p: BProc, n: PNode, inInitGuard: var bool, init: var IfBui
genStmts(p, n)
proc handleProcGlobals(m: BModule) =
var procGlobals: seq[PNode] = move m.g.graph.procGlobals
for i in 0..<procGlobals.len:
var stmts = newBuilder("")
# fixes recursive calls #24997
swap stmts, m.preInitProc.s(cpsStmts)
genStmts(m.preInitProc, procGlobals[i])
swap stmts, m.preInitProc.s(cpsStmts)
handleProcGlobals(m)
m.preInitProc.s(cpsStmts).add stmts.extract()
proc genTopLevelStmt*(m: BModule; n: PNode) =
## Also called from `ic/cbackend.nim`.
if pipelineutils.skipCodegen(m.config, n): return
@@ -2449,7 +2435,13 @@ proc genTopLevelStmt*(m: BModule; n: PNode) =
else:
genProcBody(m.initProc, transformedN)
handleProcGlobals(m)
var procGloals = move m.g.graph.procGlobals
while true:
if procGloals.len == 0:
procGloals = move m.g.graph.procGlobals
if procGloals.len == 0:
break
genStmts(m.preInitProc, procGloals.pop())
proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
if optForceFullMake notin m.config.globalOptions:

View File

@@ -41,17 +41,3 @@ block: # bug #24981
type Foo = object
i: int
m(Foo)
block: # bug #24997
type R = ref object
type B = object
j: int
proc y(T: type): R
proc u(T: type): R =
let res {.global.} = y(T)
res
proc y(T: type): R =
when T is object:
doAssert not isNil(u(typeof(B.j)))
R()
discard u(B)