diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/astalgo.nim | 3 | ||||
-rw-r--r-- | compiler/destroyer.nim | 29 | ||||
-rw-r--r-- | compiler/semexprs.nim | 1 |
4 files changed, 8 insertions, 27 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 899019514..7a21f49ff 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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} diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index be8d23b90..62d49445b 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -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 diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index b3b8f9f70..9b49a9500 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -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) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 820522f64..89cc53e1f 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) |