This commit is contained in:
cooldome 2020-02-14 09:13:55 +00:00 • committed by GitHub
commit 7dd787b8a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View file

@ -251,7 +251,8 @@ proc canBeMoved(c: Con; t: PType): bool {.inline.} =
result = t.attachedOps[attachedSink] != nil result = t.attachedOps[attachedSink] != nil
proc genSink(c: var Con; dest, ri: PNode): PNode = 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) result = newTree(nkFastAsgn, dest, ri)
else: else:
let t = dest.typ.skipTypes({tyGenericInst, tyAlias, tySink}) let t = dest.typ.skipTypes({tyGenericInst, tyAlias, tySink})
@ -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: # make sure it's destroyed at the end of the proc:
if not isUnpackedTuple(v): if not isUnpackedTuple(v):
c.destroys.add genDestroy(c, 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: if ri.kind == nkEmpty and c.inLoop > 0:
ri = genDefaultCall(v.typ, c, v.info) ri = genDefaultCall(v.typ, c, v.info)
if ri.kind != nkEmpty: if ri.kind != nkEmpty:
@ -660,14 +664,11 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
case ri.kind case ri.kind
of nkCallKinds: 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: of nkBracketExpr:
if isUnpackedTuple(ri[0]): if isUnpackedTuple(ri[0]):
# unpacking of tuple: take over elements # unpacking of tuple: take over the elements
result = newTree(nkFastAsgn, dest, p(ri, c, consumed)) result = genSink(c, dest, p(ri, c, consumed))
elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c) and elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c) and
not aliases(dest, ri): not aliases(dest, ri):
# Rule 3: `=sink`(x, z); wasMoved(z) # Rule 3: `=sink`(x, z); wasMoved(z)

View file

@ -74,8 +74,9 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
result.add(v) result.add(v)
for i in 0..<n.len-2: for i in 0..<n.len-2:
if n[i].kind == nkSym: v.addVar(n[i]) let val = newTupleAccess(g, tempAsNode, i)
result.add newAsgnStmt(n[i], 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 = proc evalOnce*(g: ModuleGraph; value: PNode; owner: PSym): PNode =
## Turns (value) into (let tmp = value; tmp) so that 'value' can be re-used ## Turns (value) into (let tmp = value; tmp) so that 'value' can be re-used

View file

@ -86,3 +86,14 @@ proc tbug13314 =
execute() execute()
tbug13314() 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()