Skip to content

Commit

Permalink
stack closures progress
Browse files Browse the repository at this point in the history
  • Loading branch information
recloser committed Jul 4, 2020
1 parent 4b18e7d commit 6cfbf4b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/lambdalifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -823,19 +823,26 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
if inContainer: dec c.inContainer

proc anyInnerProcMightEscape(fn: PSym): bool =
# go over the ast and check if any procs defined
# within are assigned or passed rather than just called
# sfAddrTaken should be set on the proc's sym if that's
# the case
proc aux(nodes: TNodeSeq): bool =
for node in nodes:
if (node.kind == nkSym and
isInnerProc(node.sym) and
sfAddrTaken in node.sym.flags):
{sfGenSym, sfAddrTaken} * node.sym.flags != {}):
# ^ HACK: checking for sfGenSym should be irrelevant here
# but sfAddrTaken is never set for gensym'd procs
# so just assume any gensym'd proc might escape
return true
elif node.kind in nkLambdaKinds:
# would be better to check if the lambda actually
# captures something
return true
elif node.kind notin nkLiterals + {nkSym, nkIdent} and aux(node.sons):
return true
return aux(fn.ast[bodyPos].sons)
return fn.typ.callConv == ccClosure or aux(fn.ast[bodyPos].sons)

# ------------------ old stuff -------------------------------------------

Expand Down

0 comments on commit 6cfbf4b

Please sign in to comment.