Skip to content

Commit 06921cf

Browse files
committed
[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
1 parent 6fdaea5 commit 06921cf

20 files changed

+98
-260
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ extension AddressUseVisitor {
165165

166166
case let builtin as BuiltinInst:
167167
switch builtin.id {
168-
case .Copy where builtin.operands[1] == operand: // source
169-
return loadedAddressUse(of: operand, into: builtin.operands[0])
170-
171-
case .Copy where builtin.operands[0] == operand: // dest
172-
return leafAddressUse(of: operand)
173-
174168
// Builtins that cannot load a nontrivial value.
175169
case .TSanInoutAccess, .ResumeThrowingContinuationReturning,
176170
.ResumeNonThrowingContinuationReturning, .GenericAdd,

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,6 @@ extension LifetimeDependenceDefUseWalker {
909909
case let tai as TupleAddrConstructorInst:
910910
return visitStoredUses(of: operand, into: tai.destinationOperand.value)
911911

912-
case let bi as BuiltinInst where bi.id == .Copy:
913-
// This must be a non-address-lowered form of Builtin.Copy that
914-
// produces an owned value.
915-
assert(bi.ownership == .owned)
916-
return walkDownUses(of: bi, using: operand)
917-
918912
default:
919913
return nonForwardingUse(of: operand)
920914
}

include/swift/AST/Builtins.def

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ BUILTIN_SIL_OPERATION(HopToActor, "hopToActor", None)
537537
/// Returns the number of items in a pack.
538538
BUILTIN_SIL_OPERATION(PackLength, "packLength", Special)
539539

540+
/// TODO: Remove. Only exists to avoid a reverse condfail.
541+
/// rdar://127516085 (Complete removal of Builtin.copy)
542+
///
543+
/// copy: <T>(T) -> T
544+
///
545+
/// Creates a copy of the source at the destination.
546+
BUILTIN_SIL_OPERATION(Copy, "copy", Special)
547+
540548
// BUILTIN_RUNTIME_CALL - A call into a runtime function.
541549
// These functions accept a single argument of any type.
542550
#ifndef BUILTIN_RUNTIME_CALL
@@ -804,24 +812,6 @@ BUILTIN_MISC_OPERATION(CreateTaskGroupWithFlags,
804812
BUILTIN_MISC_OPERATION(DestroyTaskGroup,
805813
"destroyTaskGroup", "", Special)
806814

807-
/// A builtin that can only be called from a transparent generic function. Takes
808-
/// two operands, the first operand the result address, the second operand the
809-
/// input address. Transforms into
810-
///
811-
/// %input = load [take] %inputAddr
812-
/// %result = explicit_copy_value %input
813-
/// store %result to [init] %resultAddr
814-
/// store %input to [init] %inputAddr
815-
///
816-
/// transparently inlined into a caller that has the generic of the callee
817-
/// specialized into a loadable type. If the transparent inlining does not
818-
/// specialize the type (due to being inlined into a non-generic context, the
819-
/// SILVerifier will abort).
820-
///
821-
/// Illegal to call except for in Swift._copy in the stdlib. This is enforced by
822-
/// the SILVerifier.
823-
BUILTIN_MISC_OPERATION(Copy, "copy", "", Special)
824-
825815
/// Unchecked pointer alignment assertion. Allows the compiler to assume
826816
/// alignment of the pointer to emit more efficient code.
827817
///

include/swift/AST/SemanticAttrs.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ SEMANTICS_ATTR(FORCE_EMIT_OPT_REMARK_PREFIX, "optremark")
124124
SEMANTICS_ATTR(OBJC_FORBID_ASSOCIATED_OBJECTS, "objc.forbidAssociatedObjects")
125125

126126
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_MOVE, "lifetimemanagement.move")
127-
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_COPY, "lifetimemanagement.copy")
128127

129128
SEMANTICS_ATTR(NO_PERFORMANCE_ANALYSIS, "no_performance_analysis")
130129

include/swift/SIL/AddressWalker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ TransitiveAddressWalker<Impl>::walk(SILValue projectedAddress) && {
251251
case BuiltinValueKind::TSanInoutAccess:
252252
case BuiltinValueKind::ResumeThrowingContinuationReturning:
253253
case BuiltinValueKind::ResumeNonThrowingContinuationReturning:
254-
case BuiltinValueKind::Copy:
255254
case BuiltinValueKind::GenericAdd:
256255
case BuiltinValueKind::GenericFAdd:
257256
case BuiltinValueKind::GenericAnd:

lib/IRGen/GenBuiltin.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,16 +1437,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14371437
return;
14381438
}
14391439

1440-
if (Builtin.ID == BuiltinValueKind::Copy) {
1441-
auto input = args.claimNext();
1442-
auto result = args.claimNext();
1443-
SILType addrTy = argTypes[0];
1444-
const TypeInfo &addrTI = IGF.getTypeInfo(addrTy);
1445-
Address inputAttr = addrTI.getAddressForPointer(input);
1446-
Address resultAttr = addrTI.getAddressForPointer(result);
1447-
addrTI.initializeWithCopy(IGF, resultAttr, inputAttr, addrTy, false);
1448-
return;
1449-
}
14501440
if (Builtin.ID == BuiltinValueKind::AssumeAlignment) {
14511441
// A no-op pointer cast that passes on its first value. Common occurrences of
14521442
// this builtin should already be removed with the alignment guarantee moved

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,6 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, GetEnumTag)
899899
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, InjectEnumTag)
900900
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, DistributedActorAsAnyActor)
901901
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, AddressOfRawLayout)
902-
OperandOwnership OperandOwnershipBuiltinClassifier::visitCopy(BuiltinInst *bi,
903-
StringRef) {
904-
if (bi->getFunction()->getConventions().useLoweredAddresses()) {
905-
return OperandOwnership::UnownedInstantaneousUse;
906-
} else {
907-
return OperandOwnership::DestroyingConsume;
908-
}
909-
}
910902
BUILTIN_OPERAND_OWNERSHIP(DestroyingConsume, StartAsyncLet)
911903
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, EndAsyncLet)
912904
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, EndAsyncLetLifetime)

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ CONSTANT_OWNERSHIP_BUILTIN(None, CreateTaskGroup)
629629
CONSTANT_OWNERSHIP_BUILTIN(None, CreateTaskGroupWithFlags)
630630
CONSTANT_OWNERSHIP_BUILTIN(None, DestroyTaskGroup)
631631
CONSTANT_OWNERSHIP_BUILTIN(None, TaskRunInline)
632-
CONSTANT_OWNERSHIP_BUILTIN(None, Copy)
633632
CONSTANT_OWNERSHIP_BUILTIN(None, GetEnumTag)
634633
CONSTANT_OWNERSHIP_BUILTIN(None, InjectEnumTag)
635634
CONSTANT_OWNERSHIP_BUILTIN(Owned, DistributedActorAsAnyActor)

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,11 +2592,6 @@ static void visitBuiltinAddress(BuiltinInst *builtin,
25922592
visitor(&builtin->getAllOperands()[0]);
25932593
return;
25942594

2595-
// These effect both operands.
2596-
case BuiltinValueKind::Copy:
2597-
visitor(&builtin->getAllOperands()[1]);
2598-
return;
2599-
26002595
// These consume values out of their second operand.
26012596
case BuiltinValueKind::ResumeNonThrowingContinuationReturning:
26022597
case BuiltinValueKind::ResumeThrowingContinuationReturning:

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,22 +2343,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
23432343
return;
23442344
}
23452345

2346-
if (builtinKind == BuiltinValueKind::Copy) {
2347-
// We expect that this builtin will be specialized during transparent
2348-
// inlining into explicit_copy_value if we inline into a non-generic
2349-
// context. If the builtin still remains and is not in the specific copy
2350-
// semantic function (which is the only function marked with
2351-
// semantics::LIFETIMEMANAGEMENT_COPY), then we know that we did
2352-
// transparent inlining into a function that did not result in the Builtin
2353-
// being specialized out which is user error.
2354-
//
2355-
// NOTE: Once we have opaque values, this restriction will go away. This
2356-
// is just so we can call Builtin.copy outside of the stdlib.
2357-
auto semanticName = semantics::LIFETIMEMANAGEMENT_COPY;
2358-
require(BI->getFunction()->hasSemanticsAttr(semanticName),
2359-
"_copy used within a generic context");
2360-
}
2361-
23622346
if (builtinKind == BuiltinValueKind::CreateAsyncTask) {
23632347
requireType(BI->getType(), _object(_tuple(_nativeObject, _rawPointer)),
23642348
"result of createAsyncTask");

0 commit comments

Comments
 (0)