Skip to content

IRGen: Lookup the conformance of an archetype in the right substitution map when computing necessary bindings of abstract cnditional requirements #32277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,12 +2749,10 @@ static void addAbstractConditionalRequirements(
auto *proto =
req.getSecondType()->castTo<ProtocolType>()->getDecl();
auto ty = req.getFirstType()->getCanonicalType();
if (!isa<ArchetypeType>(ty))
auto archetype = dyn_cast<ArchetypeType>(ty);
if (!archetype)
continue;
auto conformance = subMap.lookupConformance(ty, proto);
if (!conformance.isAbstract())
continue;
requirements.insert({ty, conformance.getAbstract()});
requirements.insert({ty, proto});
}
// Recursively add conditional requirements.
for (auto &conf : subMap.getConformances()) {
Expand Down
24 changes: 22 additions & 2 deletions test/IRGen/partial_apply_forwarder.sil
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ protocol MyEquatable {
static func isEqual (lhs: Self, rhs: Self) -> Builtin.Int1
}

protocol MyExtended : MyEquatable {
func extended()
}
public struct Inner<Element> {
public init()
public init(_ e: Element)
Expand All @@ -278,7 +281,7 @@ public struct Outermost<Value> {
sil @$closure : $@convention(method) <Value where Value : MyEquatable> (Outer<Value>, Outer<Value>, @thin Outer<Value>.Type) -> Builtin.Int1
sil @$closure2 : $@convention(method) <Value where Value : MyEquatable> (Outermost<Value>, Outermost<Value>, @thin Outermost<Value>.Type) -> Builtin.Int1

sil @$dont_crash_test_capture_specialized_conditional_conformance : $@convention(thin) <Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
sil @$dont_crash_test_capture_specialized_conditional_conformance : $@convention(thin) <Element where Element : MyExtended> (Outer<Inner<Element>>) -> () {
bb0(%0 : $Outer<Inner<Element>>):
%2 = alloc_stack $Outer<Inner<Element>>
store %0 to %2 : $*Outer<Inner<Element>>
Expand All @@ -291,7 +294,24 @@ bb0(%0 : $Outer<Inner<Element>>):
return %15 : $()
}

sil @$dont_crash_test_capture_specialized_conditional_conformance_nested : $@convention(thin) <Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
protocol AssocType {
associatedtype A : MyExtended
}

sil @$dont_crash_test_capture_specialized_conditional_conformance_associated_type : $@convention(thin) <Element where Element : AssocType> (Outer<Inner<Element.A>>) -> () {
bb0(%0 : $Outer<Inner<Element.A>>):
%2 = alloc_stack $Outer<Inner<Element.A>>
store %0 to %2 : $*Outer<Inner<Element.A>>
%4 = metatype $@thin Outer<Inner<Element.A>>.Type
%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
%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
strong_release %6 : $@callee_guaranteed (Outer<Inner<Element.A>>, Outer<Inner<Element.A>>) -> Builtin.Int1
dealloc_stack %2 : $*Outer<Inner<Element.A>>
%15 = tuple ()
return %15 : $()
}

sil @$dont_crash_test_capture_specialized_conditional_conformance_nested : $@convention(thin) <A, B, Element where Element : MyEquatable> (Outer<Inner<Element>>) -> () {
bb0(%0 : $Outer<Inner<Element>>):
%4 = metatype $@thin Outermost<Outer<Inner<Element>>>.Type
%5 = function_ref @$closure2 : $@convention(method) <Value where Value : MyEquatable> (Outermost<Value>, Outermost<Value>, @thin Outermost<Value>.Type) -> Builtin.Int1
Expand Down