mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
remove cyclic imports (transf and lambdalifting) in the compiler
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
import
|
||||
intsets, strutils, options, ast, astalgo, msgs,
|
||||
idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos,
|
||||
transf, liftdestructors, typeallowed
|
||||
liftdestructors, typeallowed
|
||||
|
||||
from transf import nil
|
||||
|
||||
when defined(nimPreviewSlimSystem):
|
||||
import std/assertions
|
||||
@@ -441,7 +443,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
|
||||
if innerProc:
|
||||
if s.isIterator: c.somethingToDo = true
|
||||
if not c.processed.containsOrIncl(s.id):
|
||||
let body = transformBody(c.graph, c.idgen, s, useCache)
|
||||
let body = transf.transformBody(c.graph, c.idgen, s, transf.useCache)
|
||||
detectCapturedVars(body, s, c)
|
||||
let ow = s.skipGenericOwner
|
||||
if ow == owner:
|
||||
@@ -737,7 +739,7 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: var DetectionPass;
|
||||
# echo renderTree(s.getBody, {renderIds})
|
||||
let oldInContainer = c.inContainer
|
||||
c.inContainer = 0
|
||||
var body = transformBody(d.graph, d.idgen, s, dontUseCache)
|
||||
var body = transf.transformBody(d.graph, d.idgen, s, transf.dontUseCache)
|
||||
body = liftCapturedVars(body, s, d, c)
|
||||
if c.envVars.getOrDefault(s.id).isNil:
|
||||
s.transformedBody = body
|
||||
|
||||
@@ -33,7 +33,9 @@ type
|
||||
|
||||
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, flag: TransformBodyFlag, force = false): PNode
|
||||
|
||||
import closureiters, lambdalifting
|
||||
import closureiters
|
||||
from lambdalifting import nil
|
||||
|
||||
|
||||
type
|
||||
PTransCon = ref object # part of TContext; stackable
|
||||
@@ -94,8 +96,8 @@ proc newTemp(c: PTransf, typ: PType, info: TLineInfo): PNode =
|
||||
r.typ = typ #skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
||||
incl(r.flags, sfFromGeneric)
|
||||
let owner = getCurrOwner(c)
|
||||
if owner.isIterator and not c.tooEarly:
|
||||
result = freshVarForClosureIter(c.graph, r, c.idgen, owner)
|
||||
if lambdalifting.isIterator(owner) and not c.tooEarly:
|
||||
result = lambdalifting.freshVarForClosureIter(c.graph, r, c.idgen, owner)
|
||||
else:
|
||||
result = newSymNode(r)
|
||||
|
||||
@@ -120,10 +122,10 @@ proc transformSymAux(c: PTransf, n: PNode): PNode =
|
||||
discard transformBody(c.graph, c.idgen, s, useCache)
|
||||
if s.kind == skIterator:
|
||||
if c.tooEarly: return n
|
||||
else: return liftIterSym(c.graph, n, c.idgen, getCurrOwner(c))
|
||||
else: return lambdalifting.liftIterSym(c.graph, n, c.idgen, getCurrOwner(c))
|
||||
elif s.kind in {skProc, skFunc, skConverter, skMethod} and not c.tooEarly:
|
||||
# top level .closure procs are still somewhat supported for 'Nake':
|
||||
return makeClosure(c.graph, c.idgen, s, nil, n.info)
|
||||
return lambdalifting.makeClosure(c.graph, c.idgen, s, nil, n.info)
|
||||
#elif n.sym.kind in {skVar, skLet} and n.sym.typ.callConv == ccClosure:
|
||||
# echo n.info, " come heer for ", c.tooEarly
|
||||
# if not c.tooEarly:
|
||||
@@ -173,8 +175,8 @@ proc transformSym(c: PTransf, n: PNode): PNode =
|
||||
|
||||
proc freshVar(c: PTransf; v: PSym): PNode =
|
||||
let owner = getCurrOwner(c)
|
||||
if owner.isIterator and not c.tooEarly:
|
||||
result = freshVarForClosureIter(c.graph, v, c.idgen, owner)
|
||||
if lambdalifting.isIterator(owner) and not c.tooEarly:
|
||||
result = lambdalifting.freshVarForClosureIter(c.graph, v, c.idgen, owner)
|
||||
else:
|
||||
var newVar = copySym(v, nextSymId(c.idgen))
|
||||
incl(newVar.flags, sfFromGeneric)
|
||||
@@ -1155,12 +1157,12 @@ proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; flag: Transfo
|
||||
else:
|
||||
prc.transformedBody = newNode(nkEmpty) # protects from recursion
|
||||
var c = openTransf(g, prc.getModule, "", idgen)
|
||||
result = liftLambdas(g, prc, getBody(g, prc), c.tooEarly, c.idgen, force)
|
||||
result = lambdalifting.liftLambdas(g, prc, getBody(g, prc), c.tooEarly, c.idgen, force)
|
||||
result = processTransf(c, result, prc)
|
||||
liftDefer(c, result)
|
||||
result = liftLocalsIfRequested(prc, result, g.cache, g.config, c.idgen)
|
||||
|
||||
if prc.isIterator:
|
||||
if lambdalifting.isIterator(prc):
|
||||
result = g.transformClosureIterator(c.idgen, prc, result)
|
||||
|
||||
incl(result.flags, nfTransf)
|
||||
|
||||
Reference in New Issue
Block a user