diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-06-02 22:03:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-02 16:03:32 +0200 |
commit | 1133f20fe2c834d14454c32d7d9fc2cd1fe8ffa2 (patch) | |
tree | 6eb03f314132d5022d6ebfdc7d4b706dfa8cfb5f /tests | |
parent | ead7e20926b1f5ea1b06679947d3d16fcc085e68 (diff) | |
download | Nim-1133f20fe2c834d14454c32d7d9fc2cd1fe8ffa2.tar.gz |
lift the `=dup` hook (#21903)
* fixes tests again * remove helper functions * fixes closures, owned refs * final cleanup
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arc/tdup.nim | 7 | ||||
-rw-r--r-- | tests/arc/topt_no_cursor.nim | 15 | ||||
-rw-r--r-- | tests/arc/topt_wasmoved_destroy_pairs.nim | 3 | ||||
-rw-r--r-- | tests/destructor/tatomicptrs.nim | 10 | ||||
-rw-r--r-- | tests/destructor/tmatrix.nim | 5 | ||||
-rw-r--r-- | tests/destructor/tprevent_assign2.nim | 7 | ||||
-rw-r--r-- | tests/destructor/tprevent_assign3.nim | 7 | ||||
-rw-r--r-- | tests/destructor/tv2_cast.nim | 14 |
8 files changed, 35 insertions, 33 deletions
diff --git a/tests/arc/tdup.nim b/tests/arc/tdup.nim index b77f5c6eb..61f262a68 100644 --- a/tests/arc/tdup.nim +++ b/tests/arc/tdup.nim @@ -18,7 +18,7 @@ inc: var id_1 = 777 s = RefCustom(id_2: addr(id_1)) inc_1 : - :tmpD_1 = `=dup`(s) + :tmpD_1 = `=dup_1`(s) :tmpD_1 inc_1 : let blitTmp_1 = s @@ -34,14 +34,15 @@ type RefCustom = object id: ptr int +proc `=dup`(x: RefCustom): RefCustom = + result.id = x.id + proc inc(x: sink Ref) = inc x.id proc inc(x: sink RefCustom) = inc x.id[] -proc `=dup`(x: RefCustom): RefCustom = - result.id = x.id proc foo = var x = Ref(id: 8) diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index 32652b60a..39e5c8a9b 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -61,11 +61,9 @@ var try: it_cursor = x a = ( - `=wasMoved`(:tmpD) - `=copy`(:tmpD, it_cursor.key) + :tmpD = `=dup`(it_cursor.key) :tmpD, - `=wasMoved`(:tmpD_1) - `=copy`(:tmpD_1, it_cursor.val) + :tmpD_1 = `=dup`(it_cursor.val) :tmpD_1) echo [ :tmpD_2 = `$$`(a) @@ -125,19 +123,16 @@ this.isValid = fileExists(this.value) if dirExists(this.value): var :tmpD par = (dir: - `=wasMoved`(:tmpD) - `=copy`(:tmpD, this.value) + :tmpD = `=dup`(this.value) :tmpD, front: "") else: var :tmpD_1 :tmpD_2 :tmpD_3 par = (dir_1: parentDir(this.value), front_1: - `=wasMoved`(:tmpD_1) - `=copy`(:tmpD_1, + :tmpD_1 = `=dup`( :tmpD_3 = splitDrive do: - `=wasMoved`(:tmpD_2) - `=copy`(:tmpD_2, this.value) + :tmpD_2 = `=dup`(this.value) :tmpD_2 :tmpD_3.path) :tmpD_1) diff --git a/tests/arc/topt_wasmoved_destroy_pairs.nim b/tests/arc/topt_wasmoved_destroy_pairs.nim index 6577d6787..c96340a30 100644 --- a/tests/arc/topt_wasmoved_destroy_pairs.nim +++ b/tests/arc/topt_wasmoved_destroy_pairs.nim @@ -39,8 +39,7 @@ try: if i_cursor == 2: return add(a): - `=wasMoved`(:tmpD) - `=copy`(:tmpD, x) + :tmpD = `=dup`(x) :tmpD inc i_1, 1 if cond: diff --git a/tests/destructor/tatomicptrs.nim b/tests/destructor/tatomicptrs.nim index 88f84d67c..7bd5482b2 100644 --- a/tests/destructor/tatomicptrs.nim +++ b/tests/destructor/tatomicptrs.nim @@ -39,7 +39,7 @@ proc `=destroy`*[T](dest: var SharedPtr[T]) = echo "deallocating" dest.x = nil -proc `=`*[T](dest: var SharedPtr[T]; src: SharedPtr[T]) = +proc `=copy`*[T](dest: var SharedPtr[T]; src: SharedPtr[T]) = var s = src.x if s != nil: incRef(s) #atomicSwap(dest, s) @@ -50,6 +50,9 @@ proc `=`*[T](dest: var SharedPtr[T]; src: SharedPtr[T]) = deallocShared(s) echo "deallocating" +proc `=dup`*[T](src: SharedPtr[T]): SharedPtr[T] = + `=copy`(result, src) + proc `=sink`*[T](dest: var SharedPtr[T]; src: SharedPtr[T]) = ## XXX make this an atomic store: if dest.x != src.x: @@ -120,7 +123,7 @@ proc `=destroy`*[T](m: var MySeq[T]) {.inline.} = deallocShared(m.data) m.data = nil -proc `=`*[T](m: var MySeq[T], m2: MySeq[T]) = +proc `=copy`*[T](m: var MySeq[T], m2: MySeq[T]) = if m.data == m2.data: return if m.data != nil: `=destroy`(m) @@ -131,6 +134,9 @@ proc `=`*[T](m: var MySeq[T], m2: MySeq[T]) = m.data = cast[ptr UncheckedArray[T]](allocShared(bytes)) copyMem(m.data, m2.data, bytes) +proc `=dup`*[T](m: MySeq[T]): MySeq[T] = + `=copy`[T](result, m) + proc `=sink`*[T](m: var MySeq[T], m2: MySeq[T]) {.inline.} = if m.data != m2.data: if m.data != nil: diff --git a/tests/destructor/tmatrix.nim b/tests/destructor/tmatrix.nim index 98ca95c94..2fd5af789 100644 --- a/tests/destructor/tmatrix.nim +++ b/tests/destructor/tmatrix.nim @@ -31,7 +31,7 @@ proc `=sink`*(a: var Matrix; b: Matrix) = a.m = b.m a.n = b.n -proc `=`*(a: var Matrix; b: Matrix) = +proc `=copy`*(a: var Matrix; b: Matrix) = if a.data != nil and a.data != b.data: dealloc(a.data) deallocCount.inc @@ -43,6 +43,9 @@ proc `=`*(a: var Matrix; b: Matrix) = allocCount.inc copyMem(a.data, b.data, b.m * b.n * sizeof(float)) +proc `=dup`*(a: Matrix): Matrix = + `=copy`(result, a) + proc matrix*(m, n: int, s: float): Matrix = ## Construct an m-by-n constant matrix. result.m = m diff --git a/tests/destructor/tprevent_assign2.nim b/tests/destructor/tprevent_assign2.nim index fd1a711db..7d788fa5c 100644 --- a/tests/destructor/tprevent_assign2.nim +++ b/tests/destructor/tprevent_assign2.nim @@ -1,7 +1,7 @@ discard """ - errormsg: "'=copy' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" + errormsg: "'=dup' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" file: "tprevent_assign2.nim" - line: 48 + line: 49 """ type @@ -9,7 +9,8 @@ type x: int proc `=destroy`(f: var Foo) = f.x = 0 -proc `=`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=copy`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=dup`(a: Foo): Foo {.error.} proc `=sink`(a: var Foo; b: Foo) = a.x = b.x proc createTree(x: int): Foo = diff --git a/tests/destructor/tprevent_assign3.nim b/tests/destructor/tprevent_assign3.nim index b9bd40fa9..aa834a66c 100644 --- a/tests/destructor/tprevent_assign3.nim +++ b/tests/destructor/tprevent_assign3.nim @@ -1,7 +1,7 @@ discard """ - errormsg: "'=copy' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" + errormsg: "'=dup' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" file: "tprevent_assign3.nim" - line: 46 + line: 47 """ type @@ -9,7 +9,8 @@ type x: int proc `=destroy`(f: var Foo) = f.x = 0 -proc `=`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=copy`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=dup`(a: Foo): Foo {.error.} proc `=sink`(a: var Foo; b: Foo) = a.x = b.x proc createTree(x: int): Foo = diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim index 6fa419996..4ff2dc9a0 100644 --- a/tests/destructor/tv2_cast.nim +++ b/tests/destructor/tv2_cast.nim @@ -3,7 +3,7 @@ discard """ @[116, 101, 115, 116] @[1953719668, 875770417] destroying O1''' - cmd: '''nim c --gc:arc --expandArc:main --expandArc:main1 --expandArc:main2 --expandArc:main3 --hints:off --assertions:off $file''' + cmd: '''nim c --mm:arc --expandArc:main --expandArc:main1 --expandArc:main2 --expandArc:main3 --hints:off --assertions:off $file''' nimout: ''' --expandArc: main @@ -13,8 +13,7 @@ var :tmpD_1 :tmpD_2 data = - `=wasMoved`(:tmpD) - `=copy`(:tmpD, cast[string]( + :tmpD = `=dup`(cast[string]( :tmpD_2 = encode(cast[seq[byte]]( :tmpD_1 = newString(100) :tmpD_1)) @@ -33,8 +32,7 @@ var :tmpD_1 s = newString(100) data = - `=wasMoved`(:tmpD) - `=copy`(:tmpD, cast[string]( + :tmpD = `=dup`(cast[string]( :tmpD_1 = encode(toOpenArrayByte(s, 0, len(s) - 1)) :tmpD_1)) :tmpD @@ -51,8 +49,7 @@ var :tmpD_1 s = newSeq(100) data = - `=wasMoved`(:tmpD) - `=copy`(:tmpD, cast[string]( + :tmpD = `=dup`(cast[string]( :tmpD_1 = encode(s) :tmpD_1)) :tmpD @@ -68,8 +65,7 @@ var :tmpD_1 :tmpD_2 data = - `=wasMoved`(:tmpD) - `=copy`(:tmpD, cast[string]( + :tmpD = `=dup`(cast[string]( :tmpD_2 = encode do: :tmpD_1 = newSeq(100) :tmpD_1 |