Skip to content

Commit 41cac98

Browse files
committed
IRGen: Use correct archetype conformance code path for opaque associated types.
The code here was not correct in a situation where an opaque type had constraints that were refinements of the protocol requirements of an associated type, as in: ``` protocol ParentProtocol {} protocol SubProtocol: ParentProtocol {} protocol P { associatedtype A: ParentProtocol func foo() -> A } struct S: P { func foo() -> some SubProtocol } ``` because it assumed that the conformance could be found directly on the opaque type instead of potentially via an arbitrary MetadataPath. Falling through to the code that already correctly handles archetype conformances right below the removed code does the right thing. Fixes rdar://problem/53081207.
1 parent f883175 commit 41cac98

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,6 @@ namespace {
16901690
auto opaqueType = O->getDeclaredInterfaceType()
16911691
->castTo<OpaqueTypeArchetypeType>();
16921692

1693-
1694-
16951693
for (auto proto : opaqueType->getConformsTo()) {
16961694
auto conformance = ProtocolConformanceRef(proto);
16971695
auto underlyingConformance = conformance

lib/IRGen/GenProto.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,17 +1565,6 @@ void WitnessTableBuilder::defineAssociatedTypeWitnessTableAccessFunction(
15651565
IGF.bindLocalTypeDataFromTypeMetadata(ConcreteType, IsExact, self,
15661566
MetadataState::Abstract);
15671567

1568-
// If the associated type is opaque, use the runtime to fetch the conformance.
1569-
if (associatedRootOpaqueType) {
1570-
assert(associatedType == CanType(associatedRootOpaqueType)
1571-
&& "associated type is nested type of opaque type?! not implemented");
1572-
auto wtable = emitOpaqueTypeWitnessTableRef(IGF,
1573-
CanOpaqueTypeArchetypeType(associatedRootOpaqueType),
1574-
associatedProtocol);
1575-
IGF.Builder.CreateRet(wtable);
1576-
return;
1577-
}
1578-
15791568
// Find abstract conformances.
15801569
// TODO: provide an API to find the best metadata path to the conformance
15811570
// and decide whether it's expensive enough to be worth caching.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir %s | %FileCheck %s
2+
3+
protocol Butt { }
4+
5+
protocol Tubb: Butt { }
6+
7+
protocol P {
8+
associatedtype A: Butt
9+
associatedtype B: Butt
10+
func foo(_ x: A) -> B
11+
}
12+
13+
struct Foo<T: Tubb>: P {
14+
func foo(_ x: T) -> some Tubb { return x }
15+
}
16+
17+
// CHECK-LABEL: define {{.*}} @"$s030opaque_result_type_associated_C17_conformance_path3FooVyxGAA1PAA1B_AA4ButtPWT"
18+
// CHECK: [[TUBB_CONFORMANCE:%.*]] = call swiftcc i8** @swift_getOpaqueTypeConformance({{.*}}, i{{.*}} 1)
19+
// CHECK: [[BUTT_CONFORMANCE_ADDR:%.*]] = getelementptr {{.*}} [[TUBB_CONFORMANCE]], i32 1
20+
// CHECK: [[BUTT_CONFORMANCE_LOAD:%.*]] = load {{.*}} [[BUTT_CONFORMANCE_ADDR]]
21+
// CHECK: [[BUTT_CONFORMANCE:%.*]] = bitcast {{.*}} [[BUTT_CONFORMANCE_LOAD]]
22+
// CHECK: ret {{.*}} [[BUTT_CONFORMANCE]]

0 commit comments

Comments
 (0)