summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-06-27 19:07:29 +0800
committerGitHub <noreply@github.com>2023-06-27 13:07:29 +0200
commite422b3c8605f7668b89468ec3f67285bf42e5049 (patch)
tree51754de01ada83c97e9cb591badfd9ca703a131b
parentd52b1d848e6e402971e9bd81e58f6d2553854372 (diff)
downloadNim-e422b3c8605f7668b89468ec3f67285bf42e5049.tar.gz
adds =destroy T support for strings and seqs (#22167)
* adds =destroy T support for strings and seqs

* fixes system

* fixes tests
-rw-r--r--compiler/liftdestructors.nim4
-rw-r--r--lib/system.nim8
-rw-r--r--tests/arc/topt_no_cursor.nim2
-rw-r--r--tests/destructor/tv2_cast.nim12
4 files changed, 16 insertions, 10 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim
index c25f089fd..eac2323aa 100644
--- a/compiler/liftdestructors.nim
+++ b/compiler/liftdestructors.nim
@@ -1069,7 +1069,7 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp
   let src = newSym(skParam, getIdent(g.cache, if kind == attachedTrace: "env" else: "src"),
                    idgen, result, info)
 
-  if kind == attachedDestructor and typ.kind == tyRef:
+  if kind == attachedDestructor and typ.kind in {tyRef, tyString, tySequence} and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}:
     dest.typ = typ
   else:
     dest.typ = makeVarType(typ.owner, typ, idgen)
@@ -1196,7 +1196,7 @@ proc patchBody(g: ModuleGraph; c: PContext; n: PNode; info: TLineInfo; idgen: Id
       if op != nil:
         if op.ast.isGenericRoutine:
           internalError(g.config, info, "resolved destructor is generic")
-        if op.magic == mDestroy:
+        if op.magic == mDestroy and t.kind != tyString:
           internalError(g.config, info, "patching mDestroy with mDestroy?")
         n[0] = newSymNode(op)
   for x in n: patchBody(g, c, x, info, idgen)
diff --git a/lib/system.nim b/lib/system.nim
index d4835b20b..845ab58e6 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -365,7 +365,13 @@ proc arrGet[I: Ordinal;T](a: T; i: I): T {.
 proc arrPut[I: Ordinal;T,S](a: T; i: I;
   x: S) {.noSideEffect, magic: "ArrPut".}
 
-when defined(nimAllowNonVarDestructor):
+when defined(nimAllowNonVarDestructor) and arcLikeMem:
+  proc `=destroy`*(x: string) {.inline, magic: "Destroy".} =
+    discard
+
+  proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} =
+    discard
+
   proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} =
     discard
 
diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim
index 39e5c8a9b..7cfb0a0d5 100644
--- a/tests/arc/topt_no_cursor.nim
+++ b/tests/arc/topt_no_cursor.nim
@@ -95,7 +95,7 @@ try:
         finally:
           `=destroy`(splitted)
 finally:
-  `=destroy_1`(lan_ip)
+  `=destroy`(lan_ip)
 -- end of expandArc ------------------------
 --expandArc: mergeShadowScope
 
diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim
index 4ff2dc9a0..6fcb5994c 100644
--- a/tests/destructor/tv2_cast.nim
+++ b/tests/destructor/tv2_cast.nim
@@ -20,8 +20,8 @@ data =
     :tmpD_2))
   :tmpD
 `=destroy`(:tmpD_2)
-`=destroy_1`(:tmpD_1)
-`=destroy_1`(data)
+`=destroy`(:tmpD_1)
+`=destroy`(data)
 -- end of expandArc ------------------------
 --expandArc: main1
 
@@ -37,8 +37,8 @@ data =
     :tmpD_1))
   :tmpD
 `=destroy`(:tmpD_1)
-`=destroy_1`(data)
-`=destroy_1`(s)
+`=destroy`(data)
+`=destroy`(s)
 -- end of expandArc ------------------------
 --expandArc: main2
 
@@ -54,7 +54,7 @@ data =
     :tmpD_1))
   :tmpD
 `=destroy`(:tmpD_1)
-`=destroy_1`(data)
+`=destroy`(data)
 `=destroy`(s)
 -- end of expandArc ------------------------
 --expandArc: main3
@@ -73,7 +73,7 @@ data =
   :tmpD
 `=destroy`(:tmpD_2)
 `=destroy`(:tmpD_1)
-`=destroy_1`(data)
+`=destroy`(data)
 -- end of expandArc ------------------------
 '''
 """