summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-06-07 21:13:34 +0800
committerGitHub <noreply@github.com>2023-06-07 15:13:34 +0200
commit47fa7506ab8105eac80fac50a9f01ef89ba95cc3 (patch)
tree0a62b7f807d318d7e5f03e28a5b25935248bfab8
parentebecfbc7a5915ca61bb340965fb1e50f6c66eb37 (diff)
downloadNim-47fa7506ab8105eac80fac50a9f01ef89ba95cc3.tar.gz
fixes #21989; lift `=dup` from a custom `=copy` for objects to keep backward compatibilities (#22009)
* fixes #21989; optimize `=dup` iff it is overridden

* remove owned

* fixes refs

* lift destructors

* lift dup
-rw-r--r--compiler/liftdestructors.nim11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim
index e8f25f1a3..0ac54a3ee 100644
--- a/compiler/liftdestructors.nim
+++ b/compiler/liftdestructors.nim
@@ -979,7 +979,16 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
         else:
           fillBodyObjT(c, t, body, x, y)
       else:
-        fillBodyObjT(c, t, body, x, y)
+        if c.kind == attachedDup:
+          var op2 = getAttachedOp(c.g, t, attachedAsgn)
+          if op2 != nil and sfOverriden in op2.flags:
+            #markUsed(c.g.config, c.info, op, c.g.usageSym)
+            onUse(c.info, op2)
+            body.add newHookCall(c, t.assignment, x, y)
+          else:
+            fillBodyObjT(c, t, body, x, y)
+        else:
+          fillBodyObjT(c, t, body, x, y)
   of tyDistinct:
     if not considerUserDefinedOp(c, t, body, x, y):
       fillBody(c, t[0], body, x, y)