Skip to content

Commit 2781c40

Browse files
committed
[Runtime] Use the Swift calling convention for swift_getAssociatedTypeWitness.
Runtime functions need to use the Swift calling convention for any function returning MetadataResponse, so that we get the two values returned in separate registers. Fixes rdar://problem/45042971 and rdar://problem/45851050.
1 parent c09d479 commit 2781c40

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

include/swift/ABI/Metadata.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ using Metadata = TargetMetadata<InProcess>;
167167
/// The result of requesting type metadata. Generally the return value of
168168
/// a function.
169169
///
170-
/// For performance, functions returning this type should use SWIFT_CC so
171-
/// that the components are returned as separate values.
170+
/// For performance and ABI matching across Swift/C++, functions returning
171+
/// this type must use SWIFT_CC so that the components are returned as separate
172+
/// values.
172173
struct MetadataResponse {
173174
/// The requested metadata.
174175
const Metadata *Value;

include/swift/Runtime/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ swift_instantiateWitnessTable(ProtocolConformanceDescriptor *conformance,
418418
/// \param assocType Associated type descriptor.
419419
///
420420
/// \returns metadata for the associated type witness.
421-
SWIFT_RUNTIME_EXPORT
421+
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
422422
MetadataResponse swift_getAssociatedTypeWitness(
423423
MetadataRequest request,
424424
WitnessTable *wtable,

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ FUNCTION(InstantiateWitnessTable, swift_instantiateWitnessTable, C_CC,
651651
// const Metadata *conformingType,
652652
// ProtocolRequirement *reqBase,
653653
// ProtocolRequirement *assocType);
654-
FUNCTION(GetAssociatedTypeWitness, swift_getAssociatedTypeWitness, C_CC,
654+
FUNCTION(GetAssociatedTypeWitness, swift_getAssociatedTypeWitness, SwiftCC,
655655
RETURNS(TypeMetadataResponseTy),
656656
ARGS(SizeTy,
657657
WitnessTablePtrTy,

test/IRGen/associated_types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func testFastRuncible<T: Runcible, U: FastRuncible>(_ t: T, u: U)
7575
// 1. Get the type metadata for U.RuncerType.Runcee.
7676
// 1a. Get the type metadata for U.RuncerType.
7777
// Note that we actually look things up in T, which is going to prove unfortunate.
78-
// CHECK: [[T2:%.*]] = call %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %T.Runcible, %swift.type* %T, %swift.protocol_requirement* getelementptr{{.*}}i32 12), i32 -1), %swift.protocol_requirement* getelementptr inbounds (<{{.*}}>, <{{.*}}>* @"$s16associated_types8RuncibleMp", i32 0, i32 14)) [[NOUNWIND_READNONE:#.*]]
78+
// CHECK: [[T2:%.*]] = call swiftcc %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %T.Runcible, %swift.type* %T, %swift.protocol_requirement* getelementptr{{.*}}i32 12), i32 -1), %swift.protocol_requirement* getelementptr inbounds (<{{.*}}>, <{{.*}}>* @"$s16associated_types8RuncibleMp", i32 0, i32 14)) [[NOUNWIND_READNONE:#.*]]
7979
// CHECK-NEXT: %T.RuncerType = extractvalue %swift.metadata_response [[T2]], 0
8080
// CHECK-NEXT: store %swift.type*
8181
// 2. Get the witness table for U.RuncerType.Runcee : Speedy
@@ -85,7 +85,7 @@ func testFastRuncible<T: Runcible, U: FastRuncible>(_ t: T, u: U)
8585
// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** (%swift.type*, %swift.type*, i8**)*
8686
// CHECK-NEXT: %T.RuncerType.FastRuncer = call swiftcc i8** [[T2]](%swift.type* %T.RuncerType, %swift.type* %U, i8** %U.FastRuncible)
8787
// 1c. Get the type metadata for U.RuncerType.Runcee.
88-
// CHECK-NEXT: [[T2:%.*]] = call %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %T.RuncerType.FastRuncer, %swift.type* %T.RuncerType, {{.*}}, %swift.protocol_requirement* getelementptr inbounds (<{{.*}}>, <{{.*}}>* @"$s16associated_types10FastRuncerMp", i32 0, i32 10))
88+
// CHECK-NEXT: [[T2:%.*]] = call swiftcc %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %T.RuncerType.FastRuncer, %swift.type* %T.RuncerType, {{.*}}, %swift.protocol_requirement* getelementptr inbounds (<{{.*}}>, <{{.*}}>* @"$s16associated_types10FastRuncerMp", i32 0, i32 10))
8989
// CHECK-NEXT: %T.RuncerType.Runcee = extractvalue %swift.metadata_response [[T2]], 0
9090
// CHECK-NEXT: store %swift.type*
9191
// 2b. Get the witness table for U.RuncerType.Runcee : Speedy.

test/IRGen/generic_structs.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct GenericLayoutWithAssocType<T: ParentHasAssociatedType> {
256256
// CHECK: [[T0_GEP:%.*]] = getelementptr inbounds i8*, i8** %T.ParentHasAssociatedType, i32 1
257257
// CHECK: [[T0:%.*]] = load i8*, i8** [[T0_GEP]]
258258
// CHECK: [[T1:%.*]] = bitcast i8* [[T0]] to i8**
259-
// CHECK: [[T4:%.*]] = call %swift.metadata_response @swift_getAssociatedTypeWitness(i64 0, i8** %T.HasAssociatedType, %swift.type* %T, %swift.protocol_requirement* @"$s15generic_structs17HasAssociatedTypeTL", %swift.protocol_requirement* @"$s5Assoc15generic_structs17HasAssociatedTypePTl")
259+
// CHECK: [[T4:%.*]] = call swiftcc %swift.metadata_response @swift_getAssociatedTypeWitness(i64 0, i8** %T.HasAssociatedType, %swift.type* %T, %swift.protocol_requirement* @"$s15generic_structs17HasAssociatedTypeTL", %swift.protocol_requirement* @"$s5Assoc15generic_structs17HasAssociatedTypePTl")
260260

261261
// CHECK: %T.Assoc = extractvalue %swift.metadata_response [[T4]], 0
262262

@@ -265,5 +265,5 @@ struct GenericLayoutWithAssocType<T: ParentHasAssociatedType> {
265265
// CHECK: [[T2:%.*]] = bitcast i8* [[T1]] to i8** (%swift.type*, %swift.type*, i8**)*
266266
// CHECK: %T.Assoc.HasAssociatedType = call swiftcc i8** [[T2]](%swift.type* %T.Assoc, %swift.type* %T, i8** %T.ParentHasAssociatedType)
267267

268-
// CHECK: [[T2:%.*]] = call %swift.metadata_response @swift_getAssociatedTypeWitness(i64 0, i8** %T.Assoc.HasAssociatedType, %swift.type* %T.Assoc, %swift.protocol_requirement* @"$s15generic_structs17HasAssociatedTypeTL", %swift.protocol_requirement* @"$s5Assoc15generic_structs17HasAssociatedTypePTl")
268+
// CHECK: [[T2:%.*]] = call swiftcc %swift.metadata_response @swift_getAssociatedTypeWitness(i64 0, i8** %T.Assoc.HasAssociatedType, %swift.type* %T.Assoc, %swift.protocol_requirement* @"$s15generic_structs17HasAssociatedTypeTL", %swift.protocol_requirement* @"$s5Assoc15generic_structs17HasAssociatedTypePTl")
269269
// CHECK: %T.Assoc.Assoc = extractvalue %swift.metadata_response [[T2]], 0

test/IRGen/protocol_resilience_descriptors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ where Element: ProtocolWithRequirements, Element.T == Y {
8282

8383
// CHECK-USAGE: define{{( dllexport)?}}{{( protected)?}} swiftcc %swift.type* @"$s31protocol_resilience_descriptors17assocTypeMetadatay1TQzmxm010resilient_A024ProtocolWithRequirementsRzlF"(%swift.type*, %swift.type* [[PWD:%.*]], i8** [[WTABLE:%.*]])
8484
public func assocTypeMetadata<PWR: ProtocolWithRequirements>(_: PWR.Type) -> PWR.T.Type {
85-
// CHECK-USAGE: call %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %PWR.ProtocolWithRequirements, %swift.type* %PWR, %swift.protocol_requirement* @"$s18resilient_protocol24ProtocolWithRequirementsTL", %swift.protocol_requirement* @"$s1T18resilient_protocol24ProtocolWithRequirementsPTl")
85+
// CHECK-USAGE: call swiftcc %swift.metadata_response @swift_getAssociatedTypeWitness([[INT]] 0, i8** %PWR.ProtocolWithRequirements, %swift.type* %PWR, %swift.protocol_requirement* @"$s18resilient_protocol24ProtocolWithRequirementsTL", %swift.protocol_requirement* @"$s1T18resilient_protocol24ProtocolWithRequirementsPTl")
8686
return PWR.T.self
8787
}
8888

0 commit comments

Comments
 (0)