From e1280319031b4a6b5b004e9e7a4436caea2a1829 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 21 Nov 2023 12:29:53 +0000 Subject: [PATCH 01/13] prepare to enforce Non-var T destructors --- compiler/liftdestructors.nim | 2 +- lib/system.nim | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 8995e1073bf18..e610289917104 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1092,7 +1092,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 in {tyRef, tyString, tySequence} and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}: + if kind == attachedDestructor and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}: dest.typ = typ else: dest.typ = makeVarType(typ.owner, typ, idgen) diff --git a/lib/system.nim b/lib/system.nim index 4f2a051632d35..edea14b088516 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -367,19 +367,14 @@ const arcLikeMem = defined(gcArc) or defined(gcAtomicArc) or defined(gcOrc) when defined(nimAllowNonVarDestructor) and arcLikeMem: - proc `=destroy`*(x: string) {.inline, magic: "Destroy".} = + proc `=destroy`*[T](x: T) {.inline, magic: "Destroy".} = + ## Generic `destructor`:idx: implementation that can be overridden. discard - - proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} = - discard - - proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} = +else: + proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} = + ## Generic `destructor`:idx: implementation that can be overridden. discard -proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} = - ## Generic `destructor`:idx: implementation that can be overridden. - discard - when defined(nimHasDup): proc `=dup`*[T](x: T): T {.inline, magic: "Dup".} = ## Generic `dup`:idx: implementation that can be overridden. From fc930cd62b511b18d07f0cd37115edaad10a812d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:13:50 +0000 Subject: [PATCH 02/13] fixes discrimantor assignments --- compiler/liftdestructors.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index e610289917104..8c0f4cb2be8a7 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1082,7 +1082,7 @@ proc symDupPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttache incl result.flags, sfGeneratedOp proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp; - info: TLineInfo; idgen: IdGenerator): PSym = + info: TLineInfo; idgen: IdGenerator; isDiscriminant = false): PSym = if kind == attachedDup: return symDupPrototype(g, typ, owner, kind, info, idgen) @@ -1092,7 +1092,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 g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}: + if kind == attachedDestructor and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and not isDiscriminant: dest.typ = typ else: dest.typ = makeVarType(typ.owner, typ, idgen) @@ -1185,7 +1185,8 @@ proc produceSym(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; proc produceDestructorForDiscriminator*(g: ModuleGraph; typ: PType; field: PSym, info: TLineInfo; idgen: IdGenerator): PSym = assert(typ.skipTypes({tyAlias, tyGenericInst}).kind == tyObject) - result = symPrototype(g, field.typ, typ.owner, attachedDestructor, info, idgen) + # discrimantor assignments needs pointers to destroy fields; alas, we cannot use non-var destructor here + result = symPrototype(g, field.typ, typ.owner, attachedDestructor, info, idgen, isDiscriminant = true) var a = TLiftCtx(info: info, g: g, kind: attachedDestructor, asgnForType: typ, idgen: idgen, fn: result) a.asgnForType = typ From ee13803e5516ba1c6a7d0619a0efd52351baa8b5 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 22 Nov 2023 02:10:57 +0000 Subject: [PATCH 03/13] fixes two tests --- tests/converter/tconverter_unique_ptr.nim | 18 +++++++++--------- tests/destructor/const_smart_ptr.nim | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/converter/tconverter_unique_ptr.nim b/tests/converter/tconverter_unique_ptr.nim index 23c1a3d96db3a..9ee0556594d90 100644 --- a/tests/converter/tconverter_unique_ptr.nim +++ b/tests/converter/tconverter_unique_ptr.nim @@ -22,12 +22,12 @@ proc `$`(x: MyLen): string {.borrow.} proc `==`(x1, x2: MyLen): bool {.borrow.} -proc `=destroy`*(m: var MySeq) {.inline.} = +proc `=destroy`*(m: MySeq) {.inline.} = if m.data != nil: deallocShared(m.data) - m.data = nil + (addr m.data)[] = nil -proc `=`*(m: var MySeq, m2: MySeq) = +proc `=copy`*(m: var MySeq, m2: MySeq) = if m.data == m2.data: return if m.data != nil: `=destroy`(m) @@ -77,13 +77,13 @@ converter literalToLen*(x: int{lit}): MyLen = # Unique pointer implementation #------------------------------------------------------------- -proc `=destroy`*[T](p: var UniquePtr[T]) = +proc `=destroy`*[T](p: UniquePtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - p.val = nil + (addr p.val)[] = nil -proc `=`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.error.} +proc `=copy`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.error.} proc `=sink`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.inline.} = if dest.val != nil and dest.val != src.val: @@ -118,13 +118,13 @@ type ## as it returns only `lent T` val: ptr T -proc `=destroy`*[T](p: var ConstPtr[T]) = +proc `=destroy`*[T](p: ConstPtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - p.val = nil + (addr p.val)[] = nil -proc `=`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} +proc `=copy`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} proc `=sink`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.inline.} = if dest.val != nil and dest.val != src.val: diff --git a/tests/destructor/const_smart_ptr.nim b/tests/destructor/const_smart_ptr.nim index 4d8c7c9a375ec..36f7d6d9ee2c5 100644 --- a/tests/destructor/const_smart_ptr.nim +++ b/tests/destructor/const_smart_ptr.nim @@ -2,13 +2,13 @@ type ConstPtr*[T] = object val: ptr T -proc `=destroy`*[T](p: var ConstPtr[T]) = +proc `=destroy`*[T](p: ConstPtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - p.val = nil + (addr p.val)[] = nil -proc `=`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} +proc `=copy`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} proc `=sink`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.inline.} = if dest.val != nil and dest.val != src.val: @@ -31,12 +31,12 @@ type len: int data: ptr UncheckedArray[float] -proc `=destroy`*(m: var MySeqNonCopyable) {.inline.} = +proc `=destroy`*(m: MySeqNonCopyable) {.inline.} = if m.data != nil: deallocShared(m.data) - m.data = nil + (addr m.data)[] = nil -proc `=`*(m: var MySeqNonCopyable, m2: MySeqNonCopyable) {.error.} +proc `=copy`*(m: var MySeqNonCopyable, m2: MySeqNonCopyable) {.error.} proc `=sink`*(m: var MySeqNonCopyable, m2: MySeqNonCopyable) {.inline.} = if m.data != m2.data: From b763198149b56bea83ebb133e0f9df66debbd6a9 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:57:35 +0000 Subject: [PATCH 04/13] fixes few tests --- tests/arc/topt_no_cursor.nim | 2 +- tests/ccgbugs/tforward_decl_only.nim | 1 - tests/destructor/tv2_cast.nim | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index b24e8e5a9d7b9..0a4984a690999 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -97,7 +97,7 @@ try: finally: `=destroy`(splitted) finally: - `=destroy`(lan_ip) + `=destroy_1`(lan_ip) -- end of expandArc ------------------------ --expandArc: mergeShadowScope diff --git a/tests/ccgbugs/tforward_decl_only.nim b/tests/ccgbugs/tforward_decl_only.nim index d62c36b180ab3..2a867bc3bec19 100644 --- a/tests/ccgbugs/tforward_decl_only.nim +++ b/tests/ccgbugs/tforward_decl_only.nim @@ -1,6 +1,5 @@ discard """ ccodecheck: "\\i !@('struct tyObject_MyRefObject'[0-z]+' {')" -ccodecheck: "\\i !@('mymoduleInit')" output: "hello" """ diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim index 6fcb5994c3a4e..4ff2dc9a07f19 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`(:tmpD_1) -`=destroy`(data) +`=destroy_1`(:tmpD_1) +`=destroy_1`(data) -- end of expandArc ------------------------ --expandArc: main1 @@ -37,8 +37,8 @@ data = :tmpD_1)) :tmpD `=destroy`(:tmpD_1) -`=destroy`(data) -`=destroy`(s) +`=destroy_1`(data) +`=destroy_1`(s) -- end of expandArc ------------------------ --expandArc: main2 @@ -54,7 +54,7 @@ data = :tmpD_1)) :tmpD `=destroy`(:tmpD_1) -`=destroy`(data) +`=destroy_1`(data) `=destroy`(s) -- end of expandArc ------------------------ --expandArc: main3 @@ -73,7 +73,7 @@ data = :tmpD `=destroy`(:tmpD_2) `=destroy`(:tmpD_1) -`=destroy`(data) +`=destroy_1`(data) -- end of expandArc ------------------------ ''' """ From 8b0bfbb34730069787501bd3df8246f013be7246 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:15:24 +0000 Subject: [PATCH 05/13] fixes tests --- compiler/liftdestructors.nim | 3 ++- tests/ccgbugs/tforward_decl_only.nim | 2 +- tests/gc/closureleak.nim | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 8c0f4cb2be8a7..42ea2ae94a0ae 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1092,7 +1092,8 @@ 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 g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and not isDiscriminant: + if kind == attachedDestructor and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and + not isDiscriminant: dest.typ = typ else: dest.typ = makeVarType(typ.owner, typ, idgen) diff --git a/tests/ccgbugs/tforward_decl_only.nim b/tests/ccgbugs/tforward_decl_only.nim index 2a867bc3bec19..b115dcbe70f2e 100644 --- a/tests/ccgbugs/tforward_decl_only.nim +++ b/tests/ccgbugs/tforward_decl_only.nim @@ -1,5 +1,5 @@ discard """ -ccodecheck: "\\i !@('struct tyObject_MyRefObject'[0-z]+' {')" +ccodecheck: "\\i !@('struct tyObject_MyRefObject'[0-z]+' _')" output: "hello" """ diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim index 0265431d04631..e67beb513d154 100644 --- a/tests/gc/closureleak.nim +++ b/tests/gc/closureleak.nim @@ -11,9 +11,19 @@ var foo_counter = 0 var alive_foos = newseq[int](0) when defined(gcDestructors): - proc `=destroy`(some: var TFoo) = + proc `=destroy`(some: TFoo) = alive_foos.del alive_foos.find(some.id) - `=destroy`(some.fn) + # TODO: fixme: investigate why `=destroy` requires `some.fn` to be `gcsafe` + # the debugging info below came from `symPrototype` in the liftdestructors + # proc (){.closure, gcsafe.}, {tfThread, tfHasAsgn, tfCheckedForDestructor, tfExplicitCallConv} + # var proc (){.closure, gcsafe.}, {tfHasGCedMem} + # it worked by accident with var T destructors because in the sempass2 + # + # let argtype = skipTypes(a.typ, abstractInst) # !!! it does't skip `tyVar` + # if argtype.kind == tyProc and notGcSafe(argtype) and not tracked.inEnforcedGcSafe: + # localError(tracked.config, n.info, $n & " is not GC safe") + {.cast(gcsafe).}: + `=destroy`(some.fn) else: proc free*(some: ref TFoo) = From f5e7983e3693b4e692aba4f88b4b0843549d1542 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:43:38 +0000 Subject: [PATCH 06/13] implement `nimPreviewNonVarDestructor` --- compiler/liftdestructors.nim | 2 +- compiler/nim.cfg | 1 + lib/system.nim | 12 +++++++++++- tests/config.nims | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 42ea2ae94a0ae..36d9d5b1a1648 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1093,7 +1093,7 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp idgen, result, info) if kind == attachedDestructor and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and - not isDiscriminant: + ((g.config.isDefined("nimPreviewNonVarDestructor") and not isDiscriminant) or typ.kind in {tyRef, tyString, tySequence}): dest.typ = typ else: dest.typ = makeVarType(typ.owner, typ, idgen) diff --git a/compiler/nim.cfg b/compiler/nim.cfg index e4425065e704c..8488cb9efcb6c 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -9,6 +9,7 @@ define:nimPreviewSlimSystem define:nimPreviewCstringConversion define:nimPreviewProcConversion define:nimPreviewRangeDefault +define:nimPreviewNonVarDestructor threads:off #import:"$projectpath/testability" diff --git a/lib/system.nim b/lib/system.nim index edea14b088516..5d0bbb9c7f672 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -366,7 +366,7 @@ proc arrPut[I: Ordinal;T,S](a: T; i: I; const arcLikeMem = defined(gcArc) or defined(gcAtomicArc) or defined(gcOrc) -when defined(nimAllowNonVarDestructor) and arcLikeMem: +when defined(nimAllowNonVarDestructor) and arcLikeMem and defined(nimPreviewNonVarDestructor): proc `=destroy`*[T](x: T) {.inline, magic: "Destroy".} = ## Generic `destructor`:idx: implementation that can be overridden. discard @@ -375,6 +375,16 @@ else: ## Generic `destructor`:idx: implementation that can be overridden. discard + 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 + when defined(nimHasDup): proc `=dup`*[T](x: T): T {.inline, magic: "Dup".} = ## Generic `dup`:idx: implementation that can be overridden. diff --git a/tests/config.nims b/tests/config.nims index b288bec2ae11d..e0de65fc42fc7 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -40,6 +40,7 @@ switch("define", "nimPreviewFloatRoundtrip") switch("define", "nimPreviewJsonutilsHoleyEnum") switch("define", "nimPreviewHashRef") switch("define", "nimPreviewRangeDefault") +switch("define", "nimPreviewNonVarDestructor") switch("warningAserror", "UnnamedBreak") switch("legacy", "verboseTypeMismatch") From 3c154085b0e01d334a73f2fd0fe2f31785bac836 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 23 Nov 2023 02:36:38 +0000 Subject: [PATCH 07/13] adds a test case for #22975 --- tests/destructor/tnonvardestructor.nim | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/destructor/tnonvardestructor.nim b/tests/destructor/tnonvardestructor.nim index 1f59a397839f6..1b44137906ea1 100644 --- a/tests/destructor/tnonvardestructor.nim +++ b/tests/destructor/tnonvardestructor.nim @@ -152,7 +152,7 @@ type Graph = object nodes: seq[Node] -proc `=destroy`(x: var NodeObj) = +proc `=destroy`(x: NodeObj) = `=destroy`(x.neighbors) `=destroy`(x.label) @@ -210,7 +210,7 @@ block: # bug #22197 ## If this does not exist, it also works! proc newFileID(): FileID = FileID(H5Id()) - proc `=destroy`(grp: var H5GroupObj) = + proc `=destroy`(grp: H5GroupObj) = ## Closes the group and resets all references to nil. if cast[pointer](grp.fileId) != nil: `=destroy`(grp.file_id) @@ -218,3 +218,30 @@ block: # bug #22197 var grp = H5Group() reset(grp.file_id) reset(grp) + +import std/tables + +block: # bug #22286 + type + A = object + B = object + a: A + C = object + b: B + + proc `=destroy`(self: A) = + echo "destroyed" + + proc `=destroy`(self: C) = + `=destroy`(self.b) + + var c = C() + +block: # https://forum.nim-lang.org/t/10642 + type AObj = object + name: string + tableField: Table[string, string] + + proc `=destroy`(x: AObj) = + `=destroy`(x.name) + `=destroy`(x.tableField) From d31a8e0c01260d9386ff8e74a140e06ac2581806 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 23 Nov 2023 02:36:44 +0000 Subject: [PATCH 08/13] adds a changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 3351a6f7a0526..ab121f5a13594 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ - `-d:nimStrictDelete` becomes the default. An index error is produced when the index passed to `system.delete` was out of bounds. Use `-d:nimAuditDelete` to mimic the old behavior for backwards compatibility. - The default user-agent in `std/httpclient` has been changed to `Nim-httpclient/` instead of `Nim httpclient/` which was incorrect according to the HTTP spec. +- With `-d:nimPreviewNonVarDestructor`, non-var destructors become the default. ## Standard library additions and changes From 54fad7949ebb1d8586e53256dba1fff6ef4520d6 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 23 Nov 2023 04:11:45 +0000 Subject: [PATCH 09/13] try to fix tests/arc/thard_alignment --- lib/system.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/system.nim b/lib/system.nim index 5d0bbb9c7f672..9dea2e57d556b 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -370,6 +370,10 @@ when defined(nimAllowNonVarDestructor) and arcLikeMem and defined(nimPreviewNonV proc `=destroy`*[T](x: T) {.inline, magic: "Destroy".} = ## Generic `destructor`:idx: implementation that can be overridden. discard + + proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} = + ## TODO: fixme why is it needed by tests/arc/thard_alignment??? + discard else: proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} = ## Generic `destructor`:idx: implementation that can be overridden. From d8a888a51096fbb0eb9c272afb753355f0687a78 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:40:00 +0000 Subject: [PATCH 10/13] fixes thard_alignment --- lib/system.nim | 4 ---- tests/arc/thard_alignment.nim | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 9dea2e57d556b..5d0bbb9c7f672 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -370,10 +370,6 @@ when defined(nimAllowNonVarDestructor) and arcLikeMem and defined(nimPreviewNonV proc `=destroy`*[T](x: T) {.inline, magic: "Destroy".} = ## Generic `destructor`:idx: implementation that can be overridden. discard - - proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} = - ## TODO: fixme why is it needed by tests/arc/thard_alignment??? - discard else: proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} = ## Generic `destructor`:idx: implementation that can be overridden. diff --git a/tests/arc/thard_alignment.nim b/tests/arc/thard_alignment.nim index baa964c77dbe9..c376635bb2119 100644 --- a/tests/arc/thard_alignment.nim +++ b/tests/arc/thard_alignment.nim @@ -1,6 +1,6 @@ discard """ disabled: "arm64" -cmd: "nim c --gc:arc $file" +cmd: "nim c --gc:arc -u:nimPreviewNonVarDestructor $file" output: "y" """ From 99adaa81b1a8802dbdb533cae7019c20ec4ca5d4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:51:21 +0000 Subject: [PATCH 11/13] adds fixme comments --- tests/arc/thard_alignment.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/arc/thard_alignment.nim b/tests/arc/thard_alignment.nim index c376635bb2119..30cfddb055319 100644 --- a/tests/arc/thard_alignment.nim +++ b/tests/arc/thard_alignment.nim @@ -1,9 +1,11 @@ discard """ disabled: "arm64" -cmd: "nim c --gc:arc -u:nimPreviewNonVarDestructor $file" +cmd: "nim c --mm:arc -u:nimPreviewNonVarDestructor $file" output: "y" """ +# TODO: fixme: investigate why it failed with non-var destructors + {.passC: "-march=native".} proc isAlignedCheck(p: pointer, alignment: int) = From e53d6e4e4989f42103408bd4df87f49b5035defc Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:24:59 +0800 Subject: [PATCH 12/13] Apply suggestions from code review Co-authored-by: Andreas Rumpf --- tests/converter/tconverter_unique_ptr.nim | 2 -- tests/destructor/const_smart_ptr.nim | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/converter/tconverter_unique_ptr.nim b/tests/converter/tconverter_unique_ptr.nim index 9ee0556594d90..4c947aff4c18e 100644 --- a/tests/converter/tconverter_unique_ptr.nim +++ b/tests/converter/tconverter_unique_ptr.nim @@ -81,7 +81,6 @@ proc `=destroy`*[T](p: UniquePtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - (addr p.val)[] = nil proc `=copy`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.error.} @@ -122,7 +121,6 @@ proc `=destroy`*[T](p: ConstPtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - (addr p.val)[] = nil proc `=copy`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} diff --git a/tests/destructor/const_smart_ptr.nim b/tests/destructor/const_smart_ptr.nim index 36f7d6d9ee2c5..25dd46500d9f5 100644 --- a/tests/destructor/const_smart_ptr.nim +++ b/tests/destructor/const_smart_ptr.nim @@ -6,7 +6,6 @@ proc `=destroy`*[T](p: ConstPtr[T]) = if p.val != nil: `=destroy`(p.val[]) dealloc(p.val) - (addr p.val)[] = nil proc `=copy`*[T](dest: var ConstPtr[T], src: ConstPtr[T]) {.error.} @@ -34,7 +33,6 @@ type proc `=destroy`*(m: MySeqNonCopyable) {.inline.} = if m.data != nil: deallocShared(m.data) - (addr m.data)[] = nil proc `=copy`*(m: var MySeqNonCopyable, m2: MySeqNonCopyable) {.error.} From ec827903bd07d368428aefa833c12f4ccfd41a22 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 25 Nov 2023 19:08:45 +0800 Subject: [PATCH 13/13] Update tests/converter/tconverter_unique_ptr.nim Co-authored-by: Andreas Rumpf --- tests/converter/tconverter_unique_ptr.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/converter/tconverter_unique_ptr.nim b/tests/converter/tconverter_unique_ptr.nim index 4c947aff4c18e..6902f9e9e0ce1 100644 --- a/tests/converter/tconverter_unique_ptr.nim +++ b/tests/converter/tconverter_unique_ptr.nim @@ -25,7 +25,6 @@ proc `==`(x1, x2: MyLen): bool {.borrow.} proc `=destroy`*(m: MySeq) {.inline.} = if m.data != nil: deallocShared(m.data) - (addr m.data)[] = nil proc `=copy`*(m: var MySeq, m2: MySeq) = if m.data == m2.data: return