Skip to content

Commit

Permalink
Force lambda lifting for getImplTransformed. Hacky. Fixes #19818 (#21031
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yglukhov authored Jan 19, 2023
1 parent ac982d8 commit 9afb466
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions compiler/lambdalifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9afb466

Please sign in to comment.