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 f177baf commit c4540a3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions compiler/lambdalifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -823,19 +823,30 @@ 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 == nkSym and
node.sym.isIterator and
node.sym.typ.callConv == ccClosure:
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 c4540a3

Please sign in to comment.