Removed oldIterTranf feature
This commit is contained in:
parent
5f2cdcd4fa
commit
5c449c8cd1
5 changed files with 4 additions and 109 deletions
|
|
@ -607,81 +607,6 @@ proc getStateField*(g: ModuleGraph; owner: PSym): PSym =
|
||||||
proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
|
proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
c: var LiftingPass): PNode
|
c: var LiftingPass): PNode
|
||||||
|
|
||||||
proc transformYield(n: PNode; owner: PSym; d: DetectionPass;
|
|
||||||
c: var LiftingPass): PNode =
|
|
||||||
if c.inContainer > 0:
|
|
||||||
localError(d.graph.config, n.info, "invalid control flow: 'yield' within a constructor")
|
|
||||||
let state = getStateField(d.graph, owner)
|
|
||||||
assert state != nil
|
|
||||||
assert state.typ != nil
|
|
||||||
assert state.typ.n != nil
|
|
||||||
inc state.typ.n.sons[1].intVal
|
|
||||||
let stateNo = state.typ.n.sons[1].intVal
|
|
||||||
|
|
||||||
var stateAsgnStmt = newNodeI(nkAsgn, n.info)
|
|
||||||
stateAsgnStmt.add(rawIndirectAccess(newSymNode(getEnvParam(owner)),
|
|
||||||
state, n.info))
|
|
||||||
stateAsgnStmt.add(newIntTypeNode(nkIntLit, stateNo,
|
|
||||||
getSysType(d.graph, n.info, tyInt)))
|
|
||||||
|
|
||||||
var retStmt = newNodeI(nkReturnStmt, n.info)
|
|
||||||
if n.sons[0].kind != nkEmpty:
|
|
||||||
var a = newNodeI(nkAsgn, n.sons[0].info)
|
|
||||||
var retVal = liftCapturedVars(n.sons[0], owner, d, c)
|
|
||||||
addSon(a, newSymNode(getClosureIterResult(owner)))
|
|
||||||
addSon(a, retVal)
|
|
||||||
retStmt.add(a)
|
|
||||||
else:
|
|
||||||
retStmt.add(emptyNode)
|
|
||||||
|
|
||||||
var stateLabelStmt = newNodeI(nkState, n.info)
|
|
||||||
stateLabelStmt.add(newIntTypeNode(nkIntLit, stateNo,
|
|
||||||
getSysType(d.graph, n.info, tyInt)))
|
|
||||||
|
|
||||||
result = newNodeI(nkStmtList, n.info)
|
|
||||||
result.add(stateAsgnStmt)
|
|
||||||
result.add(retStmt)
|
|
||||||
result.add(stateLabelStmt)
|
|
||||||
|
|
||||||
proc transformReturn(n: PNode; owner: PSym; d: DetectionPass;
|
|
||||||
c: var LiftingPass): PNode =
|
|
||||||
let state = getStateField(d.graph, owner)
|
|
||||||
result = newNodeI(nkStmtList, n.info)
|
|
||||||
var stateAsgnStmt = newNodeI(nkAsgn, n.info)
|
|
||||||
stateAsgnStmt.add(rawIndirectAccess(newSymNode(getEnvParam(owner)),
|
|
||||||
state, n.info))
|
|
||||||
stateAsgnStmt.add(newIntTypeNode(nkIntLit, -1, getSysType(d.graph, n.info, tyInt)))
|
|
||||||
result.add(stateAsgnStmt)
|
|
||||||
result.add(n)
|
|
||||||
|
|
||||||
proc wrapIterBody(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
|
||||||
if not owner.isIterator: return n
|
|
||||||
when false:
|
|
||||||
# unfortunately control flow is still convoluted and we can end up
|
|
||||||
# multiple times here for the very same iterator. We shield against this
|
|
||||||
# with some rather primitive check for now:
|
|
||||||
if n.kind == nkStmtList and n.len > 0:
|
|
||||||
if n.sons[0].kind == nkGotoState: return n
|
|
||||||
if n.len > 1 and n[1].kind == nkStmtList and n[1].len > 0 and
|
|
||||||
n[1][0].kind == nkGotoState:
|
|
||||||
return n
|
|
||||||
let info = n.info
|
|
||||||
result = newNodeI(nkStmtList, info)
|
|
||||||
var gs = newNodeI(nkGotoState, info)
|
|
||||||
gs.add(rawIndirectAccess(newSymNode(getHiddenParam(g, owner)), getStateField(g, owner), info))
|
|
||||||
result.add(gs)
|
|
||||||
var state0 = newNodeI(nkState, info)
|
|
||||||
state0.add(newIntNode(nkIntLit, 0))
|
|
||||||
result.add(state0)
|
|
||||||
|
|
||||||
result.add(n)
|
|
||||||
|
|
||||||
var stateAsgnStmt = newNodeI(nkAsgn, info)
|
|
||||||
stateAsgnStmt.add(rawIndirectAccess(newSymNode(getHiddenParam(g, owner)),
|
|
||||||
getStateField(g, owner), info))
|
|
||||||
stateAsgnStmt.add(newIntTypeNode(nkIntLit, -1, getSysType(g, info, tyInt)))
|
|
||||||
result.add(stateAsgnStmt)
|
|
||||||
|
|
||||||
proc symToClosure(n: PNode; owner: PSym; d: DetectionPass;
|
proc symToClosure(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
c: var LiftingPass): PNode =
|
c: var LiftingPass): PNode =
|
||||||
let s = n.sym
|
let s = n.sym
|
||||||
|
|
@ -722,8 +647,6 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
let oldInContainer = c.inContainer
|
let oldInContainer = c.inContainer
|
||||||
c.inContainer = 0
|
c.inContainer = 0
|
||||||
var body = liftCapturedVars(s.getBody, s, d, c)
|
var body = liftCapturedVars(s.getBody, s, d, c)
|
||||||
if oldIterTransf in d.graph.config.features:
|
|
||||||
body = wrapIterBody(d.graph, body, s)
|
|
||||||
if c.envvars.getOrDefault(s.id).isNil:
|
if c.envvars.getOrDefault(s.id).isNil:
|
||||||
s.ast.sons[bodyPos] = body
|
s.ast.sons[bodyPos] = body
|
||||||
else:
|
else:
|
||||||
|
|
@ -766,11 +689,7 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
if n[1].kind == nkClosure: result = n[1]
|
if n[1].kind == nkClosure: result = n[1]
|
||||||
else:
|
else:
|
||||||
if owner.isIterator:
|
if owner.isIterator:
|
||||||
if oldIterTransf in d.graph.config.features and n.kind == nkYieldStmt:
|
if nfLL in n.flags:
|
||||||
return transformYield(n, owner, d, c)
|
|
||||||
elif oldIterTransf in d.graph.config.features and n.kind == nkReturnStmt:
|
|
||||||
return transformReturn(n, owner, d, c)
|
|
||||||
elif nfLL in n.flags:
|
|
||||||
# special case 'when nimVm' due to bug #3636:
|
# special case 'when nimVm' due to bug #3636:
|
||||||
n.sons[1] = liftCapturedVars(n[1], owner, d, c)
|
n.sons[1] = liftCapturedVars(n[1], owner, d, c)
|
||||||
return
|
return
|
||||||
|
|
@ -811,7 +730,7 @@ proc liftIterToProc*(g: ModuleGraph; fn: PSym; body: PNode; ptrType: PType): PNo
|
||||||
fn.typ.callConv = ccClosure
|
fn.typ.callConv = ccClosure
|
||||||
d.ownerToType[fn.id] = ptrType
|
d.ownerToType[fn.id] = ptrType
|
||||||
detectCapturedVars(body, fn, d)
|
detectCapturedVars(body, fn, d)
|
||||||
result = wrapIterBody(g, liftCapturedVars(body, fn, d, c), fn)
|
result = liftCapturedVars(body, fn, d, c)
|
||||||
fn.kind = oldKind
|
fn.kind = oldKind
|
||||||
fn.typ.callConv = oldCC
|
fn.typ.callConv = oldCC
|
||||||
|
|
||||||
|
|
@ -840,9 +759,6 @@ proc liftLambdas*(g: ModuleGraph; fn: PSym, body: PNode; tooEarly: var bool): PN
|
||||||
result = liftCapturedVars(body, fn, d, c)
|
result = liftCapturedVars(body, fn, d, c)
|
||||||
if c.envvars.getOrDefault(fn.id) != nil:
|
if c.envvars.getOrDefault(fn.id) != nil:
|
||||||
result = newTree(nkStmtList, rawClosureCreation(fn, d, c), result)
|
result = newTree(nkStmtList, rawClosureCreation(fn, d, c), result)
|
||||||
|
|
||||||
if oldIterTransf in g.config.features:
|
|
||||||
result = wrapIterBody(g, result, fn)
|
|
||||||
else:
|
else:
|
||||||
result = body
|
result = body
|
||||||
#if fn.name.s == "get2":
|
#if fn.name.s == "get2":
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,7 @@ type
|
||||||
callOperator,
|
callOperator,
|
||||||
parallel,
|
parallel,
|
||||||
destructor,
|
destructor,
|
||||||
notnil,
|
notnil
|
||||||
oldIterTransf
|
|
||||||
|
|
||||||
SymbolFilesOption* = enum
|
SymbolFilesOption* = enum
|
||||||
disabledSf, enabledSf, writeOnlySf, readOnlySf, v2Sf
|
disabledSf, enabledSf, writeOnlySf, readOnlySf, v2Sf
|
||||||
|
|
|
||||||
|
|
@ -1556,8 +1556,6 @@ proc semYield(c: PContext, n: PNode): PNode =
|
||||||
checkSonsLen(n, 1, c.config)
|
checkSonsLen(n, 1, c.config)
|
||||||
if c.p.owner == nil or c.p.owner.kind != skIterator:
|
if c.p.owner == nil or c.p.owner.kind != skIterator:
|
||||||
localError(c.config, n.info, errYieldNotAllowedHere)
|
localError(c.config, n.info, errYieldNotAllowedHere)
|
||||||
elif oldIterTransf in c.features and c.p.inTryStmt > 0 and c.p.owner.typ.callConv != ccInline:
|
|
||||||
localError(c.config, n.info, errYieldNotAllowedInTryStmt)
|
|
||||||
elif n.sons[0].kind != nkEmpty:
|
elif n.sons[0].kind != nkEmpty:
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0]) # check for type compatibility:
|
n.sons[0] = semExprWithType(c, n.sons[0]) # check for type compatibility:
|
||||||
var iterType = c.p.owner.typ
|
var iterType = c.p.owner.typ
|
||||||
|
|
|
||||||
|
|
@ -985,7 +985,7 @@ proc transformBody*(g: ModuleGraph; module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
if c.needsDestroyPass: #and newDestructors:
|
if c.needsDestroyPass: #and newDestructors:
|
||||||
result = injectDestructorCalls(g, prc, result)
|
result = injectDestructorCalls(g, prc, result)
|
||||||
|
|
||||||
if prc.isIterator and oldIterTransf notin g.config.features:
|
if prc.isIterator:
|
||||||
result = g.transformClosureIterator(prc, result)
|
result = g.transformClosureIterator(prc, result)
|
||||||
|
|
||||||
incl(result.flags, nfTransf)
|
incl(result.flags, nfTransf)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
discard """
|
|
||||||
file: "tasynctry2.nim"
|
|
||||||
errormsg: "\'yield\' cannot be used within \'try\' in a non-inlined iterator"
|
|
||||||
line: 14
|
|
||||||
"""
|
|
||||||
import asyncdispatch
|
|
||||||
|
|
||||||
{.experimental: "oldIterTransf".}
|
|
||||||
|
|
||||||
proc foo(): Future[bool] {.async.} = discard
|
|
||||||
|
|
||||||
proc test5(): Future[int] {.async.} =
|
|
||||||
try:
|
|
||||||
discard await foo()
|
|
||||||
raise newException(ValueError, "Test5")
|
|
||||||
except:
|
|
||||||
discard await foo()
|
|
||||||
result = 0
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue