Skip to content

Commit bf4e8ae

Browse files
committed
IRGen: Handle self-conformances in defineAssociatedTypeWitnessTableAccessFunction
rdar://46664811
1 parent f453092 commit bf4e8ae

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,17 @@ void WitnessTableBuilder::defineAssociatedTypeWitnessTableAccessFunction(
16441644
ProtocolDecl *associatedProtocol = requirement.getAssociatedRequirement();
16451645

16461646
const ConformanceInfo *conformanceI = nullptr;
1647+
1648+
// Rewrite (abstract) self conformances to the concrete conformance.
1649+
if (associatedConformance.isAbstract() && !hasArchetype) {
1650+
// This must be a self conformance.
1651+
auto proto = associatedConformance.getRequirement();
1652+
assert(proto->requiresSelfConformanceWitnessTable());
1653+
assert(cast<ProtocolType>(associatedType)->getDecl() == proto);
1654+
auto concreteConformance = IGF.IGM.Context.getSelfConformance(proto);
1655+
associatedConformance = ProtocolConformanceRef(concreteConformance);
1656+
}
1657+
16471658
if (associatedConformance.isConcrete()) {
16481659
assert(associatedType->isEqual(associatedConformance.getConcrete()->getType()));
16491660

test/IRGen/associated_types.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,16 @@ func testFastRuncible<T: Runcible, U: FastRuncible>(_ t: T, u: U)
9393
// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to void (%swift.type*, %swift.type*, i8**)*
9494
// CHECK-NEXT: call swiftcc void [[T1]](%swift.type* swiftself %T.RuncerType.Runcee, %swift.type* %T.RuncerType.Runcee, i8** %T.RuncerType.Runcee.Speedy)
9595

96+
public protocol P0 {
97+
associatedtype ErrorType : Swift.Error
98+
}
99+
100+
public struct P0Impl : P0 {
101+
public typealias ErrorType = Swift.Error
102+
}
103+
104+
// CHECK: define{{.*}} swiftcc i8** @"$s16associated_types6P0ImplVAA0C0AA9ErrorTypeAaDP_s0E0PWT"(%swift.type* %P0Impl.ErrorType, %swift.type* %P0Impl, i8** %P0Impl.P0)
105+
// CHECK: ret i8** @"$ss5ErrorWS"
106+
96107
// CHECK: attributes [[NOUNWIND_READNONE]] = { nounwind readnone }
97108

0 commit comments

Comments
 (0)