@@ -2420,6 +2420,20 @@ proc addHcrInitGuards(p: BProc, n: PNode, inInitGuard: var bool, init: var IfBui
2420
2420
2421
2421
genStmts(p, n)
2422
2422
2423
+ proc handleProcGlobals(m: BModule) =
2424
+ var procGlobals: seq[PNode] = move m.g.graph.procGlobals
2425
+
2426
+ for i in 0..<procGlobals.len:
2427
+ var stmts = newBuilder("")
2428
+
2429
+ # fixes recursive calls #24997
2430
+ swap stmts, m.preInitProc.s(cpsStmts)
2431
+ genStmts(m.preInitProc, procGlobals[i])
2432
+ swap stmts, m.preInitProc.s(cpsStmts)
2433
+
2434
+ handleProcGlobals(m)
2435
+ m.preInitProc.s(cpsStmts).add stmts.extract()
2436
+
2423
2437
proc genTopLevelStmt*(m: BModule; n: PNode) =
2424
2438
## Also called from `ic/cbackend.nim`.
2425
2439
if pipelineutils.skipCodegen(m.config, n): return
@@ -2435,13 +2449,7 @@ proc genTopLevelStmt*(m: BModule; n: PNode) =
2435
2449
else:
2436
2450
genProcBody(m.initProc, transformedN)
2437
2451
2438
- var procGloals = move m.g.graph.procGlobals
2439
- while true:
2440
- if procGloals.len == 0:
2441
- procGloals = move m.g.graph.procGlobals
2442
- if procGloals.len == 0:
2443
- break
2444
- genStmts(m.preInitProc, procGloals.pop())
2452
+ handleProcGlobals(m)
2445
2453
2446
2454
proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
2447
2455
if optForceFullMake notin m.config.globalOptions:
0 commit comments