From e113bee1becc09c87d85f18434920e70caeb1f6b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 11 May 2026 19:14:17 +0800 Subject: [PATCH] use `semMove` --- compiler/semcall.nim | 13 ------------- compiler/semmagic.nim | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index a43a13d2d3..48d29610e5 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -853,12 +853,6 @@ proc compactVoidArgs(n: PNode): PNode = if n[i] != nil: result.add n[i] -proc hasOverriddenWasMoved(c: PContext; call: PNode): bool = - if call.len != 2 or call[1].typ == nil: return false - let typ = call[1].typ.skipTypes({tyAlias, tyVar, tySink}) - let op = getAttachedOp(c.graph, typ, attachedWasMoved) - result = op != nil and sfOverridden in op.flags - proc semResolvedCall(c: PContext, x: var TCandidate, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode = @@ -886,13 +880,6 @@ proc semResolvedCall(c: PContext, x: var TCandidate, else: c.inheritBindings(x, expectedType) finalCallee = generateInstance(c, x.calleeSym, x.bindings, n.info) - if x.calleeSym.magic == mMove and hasOverriddenWasMoved(c, x.call): - # Let system.move[T]'s instantiated body perform the overridable - # =wasMoved call. The mMove codegen path stays the compact default - # implementation for non-overridden hooks. - ensureMutable finalCallee - finalCallee.magic = mNone - setOwner(finalCallee, c.module) else: # For macros and templates, the resolved generic params # are added as normal params. diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 397c08bf67..4bca7bbb58 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -591,6 +591,22 @@ proc checkDefault(c: PContext, n: PNode): PNode = if constructed.requiresInit: message(c.config, n.info, warnUnsafeDefault, typeToString(constructed)) +proc hasOverriddenWasMoved(c: PContext; n: PNode): bool = + if n.len != 2 or n[1].typ == nil: return false + let typ = n[1].typ.skipTypes({tyAlias, tyVar, tySink}) + let op = getAttachedOp(c.graph, typ, attachedWasMoved) + result = op != nil and sfOverridden in op.flags + +proc semMove(c: PContext; n: PNode): PNode = + result = n + if hasOverriddenWasMoved(c, n): + # Use the instantiated body of system.move[T] for overridden hooks so + # normal semantic lowering/codegen handles the =wasMoved call. + let callee = result[0].sym + ensureMutable callee + callee.magic = mNone + setOwner(callee, c.module) + proc magicsAfterOverloadResolution(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode = ## This is the preferred code point to implement magics. @@ -655,6 +671,8 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, result = n else: result = addDefaultFieldForNew(c, n) + of mMove: + result = semMove(c, n) of mNewFinalize: result = semNewFinalize(c, n) of mDestroy: