move analyser is smarter; refs #11053
This commit is contained in:
parent
abb05ab645
commit
a394d31746
2 changed files with 17 additions and 9 deletions
|
|
@ -634,11 +634,14 @@ proc isAnalysableFieldAccess*(n: PNode; owner: PSym): bool =
|
||||||
# XXX Allow closure deref operations here if we know
|
# XXX Allow closure deref operations here if we know
|
||||||
# the owner controlled the closure allocation?
|
# the owner controlled the closure allocation?
|
||||||
result = n.kind == nkSym and n.sym.owner == owner and
|
result = n.kind == nkSym and n.sym.owner == owner and
|
||||||
owner.kind != skModule and (n.sym.kind != skParam or isSinkParam(n.sym))
|
owner.kind != skModule and
|
||||||
|
(n.sym.kind != skParam or isSinkParam(n.sym)) # or n.sym.typ.kind == tyVar)
|
||||||
|
|
||||||
proc genDef(c: var Con; n: PNode) =
|
proc genDef(c: var Con; n: PNode) =
|
||||||
if n.kind == nkSym and n.sym.kind in InterestingSyms:
|
if n.kind == nkSym and n.sym.kind in InterestingSyms:
|
||||||
c.code.add Instr(n: n, kind: def, sym: n.sym)
|
c.code.add Instr(n: n, kind: def, sym: n.sym)
|
||||||
|
elif isAnalysableFieldAccess(n, c.owner):
|
||||||
|
c.code.add Instr(n: n, kind: def, sym: nil)
|
||||||
|
|
||||||
proc canRaise(fn: PNode): bool =
|
proc canRaise(fn: PNode): bool =
|
||||||
const magicsThatCanRaise = {
|
const magicsThatCanRaise = {
|
||||||
|
|
|
||||||
|
|
@ -317,7 +317,6 @@ proc makePtrType(c: Con, baseType: PType): PType =
|
||||||
proc genOp(c: Con; t: PType; kind: TTypeAttachedOp; dest, ri: PNode): PNode =
|
proc genOp(c: Con; t: PType; kind: TTypeAttachedOp; dest, ri: PNode): PNode =
|
||||||
var op = t.attachedOps[kind]
|
var op = t.attachedOps[kind]
|
||||||
|
|
||||||
when false:
|
|
||||||
if op == nil:
|
if op == nil:
|
||||||
# give up and find the canonical type instead:
|
# give up and find the canonical type instead:
|
||||||
let h = sighashes.hashType(t, {CoType, CoConsiderOwned})
|
let h = sighashes.hashType(t, {CoType, CoConsiderOwned})
|
||||||
|
|
@ -535,6 +534,12 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
|
||||||
if ri[0].kind == nkSym and isUnpackedTuple(ri[0].sym):
|
if ri[0].kind == nkSym and isUnpackedTuple(ri[0].sym):
|
||||||
# unpacking of tuple: move out the elements
|
# unpacking of tuple: move out the elements
|
||||||
result = genSink(c, dest.typ, dest, ri)
|
result = genSink(c, dest.typ, dest, ri)
|
||||||
|
result.add p(ri, c)
|
||||||
|
elif isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c):
|
||||||
|
# Rule 3: `=sink`(x, z); wasMoved(z)
|
||||||
|
var snk = genSink(c, dest.typ, dest, ri)
|
||||||
|
snk.add ri
|
||||||
|
result = newTree(nkStmtList, snk, genWasMoved(ri, c))
|
||||||
else:
|
else:
|
||||||
result = genCopy(c, dest.typ, dest, ri)
|
result = genCopy(c, dest.typ, dest, ri)
|
||||||
result.add p(ri, c)
|
result.add p(ri, c)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue