owned refs must be moved
This commit is contained in:
parent
f8bf24623c
commit
5b1a2eecd5
4 changed files with 8 additions and 27 deletions
|
|
@ -1793,7 +1793,7 @@ when false:
|
||||||
for i in 0 ..< n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
if n[i].containsNil: return true
|
if n[i].containsNil: return true
|
||||||
|
|
||||||
template hasDestructor*(t: PType): bool = tfHasAsgn in t.flags
|
template hasDestructor*(t: PType): bool = {tfHasAsgn, tfHasOwned} * t.flags != {}
|
||||||
template incompleteType*(t: PType): bool =
|
template incompleteType*(t: PType): bool =
|
||||||
t.sym != nil and {sfForward, sfNoForward} * t.sym.flags == {sfForward}
|
t.sym != nil and {sfForward, sfNoForward} * t.sym.flags == {sfForward}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,9 @@ proc value(this: var DebugPrinter; value: PType): void =
|
||||||
this.key "kind"
|
this.key "kind"
|
||||||
this.value value.kind
|
this.value value.kind
|
||||||
|
|
||||||
|
this.key "id"
|
||||||
|
this.value value.id
|
||||||
|
|
||||||
if value.sym != nil:
|
if value.sym != nil:
|
||||||
this.key "sym"
|
this.key "sym"
|
||||||
this.value value.sym
|
this.value value.sym
|
||||||
|
|
|
||||||
|
|
@ -116,32 +116,7 @@ Rule Pattern Transformed into
|
||||||
5.4 f_noSink(g()) var tmp = bitwiseCopy(g()); f(tmp); `=destroy`(tmp)
|
5.4 f_noSink(g()) var tmp = bitwiseCopy(g()); f(tmp); `=destroy`(tmp)
|
||||||
|
|
||||||
Rule 3.2 describes a "cursor" variable, a variable that is only used as a
|
Rule 3.2 describes a "cursor" variable, a variable that is only used as a
|
||||||
view into some data structure. Rule 3.2 applies to value based
|
view into some data structure. See ``compiler/cursors.nim`` for details.
|
||||||
datatypes like strings and sequences and also ``ref`` cursors. We
|
|
||||||
seek to allow most forms of "scan" loops like::
|
|
||||||
|
|
||||||
var x = it
|
|
||||||
# scan loop:
|
|
||||||
while x != nil:
|
|
||||||
x.foo = value
|
|
||||||
x = x.next
|
|
||||||
|
|
||||||
The difference is that ``s[i] = y`` needs to be turned into a ``mut(s)``
|
|
||||||
for seqs and ``r.field = y`` is NOT turned into ``mut(r)`` as it doesn't
|
|
||||||
mutate the ``r`` itself. So the above loop is turned into something like::
|
|
||||||
|
|
||||||
use it
|
|
||||||
def x
|
|
||||||
L1:
|
|
||||||
fork L2
|
|
||||||
use value
|
|
||||||
use x
|
|
||||||
def x
|
|
||||||
L2:
|
|
||||||
|
|
||||||
Which means that ``x`` is detected as a "cursor". Rule 3.2 is not yet
|
|
||||||
implemented and requires either DFA changes or a different analysis.
|
|
||||||
Write-tracking also helps to compute this.
|
|
||||||
]##
|
]##
|
||||||
|
|
||||||
import
|
import
|
||||||
|
|
@ -357,6 +332,8 @@ proc genSink(c: Con; t: PType; dest, ri: PNode): PNode =
|
||||||
genOp(if t.sink != nil: t.sink else: t.assignment, "=sink", ri)
|
genOp(if t.sink != nil: t.sink else: t.assignment, "=sink", ri)
|
||||||
|
|
||||||
proc genCopy(c: Con; t: PType; dest, ri: PNode): PNode =
|
proc genCopy(c: Con; t: PType; dest, ri: PNode): PNode =
|
||||||
|
if tfHasOwned in t.flags:
|
||||||
|
checkForErrorPragma(c, t, ri, "=")
|
||||||
let t = t.skipTypes({tyGenericInst, tyAlias, tySink})
|
let t = t.skipTypes({tyGenericInst, tyAlias, tySink})
|
||||||
genOp(t.assignment, "=", ri)
|
genOp(t.assignment, "=", ri)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
if targetType.kind in {tySink, tyLent, tyOwned}:
|
if targetType.kind in {tySink, tyLent, tyOwned}:
|
||||||
let baseType = semTypeNode(c, n.sons[1], nil).skipTypes({tyTypeDesc})
|
let baseType = semTypeNode(c, n.sons[1], nil).skipTypes({tyTypeDesc})
|
||||||
let t = newTypeS(targetType.kind, c)
|
let t = newTypeS(targetType.kind, c)
|
||||||
|
t.flags.incl tfHasOwned
|
||||||
t.rawAddSonNoPropagationOfTypeFlags baseType
|
t.rawAddSonNoPropagationOfTypeFlags baseType
|
||||||
result = newNodeI(nkType, n.info)
|
result = newNodeI(nkType, n.info)
|
||||||
result.typ = makeTypeDesc(c, t)
|
result.typ = makeTypeDesc(c, t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue