mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 11:12:37 +00:00
owned refs must be moved
This commit is contained in:
@@ -1793,7 +1793,7 @@ when false:
|
||||
for i in 0 ..< n.safeLen:
|
||||
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 =
|
||||
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.value value.kind
|
||||
|
||||
this.key "id"
|
||||
this.value value.id
|
||||
|
||||
if value.sym != nil:
|
||||
this.key "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)
|
||||
|
||||
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
|
||||
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.
|
||||
view into some data structure. See ``compiler/cursors.nim`` for details.
|
||||
]##
|
||||
|
||||
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)
|
||||
|
||||
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})
|
||||
genOp(t.assignment, "=", ri)
|
||||
|
||||
|
||||
@@ -227,6 +227,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||
if targetType.kind in {tySink, tyLent, tyOwned}:
|
||||
let baseType = semTypeNode(c, n.sons[1], nil).skipTypes({tyTypeDesc})
|
||||
let t = newTypeS(targetType.kind, c)
|
||||
t.flags.incl tfHasOwned
|
||||
t.rawAddSonNoPropagationOfTypeFlags baseType
|
||||
result = newNodeI(nkType, n.info)
|
||||
result.typ = makeTypeDesc(c, t)
|
||||
|
||||
Reference in New Issue
Block a user