Skip to content

Commit 8a27e89

Browse files
Merge pull request #20827 from aschwaighofer/fix_class_bound_archetype_lookup
IRGen: Consider the superclass bound of archetypes in searchTypeMetadata
2 parents c65c540 + 4bc9e31 commit 8a27e89

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/IRGen/Fulfillment.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ bool FulfillmentMap::searchTypeMetadata(IRGenModule &IGM, CanType type,
124124
source, MetadataPath(path), keys);
125125
}
126126

127+
// Consider its super class bound.
128+
if (metadataState == MetadataState::Complete) {
129+
if (auto superclassTy = keys.getSuperclassBound(type)) {
130+
hadFulfillment |= searchNominalTypeMetadata(
131+
IGM, superclassTy, metadataState, source, std::move(path), keys);
132+
}
133+
}
134+
127135
// Add the fulfillment.
128136
hadFulfillment |= addFulfillment({type, nullptr},
129137
source, std::move(path), metadataState);

test/IRGen/class_bounded_generics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ func takes_metatype<T>(_: T.Type) {}
285285
// CHECK: [[ISA_ADDR:%.*]] = bitcast %T22class_bounded_generics1AC.1* %0 to %swift.type**
286286
// CHECK-NEXT: [[ISA:%.*]] = load %swift.type*, %swift.type** [[ISA_ADDR]]
287287
// CHECK: call swiftcc void @"$s22class_bounded_generics14takes_metatypeyyxmlF"(%swift.type* %T, %swift.type* %T)
288-
// CHECK-NEXT: [[ISA_PTR:%.*]] = bitcast %swift.type* [[ISA]] to %swift.type**
289-
// CHECK-NEXT: [[U_ADDR:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[ISA_PTR]], i64 10
288+
// CHECK-NEXT: [[T:%.*]] = bitcast %swift.type* %T to %swift.type**
289+
// CHECK-NEXT: [[U_ADDR:%.*]] = getelementptr inbounds %swift.type*, %swift.type** [[T]], i64 10
290290
// CHECK-NEXT: [[U:%.*]] = load %swift.type*, %swift.type** [[U_ADDR]]
291291
// CHECK: call swiftcc void @"$s22class_bounded_generics14takes_metatypeyyxmlF"(%swift.type* %U, %swift.type* %U)
292292
// CHECK: ret void

test/IRGen/fulfillment.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,33 @@ bb0(%0 : $A<A<T>>, %1 : $A<T>):
5353
%2 = tuple ()
5454
return %2 : $()
5555
}
56+
57+
protocol A2 {
58+
associatedtype AssocTy
59+
}
60+
61+
protocol C {
62+
}
63+
64+
extension A2 where Self.AssocTy : C {
65+
}
66+
67+
class K<T> : A2 where T : C {
68+
typealias AssocTy = T
69+
}
70+
71+
sil @callee : $@convention(method) <τ_0_0 where τ_0_0 : A2, τ_0_0.AssocTy : C> (@in_guaranteed τ_0_0) -> ()
72+
73+
// CHECK-LABEL: define{{.*}} swiftcc void @caller(%T11fulfillment1KC** {{.*}}, %swift.type* %Self, i8** %SelfWitnessTable)
74+
// CHECK: entry:
75+
// CHECK: %1 = bitcast %swift.type* %Self to i8***
76+
// CHECK: %2 = getelementptr inbounds i8**, i8*** %1, i64 11
77+
// CHECK: %"\CF\84_1_0.C" = load i8**, i8*** %2
78+
// CHECK: call swiftcc void @callee(%swift.type* %Self, i8** %SelfWitnessTable, i8** %"\CF\84_1_0.C"
79+
sil @caller : $@convention(witness_method: A2) <τ_0_0><τ_1_0 where τ_0_0 : K<τ_1_0>, τ_1_0 : C> (@in_guaranteed τ_0_0) -> () {
80+
bb0(%0 : $*τ_0_0):
81+
%1 = function_ref @callee : $@convention(method) <τ_0_0 where τ_0_0 : A2, τ_0_0.AssocTy : C> (@in_guaranteed τ_0_0) -> ()
82+
%2 = apply %1<τ_0_0>(%0) : $@convention(method) <τ_0_0 where τ_0_0 : A2, τ_0_0.AssocTy : C> (@in_guaranteed τ_0_0) -> ()
83+
%3 = tuple ()
84+
return %3 : $()
85+
}

0 commit comments

Comments
 (0)