Force lambda lifting for getImplTransformed. Hacky. Fixes #19818 (#21031)

This commit is contained in:
Yuriy Glukhov
2023-01-19 11:46:41 +01:00
committed by GitHub
parent ac982d8a96
commit 9afb466d73
3 changed files with 6 additions and 6 deletions

View File

@@ -859,7 +859,7 @@ proc liftIterToProc*(g: ModuleGraph; fn: PSym; body: PNode; ptrType: PType;
fn.typ.callConv = oldCC
proc liftLambdas*(g: ModuleGraph; fn: PSym, body: PNode; tooEarly: var bool;
idgen: IdGenerator): PNode =
idgen: IdGenerator, force: bool): PNode =
# XXX backend == backendJs does not suffice! The compiletime stuff needs
# the transformation even when compiling to JS ...
@@ -868,7 +868,7 @@ proc liftLambdas*(g: ModuleGraph; fn: PSym, body: PNode; tooEarly: var bool;
if body.kind == nkEmpty or (
g.config.backend == backendJs and not isCompileTime) or
fn.skipGenericOwner.kind != skModule:
(fn.skipGenericOwner.kind != skModule and not force):
# ignore forward declaration:
result = body

View File

@@ -31,7 +31,7 @@ type
TransformBodyFlag* = enum
dontUseCache, useCache
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, flag: TransformBodyFlag): PNode
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, flag: TransformBodyFlag, force = false): PNode
import closureiters, lambdalifting
@@ -1145,7 +1145,7 @@ template liftDefer(c, root) =
if c.deferDetected:
liftDeferAux(root)
proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; flag: TransformBodyFlag): PNode =
proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; flag: TransformBodyFlag, force = false): PNode =
assert prc.kind in routineKinds
if prc.transformedBody != nil:
@@ -1155,7 +1155,7 @@ proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; flag: Transfo
else:
prc.transformedBody = newNode(nkEmpty) # protects from recursion
var c = openTransf(g, prc.getModule, "", idgen)
result = liftLambdas(g, prc, getBody(g, prc), c.tooEarly, c.idgen)
result = liftLambdas(g, prc, getBody(g, prc), c.tooEarly, c.idgen, force)
result = processTransf(c, result, prc)
liftDefer(c, result)
result = liftLocalsIfRequested(prc, result, g.cache, g.config, c.idgen)

View File

@@ -1271,7 +1271,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let ast = a.sym.ast.shallowCopy
for i in 0..<a.sym.ast.len:
ast[i] = a.sym.ast[i]
ast[bodyPos] = transformBody(c.graph, c.idgen, a.sym, useCache)
ast[bodyPos] = transformBody(c.graph, c.idgen, a.sym, useCache, force=true)
ast.copyTree()
of opcSymOwner:
decodeB(rkNode)