* fixes #12989 * Revert "remove unwanted changes" This reverts commit 501829732a8e44deef2d815c303859efbe452cb5.
This commit is contained in:
parent
ce40ed18bb
commit
584e8c8283
4 changed files with 20 additions and 10 deletions
|
|
@ -133,10 +133,10 @@ proc initialized(code: ControlFlowGraph; pc: int,
|
||||||
inc pc
|
inc pc
|
||||||
return pc
|
return pc
|
||||||
|
|
||||||
template isUnpackedTuple(s: PSym): bool =
|
template isUnpackedTuple(n: PNode): bool =
|
||||||
## we move out all elements of unpacked tuples,
|
## we move out all elements of unpacked tuples,
|
||||||
## hence unpacked tuples themselves don't need to be destroyed
|
## hence unpacked tuples themselves don't need to be destroyed
|
||||||
s.kind == skTemp and s.typ.kind == tyTuple
|
(n.kind == nkSym and n.sym.kind == skTemp and n.sym.typ.kind == tyTuple)
|
||||||
|
|
||||||
proc checkForErrorPragma(c: Con; t: PType; ri: PNode; opname: string) =
|
proc checkForErrorPragma(c: Con; t: PType; ri: PNode; opname: string) =
|
||||||
var m = "'" & opname & "' is not available for type <" & typeToString(t) & ">"
|
var m = "'" & opname & "' is not available for type <" & typeToString(t) & ">"
|
||||||
|
|
@ -542,7 +542,7 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
|
||||||
# move the variable declaration to the top of the frame:
|
# move the variable declaration to the top of the frame:
|
||||||
c.addTopVar v
|
c.addTopVar v
|
||||||
# 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(it[0].sym):
|
if not isUnpackedTuple(v):
|
||||||
c.destroys.add genDestroy(c, v)
|
c.destroys.add genDestroy(c, v)
|
||||||
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)
|
||||||
|
|
@ -612,13 +612,15 @@ 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:
|
||||||
result = genSink(c, dest, ri)
|
if isUnpackedTuple(dest):
|
||||||
result.add p(ri, c, consumed)
|
result = newTree(nkFastAsgn, dest, p(ri, c, consumed))
|
||||||
of nkBracketExpr:
|
else:
|
||||||
if ri[0].kind == nkSym and isUnpackedTuple(ri[0].sym):
|
|
||||||
# unpacking of tuple: move out the elements
|
|
||||||
result = genSink(c, dest, ri)
|
result = genSink(c, dest, ri)
|
||||||
result.add p(ri, c, consumed)
|
result.add p(ri, c, consumed)
|
||||||
|
of nkBracketExpr:
|
||||||
|
if isUnpackedTuple(ri[0]):
|
||||||
|
# unpacking of tuple: take over elements
|
||||||
|
result = newTree(nkFastAsgn, dest, p(ri, c, consumed))
|
||||||
elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c):
|
elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c):
|
||||||
# Rule 3: `=sink`(x, z); wasMoved(z)
|
# Rule 3: `=sink`(x, z); wasMoved(z)
|
||||||
var snk = genSink(c, dest, ri)
|
var snk = genSink(c, dest, ri)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
var temp = newSym(skTemp, getIdent(g.cache, genPrefix), owner, value.info, g.config.options)
|
var temp = newSym(skTemp, getIdent(g.cache, genPrefix), owner, value.info, g.config.options)
|
||||||
temp.typ = skipTypes(value.typ, abstractInst)
|
temp.typ = skipTypes(value.typ, abstractInst)
|
||||||
incl(temp.flags, sfFromGeneric)
|
incl(temp.flags, sfFromGeneric)
|
||||||
incl(temp.flags, sfCursor)
|
|
||||||
|
|
||||||
var v = newNodeI(nkVarSection, value.info)
|
var v = newNodeI(nkVarSection, value.info)
|
||||||
let tempAsNode = newSymNode(temp)
|
let tempAsNode = newSymNode(temp)
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,12 @@ test()
|
||||||
import tables
|
import tables
|
||||||
var t = initTable[string, seq[ptr int]]()
|
var t = initTable[string, seq[ptr int]]()
|
||||||
discard t.hasKeyOrPut("f1", @[])
|
discard t.hasKeyOrPut("f1", @[])
|
||||||
|
|
||||||
|
|
||||||
|
#############################################
|
||||||
|
### bug #12989
|
||||||
|
proc bug(start: (seq[int], int)) =
|
||||||
|
let (s, i) = start
|
||||||
|
|
||||||
|
let input = @[0]
|
||||||
|
bug((input, 0))
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ proc test(): auto =
|
||||||
var (a, b, _) = test()
|
var (a, b, _) = test()
|
||||||
|
|
||||||
doAssert assign_counter == 0
|
doAssert assign_counter == 0
|
||||||
doAssert sink_counter == 9 # XXX this is still silly and needs to be investigated
|
doAssert sink_counter == 6
|
||||||
|
|
||||||
# bug #11510
|
# bug #11510
|
||||||
proc main =
|
proc main =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue