Skip to content

Commit

Permalink
Revert "fix #13417 (#13712)"
Browse files Browse the repository at this point in the history
This reverts commit a5f02ca.
  • Loading branch information
Araq authored Mar 23, 2020
1 parent 0ac9c7b commit 2a7c545
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
21 changes: 11 additions & 10 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -554,29 +554,29 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
# inline context.
if formal.kind == tyTypeDesc: return paDirectMapping
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
case arg.skipHidden.kind
case arg.kind
of nkStmtListExpr:
return paComplexOpenarray
of nkBracket:
return paFastAsgnTakeTypeFromArg
of nkSym:
return paDirectMapping
else:
return paComplexOpenarray

return paDirectMapping # XXX really correct?
# what if ``arg`` has side-effects?
case arg.kind
of nkEmpty..nkNilLit:
result = paDirectMapping
of nkDotExpr, nkDerefExpr, nkHiddenDeref, nkAddr, nkHiddenAddr:
result = putArgInto(arg[0], formal)
of nkCurly, nkBracket:
for i in 0..<arg.len:
if putArgInto(arg[i], formal) != paDirectMapping:
if putArgInto(arg[i], formal) != paDirectMapping:
return paFastAsgn
result = paDirectMapping
of nkPar, nkTupleConstr, nkObjConstr:
for i in 0..<arg.len:
let a = if arg[i].kind == nkExprColonExpr: arg[i][1]
else: arg[0]
if putArgInto(a, formal) != paDirectMapping:
if putArgInto(a, formal) != paDirectMapping:
return paFastAsgn
result = paDirectMapping
else:
Expand Down Expand Up @@ -644,7 +644,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
# generate access statements for the parameters (unless they are constant)
pushTransCon(c, newC)
for i in 1..<call.len:
let arg = transform(c, call[i])
var arg = transform(c, call[i])
let ff = skipTypes(iter.typ, abstractInst)
# can happen for 'nim check':
if i >= ff.n.len: return result
Expand All @@ -671,8 +671,9 @@ proc transformFor(c: PTransf, n: PNode): PNode =
idNodeTablePut(newC.mapping, formal, arg)
# XXX BUG still not correct if the arg has a side effect!
of paComplexOpenarray:
# arrays will deep copy here (pretty bad).
var temp = newTemp(c, arg.typ, formal.info)
let typ = newType(tySequence, formal.owner)
addSonSkipIntLit(typ, formal.typ[0])
var temp = newTemp(c, typ, formal.info)
addVar(v, temp)
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
idNodeTablePut(newC.mapping, formal, temp)
Expand Down
21 changes: 0 additions & 21 deletions tests/iter/titer_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,3 @@ block t2023_objiter:

var o = init()
echo(o.iter())

block:
# bug #13417

var effectCounterP1 = 0

proc p1(): seq[int] =
inc effectCounterP1
@[1,2]

iterator ip1(v: openArray[int]): auto =
for x in v:
yield x

var effectCounterLoop = 0

for x in ip1(p1()):
inc effectCounterLoop

doAssert effectCounterP1 == 1
doAssert effectCounterLoop == 2

0 comments on commit 2a7c545

Please sign in to comment.