fixes new liftLocals pass

This commit is contained in:
Andreas Rumpf
2017-11-02 20:39:08 +01:00
parent 0a38cd6543
commit cccdd9b58e
2 changed files with 8 additions and 6 deletions

View File

@@ -52,17 +52,19 @@ proc lookupParam(params, dest: PNode): PSym =
if params[i].kind == nkSym and params[i].sym.name.id == dest.ident.id:
return params[i].sym
proc liftLocalsIfRequested*(prc: PSym) =
proc liftLocalsIfRequested*(prc: PSym; n: PNode): PNode =
let liftDest = getPragmaVal(prc.ast, wLiftLocals)
if liftDest == nil: return
if liftDest == nil: return n
let partialParam = lookupParam(prc.typ.n, liftDest)
if partialParam.isNil:
localError(liftDest.info, "'$1' is not a parameter of '$2'" %
[$liftDest, prc.name.s])
return
return n
let objType = partialParam.typ.skipTypes(abstractPtrs)
if objType.kind != tyObject or tfPartial notin objType.flags:
localError(liftDest.info, "parameter '$1' is not a pointer to a partial object" % $liftDest)
return
return n
var c = Ctx(partialParam: partialParam, objType: objType)
liftLocals(prc.ast, bodyPos, c)
let w = newTree(nkStmtList, n)
liftLocals(w, 0, c)
result = w[0]

View File

@@ -978,7 +978,7 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
liftDefer(c, result)
#result = liftLambdas(prc, result)
when useEffectSystem: trackProc(prc, result)
liftLocalsIfRequested(prc)
result = liftLocalsIfRequested(prc, result)
if c.needsDestroyPass and newDestructors:
result = injectDestructorCalls(prc, result)
incl(result.flags, nfTransf)