use semMove

This commit is contained in:
ringabout
2026-05-11 19:14:17 +08:00
parent 1bb7817f65
commit e113bee1be
2 changed files with 18 additions and 13 deletions

View File

@@ -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.

View File

@@ -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: