Skip to content

Commit 6b7fbc9

Browse files
committed
Break some cycles
Use the interface type of the underlying type in the GSB in as many cases as possible except for one important one: requirement signature computation. There, use the structural type so we don't wind up recursively validating the requirements of an incomplete protocol.
1 parent c254f4d commit 6b7fbc9

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3785,7 +3785,13 @@ PotentialArchetype *GenericSignatureBuilder::realizePotentialArchetype(
37853785

37863786
static Type getStructuralType(TypeDecl *typeDecl) {
37873787
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
3788-
return typealias->getStructuralType();
3788+
// When we're computing requirement signatures, the structural type
3789+
// suffices. Otherwise we'll potentially try to validate incomplete
3790+
// requirements.
3791+
auto *proto = dyn_cast_or_null<ProtocolDecl>(typealias->getDeclContext()->getAsDecl());
3792+
if (proto && proto->isComputingRequirementSignature())
3793+
return typealias->getStructuralType();
3794+
return typealias->getUnderlyingType();
37893795
}
37903796

37913797
return typeDecl->getDeclaredInterfaceType();

test/Generics/protocol_type_aliases.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ func concreteRequirementOnConcreteNestedTypeAlias<T>(_: T) where T: Q2, S<T.C> =
4242
protocol P3 {
4343
typealias T = Int
4444
}
45-
protocol Q3: P3 { // expected-error{{generic signature requires types 'P3.T' (aka 'Int')}}
45+
protocol Q3: P3 { // expected-error{{generic signature requires types 'Int'}}
4646
typealias T = Float
4747
}
4848

4949
protocol P3_1 {
5050
typealias T = Float
5151
}
52-
protocol Q3_1: P3, P3_1 {} // expected-error{{generic signature requires types 'P3_1.T' (aka 'Float')}}
52+
protocol Q3_1: P3, P3_1 {} // expected-error{{generic signature requires types 'Float'}}
5353

5454

5555
// Subprotocols can force associated types in their parents to be concrete, and

validation-test/compiler_crashers_2_fixed/0145-sr7097.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protocol P2 {
99
}
1010

1111
// CHECK-LABEL: .P3@
12-
// CHECK-NEXT: Requirement signature: <Self where Self : P2, Self.Assoc == P3.Assoc>
12+
// CHECK-NEXT: Requirement signature: <Self where Self : P2, Self.Assoc == ConformsToP1>
1313
protocol P3 : P2 { }
1414

1515
struct S0<M: P3> where M.Assoc: P1 { } // expected-warning{{redundant conformance constraint 'M.Assoc': 'P1'}}

0 commit comments

Comments
 (0)