[SIL] Hollow out Builtin.copy, deprecate _copy.

The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
This commit is contained in:
Nate Chandler
2024-05-03 15:53:36 -07:00
parent 6fdaea514f
commit 06921cfe84
20 changed files with 98 additions and 260 deletions

View File

@@ -320,7 +320,6 @@ protected:
void visitHopToExecutorInst(HopToExecutorInst *Inst);
void visitTerminator(SILBasicBlock *BB);
void visitBuiltinInst(BuiltinInst *BI);
/// This hook is called after either of the top-level visitors:
/// cloneReachableBlocks or cloneSILFunction.
@@ -820,51 +819,6 @@ static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
Context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
}
void SILInlineCloner::visitBuiltinInst(BuiltinInst *Inst) {
if (IKind == InlineKind::MandatoryInline) {
if (auto kind = Inst->getBuiltinKind()) {
if (*kind == BuiltinValueKind::Copy) {
auto otherResultAddr = getOpValue(Inst->getOperand(0));
auto otherSrcAddr = getOpValue(Inst->getOperand(1));
auto otherType = otherSrcAddr->getType();
if (!otherType.isLoadable(*Inst->getFunction())) {
// If otherType is not loadable, emit a diagnostic since it was used
// on a generic or existential value.
diagnose(Inst->getModule().getASTContext(),
getOpLocation(Inst->getLoc()).getSourceLoc(),
diag::copy_operator_used_on_generic_or_existential_value);
return SILCloner<SILInlineCloner>::visitBuiltinInst(Inst);
}
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
// We stash otherValue in originalOtherValue in case we need to
// perform a writeback.
auto opLoc = getOpLocation(Inst->getLoc());
assert(otherType.isAddress());
// Perform a load_borrow and then copy that.
SILValue otherValue =
getBuilder().emitLoadBorrowOperation(opLoc, otherSrcAddr);
auto *mvi = getBuilder().createExplicitCopyValue(opLoc, otherValue);
getBuilder().emitStoreValueOperation(opLoc, mvi, otherResultAddr,
StoreOwnershipQualifier::Init);
// End the borrowed value.
getBuilder().emitEndBorrowOperation(opLoc, otherValue);
// We know that Inst returns a tuple value that isn't used by anything
// else, so this /should/ be safe.
return recordClonedInstruction(Inst, mvi);
}
}
}
return SILCloner<SILInlineCloner>::visitBuiltinInst(Inst);
}
//===----------------------------------------------------------------------===//
// Cost Model
//===----------------------------------------------------------------------===//