Skip to content

Commit 4849947

Browse files
Merge pull request #32277 from aschwaighofer/irgen_fix_addAbstractConditionalRequirements
IRGen: Lookup the conformance of an archetype in the right substitution map when computing necessary bindings of abstract cnditional requirements
2 parents 4d705ab + 8a2bfb0 commit 4849947

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,12 +2749,10 @@ static void addAbstractConditionalRequirements(
27492749
auto *proto =
27502750
req.getSecondType()->castTo<ProtocolType>()->getDecl();
27512751
auto ty = req.getFirstType()->getCanonicalType();
2752-
if (!isa<ArchetypeType>(ty))
2752+
auto archetype = dyn_cast<ArchetypeType>(ty);
2753+
if (!archetype)
27532754
continue;
2754-
auto conformance = subMap.lookupConformance(ty, proto);
2755-
if (!conformance.isAbstract())
2756-
continue;
2757-
requirements.insert({ty, conformance.getAbstract()});
2755+
requirements.insert({ty, proto});
27582756
}
27592757
// Recursively add conditional requirements.
27602758
for (auto &conf : subMap.getConformances()) {

test/IRGen/partial_apply_forwarder.sil

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ protocol MyEquatable {
255255
static func isEqual (lhs: Self, rhs: Self) -> Builtin.Int1
256256
}
257257

258+
protocol MyExtended : MyEquatable {
259+
func extended()
260+
}
258261
public struct Inner<Element> {
259262
public init()
260263
public init(_ e: Element)
@@ -278,7 +281,7 @@ public struct Outermost<Value> {
278281
sil @$closure : $@convention(method) <Value where Value : MyEquatable> (Outer<Value>, Outer<Value>, @thin Outer<Value>.Type) -> Builtin.Int1
279282
sil @$closure2 : $@convention(method) <Value where Value : MyEquatable> (Outermost<Value>, Outermost<Value>, @thin Outermost<Value>.Type) -> Builtin.Int1
280283

281-
sil @$dont_crash_test_capture_specialized_conditional_conformance : $@convention(thin) <Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
284+
sil @$dont_crash_test_capture_specialized_conditional_conformance : $@convention(thin) <Element where Element : MyExtended> (Outer<Inner<Element>>) -> () {
282285
bb0(%0 : $Outer<Inner<Element>>):
283286
%2 = alloc_stack $Outer<Inner<Element>>
284287
store %0 to %2 : $*Outer<Inner<Element>>
@@ -291,7 +294,24 @@ bb0(%0 : $Outer<Inner<Element>>):
291294
return %15 : $()
292295
}
293296

294-
sil @$dont_crash_test_capture_specialized_conditional_conformance_nested : $@convention(thin) <Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
297+
protocol AssocType {
298+
associatedtype A : MyExtended
299+
}
300+
301+
sil @$dont_crash_test_capture_specialized_conditional_conformance_associated_type : $@convention(thin) <Element where Element : AssocType> (Outer<Inner<Element.A>>) -> () {
302+
bb0(%0 : $Outer<Inner<Element.A>>):
303+
%2 = alloc_stack $Outer<Inner<Element.A>>
304+
store %0 to %2 : $*Outer<Inner<Element.A>>
305+
%4 = metatype $@thin Outer<Inner<Element.A>>.Type
306+
%5 = function_ref @$closure : $@convention(method) <τ_0_0 where τ_0_0 : MyEquatable> (Outer<τ_0_0>, Outer<τ_0_0>, @thin Outer<τ_0_0>.Type) -> Builtin.Int1
307+
%6 = partial_apply [callee_guaranteed] %5<Inner<Element.A>>(%4) : $@convention(method) <τ_0_0 where τ_0_0 : MyEquatable> (Outer<τ_0_0>, Outer<τ_0_0>, @thin Outer<τ_0_0>.Type) -> Builtin.Int1
308+
strong_release %6 : $@callee_guaranteed (Outer<Inner<Element.A>>, Outer<Inner<Element.A>>) -> Builtin.Int1
309+
dealloc_stack %2 : $*Outer<Inner<Element.A>>
310+
%15 = tuple ()
311+
return %15 : $()
312+
}
313+
314+
sil @$dont_crash_test_capture_specialized_conditional_conformance_nested : $@convention(thin) <A, B, Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
295315
bb0(%0 : $Outer<Inner<Element>>):
296316
%4 = metatype $@thin Outermost<Outer<Inner<Element>>>.Type
297317
%5 = function_ref @$closure2 : $@convention(method) <Value where Value : MyEquatable> (Outermost<Value>, Outermost<Value>, @thin Outermost<Value>.Type) -> Builtin.Int1

0 commit comments

Comments
 (0)