Skip to content

Commit

Permalink
fixes #13368 (#13397)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldome authored Feb 14, 2020
1 parent 1e30310 commit 7dd787b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 8 additions & 7 deletions compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ proc canBeMoved(c: Con; t: PType): bool {.inline.} =
result = t.attachedOps[attachedSink] != nil

proc genSink(c: var Con; dest, ri: PNode): PNode =
if isFirstWrite(dest, c): # optimize sink call into a bitwise memcopy
if isUnpackedTuple(dest) or isFirstWrite(dest, c):
# optimize sink call into a bitwise memcopy
result = newTree(nkFastAsgn, dest, ri)
else:
let t = dest.typ.skipTypes({tyGenericInst, tyAlias, tySink})
Expand Down Expand Up @@ -592,6 +593,9 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
# make sure it's destroyed at the end of the proc:
if not isUnpackedTuple(v):
c.destroys.add genDestroy(c, v)
elif c.inLoop > 0:
# unpacked tuple needs reset at every loop iteration
result.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info))
if ri.kind == nkEmpty and c.inLoop > 0:
ri = genDefaultCall(v.typ, c, v.info)
if ri.kind != nkEmpty:
Expand Down Expand Up @@ -660,14 +664,11 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
case ri.kind
of nkCallKinds:
if isUnpackedTuple(dest):
result = newTree(nkFastAsgn, dest, p(ri, c, consumed))
else:
result = genSink(c, dest, p(ri, c, consumed))
result = genSink(c, dest, p(ri, c, consumed))
of nkBracketExpr:
if isUnpackedTuple(ri[0]):
# unpacking of tuple: take over elements
result = newTree(nkFastAsgn, dest, p(ri, c, consumed))
# unpacking of tuple: take over the elements
result = genSink(c, dest, p(ri, c, consumed))
elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c) and
not aliases(dest, ri):
# Rule 3: `=sink`(x, z); wasMoved(z)
Expand Down
5 changes: 3 additions & 2 deletions compiler/lowerings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
result.add(v)

for i in 0..<n.len-2:
if n[i].kind == nkSym: v.addVar(n[i])
result.add newAsgnStmt(n[i], newTupleAccess(g, tempAsNode, i))
let val = newTupleAccess(g, tempAsNode, i)
if n[i].kind == nkSym: v.addVar(n[i], val)
else: result.add newAsgnStmt(n[i], val)

proc evalOnce*(g: ModuleGraph; value: PNode; owner: PSym): PNode =
## Turns (value) into (let tmp = value; tmp) so that 'value' can be re-used
Expand Down
11 changes: 11 additions & 0 deletions tests/arc/tmovebug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ proc tbug13314 =
execute()

tbug13314()

#-------------------------------------------------------------------------
# bug #13368

import strutils
proc procStat() =
for line in @["a b", "c d", "e f"]:
let cols = line.splitWhitespace(maxSplit=1)
let x = cols[0]
let (nm, rest) = (cols[0], cols[1])
procStat()

0 comments on commit 7dd787b

Please sign in to comment.