Skip to content

Commit 88f1d4f

Browse files
authored
Revert "fixes #24997; {.global.} variable in recursive function (#250… (#25019)
…16)" This reverts commit 1a2ee56.
1 parent 6d5ddcd commit 88f1d4f

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

compiler/cgen.nim

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,20 +2170,6 @@ proc addHcrInitGuards(p: BProc, n: PNode, inInitGuard: var bool) =
21702170

21712171
genStmts(p, n)
21722172

2173-
proc handleProcGlobals(m: BModule) =
2174-
var procGlobals: seq[PNode] = move m.g.graph.procGlobals
2175-
2176-
for i in 0..<procGlobals.len:
2177-
var stmts = newBuilder("")
2178-
2179-
# fixes recursive calls #24997
2180-
swap stmts, m.preInitProc.s(cpsStmts)
2181-
genStmts(m.preInitProc, procGlobals[i])
2182-
swap stmts, m.preInitProc.s(cpsStmts)
2183-
2184-
handleProcGlobals(m)
2185-
m.preInitProc.s(cpsStmts).add stmts.extract()
2186-
21872173
proc genTopLevelStmt*(m: BModule; n: PNode) =
21882174
## Also called from `ic/cbackend.nim`.
21892175
if pipelineutils.skipCodegen(m.config, n): return
@@ -2199,7 +2185,13 @@ proc genTopLevelStmt*(m: BModule; n: PNode) =
21992185
else:
22002186
genProcBody(m.initProc, transformedN)
22012187

2202-
handleProcGlobals(m)
2188+
var procGloals = move m.g.graph.procGlobals
2189+
while true:
2190+
if procGloals.len == 0:
2191+
procGloals = move m.g.graph.procGlobals
2192+
if procGloals.len == 0:
2193+
break
2194+
genStmts(m.preInitProc, procGloals.pop())
22032195

22042196
proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
22052197
if optForceFullMake notin m.config.globalOptions:

tests/global/tglobal3.nim

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,3 @@ block: # bug #24981
4141
type Foo = object
4242
i: int
4343
m(Foo)
44-
45-
block: # bug #24997
46-
type R = ref object
47-
type B = object
48-
j: int
49-
proc y(T: type): R
50-
proc u(T: type): R =
51-
let res {.global.} = y(T)
52-
res
53-
proc y(T: type): R =
54-
when T is object:
55-
doAssert not isNil(u(typeof(B.j)))
56-
R()
57-
discard u(B)

0 commit comments

Comments
 (0)