new destroyer pass works with procs too

This commit is contained in:
Andreas Rumpf
2017-10-13 07:00:52 +02:00
parent ffe52a7f7b
commit 5dca695bcf
4 changed files with 11 additions and 9 deletions

View File

@@ -290,4 +290,7 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
else:
result.add body
#echo "transformed into: ", result
when false:
echo "------------------------------------"
echo owner.name.s, " transformed from: ", n
echo result

View File

@@ -400,7 +400,7 @@ proc addToVarSection(c: PContext; result: var PNode; orig, identDefs: PNode) =
# in order for this transformation to be correct.
let L = identDefs.len
let value = identDefs[L-1]
if value.typ != nil and tfHasAsgn in value.typ.flags and c.p.owner.kind != skFunc:
if value.typ != nil and tfHasAsgn in value.typ.flags and not newDestructors:
# the spec says we need to rewrite 'var x = T()' to 'var x: T; x = T()':
identDefs.sons[L-1] = emptyNode
if result.kind != nkStmtList:

View File

@@ -971,11 +971,11 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
result = processTransf(c, result, prc)
liftDefer(c, result)
#result = liftLambdas(prc, result)
incl(result.flags, nfTransf)
when useEffectSystem: trackProc(prc, result)
if c.needsDestroyPass and newDestructors:
result = injectDestructorCalls(prc, result)
#if prc.name.s == "testbody":
incl(result.flags, nfTransf)
#if prc.name.s == "testbody":
# echo renderTree(result)
proc transformStmt*(module: PSym, n: PNode): PNode =
@@ -986,12 +986,12 @@ proc transformStmt*(module: PSym, n: PNode): PNode =
result = processTransf(c, n, module)
liftDefer(c, result)
#result = liftLambdasForTopLevel(module, result)
incl(result.flags, nfTransf)
when useEffectSystem: trackTopLevelStmt(module, result)
#if n.info ?? "temp.nim":
# echo renderTree(result, {renderIds})
if c.needsDestroyPass and newDestructors:
result = injectDestructorCalls(module, result)
incl(result.flags, nfTransf)
proc transformExpr*(module: PSym, n: PNode): PNode =
if nfTransf in n.flags:
@@ -1000,6 +1000,6 @@ proc transformExpr*(module: PSym, n: PNode): PNode =
var c = openTransf(module, "")
result = processTransf(c, n, module)
liftDefer(c, result)
incl(result.flags, nfTransf)
if c.needsDestroyPass and newDestructors:
result = injectDestructorCalls(module, result)
incl(result.flags, nfTransf)