From 48d8e215d53b5b231483b208def8b3ed8e5fdf85 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 1 May 2018 10:31:49 +0300 Subject: [PATCH] Don't leak sem PContext into transf --- compiler/seminst.nim | 2 +- compiler/semstmts.nim | 6 +++--- compiler/transf.nim | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 9ec7d8798..0513e2395 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -145,7 +145,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) = freshGenSyms(b, result, orig, symMap) b = semProcBody(c, b) b = hloBody(c, b) - n.sons[bodyPos] = transformBody(c, b, result) + n.sons[bodyPos] = transformBody(c.module, c.features, b, result) #echo "code instantiated ", result.name.s excl(result.flags, sfForward) dec c.inGenericInst diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index dfee20a99..9f00e877f 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1236,7 +1236,7 @@ proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode = addResult(c, s.typ.sons[0], n.info, skProc) addResultNode(c, n) let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) - n.sons[bodyPos] = transformBody(c, semBody, s) + n.sons[bodyPos] = transformBody(c.module, c.features, semBody, s) popProcCon(c) elif efOperand notin flags: localError(n.info, errGenericLambdaNotAllowed) @@ -1277,7 +1277,7 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode = addResult(c, n.typ.sons[0], n.info, skProc) addResultNode(c, n) let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) - n.sons[bodyPos] = transformBody(c, semBody, s) + n.sons[bodyPos] = transformBody(c.module, c.features, semBody, s) popProcCon(c) popOwner(c) closeScope(c) @@ -1590,7 +1590,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) # unfortunately we cannot skip this step when in 'system.compiles' # context as it may even be evaluated in 'system.compiles': - n.sons[bodyPos] = transformBody(c, semBody, s) + n.sons[bodyPos] = transformBody(c.module, c.features, semBody, s) else: if s.typ.sons[0] != nil and kind != skIterator: addDecl(c, newSym(skUnknown, getIdent"result", nil, n.info)) diff --git a/compiler/transf.nim b/compiler/transf.nim index c0f5e5e32..75c7f2b6c 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -20,10 +20,9 @@ import intsets, strutils, options, ast, astalgo, trees, treetab, msgs, os, lookups, - idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread, semdata, + idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread, lambdalifting, sempass2, lowerings, destroyer, liftlocals, closureiters - type PTransNode* = distinct PNode @@ -968,11 +967,11 @@ template liftDefer(c, root) = if c.deferDetected: liftDeferAux(root) -proc transformBody*(ctx: PContext, n: PNode, prc: PSym): PNode = +proc transformBody*(module: PSym, features: set[Feature], n: PNode, prc: PSym): PNode = result = n if nfTransf notin n.flags and prc.kind notin {skTemplate}: - var c = openTransf(ctx.module, "") - result = liftLambdas(ctx.features, prc, result, c.tooEarly) + var c = openTransf(module, "") + result = liftLambdas(features, prc, result, c.tooEarly) result = processTransf(c, result, prc) liftDefer(c, result) @@ -981,7 +980,7 @@ proc transformBody*(ctx: PContext, n: PNode, prc: PSym): PNode = if c.needsDestroyPass: #and newDestructors: result = injectDestructorCalls(prc, result) - if prc.isIterator and oldIterTransf notin ctx.features: + if prc.isIterator and oldIterTransf notin features: result = transformClosureIterator(prc, result) incl(result.flags, nfTransf)