Skip to content

Commit 8779e23

Browse files
authored
Merge pull request #28085 from CodaFi/pro-forma
Drop ConformanceContexts out of the TypeChecker
2 parents d259071 + c75af38 commit 8779e23

File tree

10 files changed

+46
-33
lines changed

10 files changed

+46
-33
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28172817
checkExplicitAvailability(ED);
28182818

28192819
TypeChecker::checkDeclCircularity(ED);
2820-
TC.ConformanceContexts.push_back(ED);
2820+
2821+
TypeChecker::checkConformancesInContext(ED, ED);
28212822
}
28222823

28232824
void visitStructDecl(StructDecl *SD) {
@@ -2844,7 +2845,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28442845
checkExplicitAvailability(SD);
28452846

28462847
TypeChecker::checkDeclCircularity(SD);
2847-
TC.ConformanceContexts.push_back(SD);
2848+
2849+
TypeChecker::checkConformancesInContext(SD, SD);
28482850
}
28492851

28502852
/// Check whether the given properties can be @NSManaged in this class.
@@ -3090,7 +3092,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
30903092
checkExplicitAvailability(CD);
30913093

30923094
TypeChecker::checkDeclCircularity(CD);
3093-
TC.ConformanceContexts.push_back(CD);
3095+
3096+
TypeChecker::checkConformancesInContext(CD, CD);
3097+
3098+
TypeChecker::maybeDiagnoseClassWithoutInitializers(CD);
30943099
}
30953100

30963101
void visitProtocolDecl(ProtocolDecl *PD) {
@@ -3436,7 +3441,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
34363441
for (Decl *Member : ED->getMembers())
34373442
visit(Member);
34383443

3439-
TC.ConformanceContexts.push_back(ED);
3444+
TypeChecker::checkConformancesInContext(ED, ED);
34403445

34413446
TypeChecker::checkDeclAttributes(ED);
34423447
checkAccessControl(ED);

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,6 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
293293
unsigned currentFunctionIdx = 0;
294294
unsigned currentSynthesizedDecl = SF.LastCheckedSynthesizedDecl;
295295
do {
296-
// Type check conformance contexts.
297-
for (unsigned i = 0; i != TC.ConformanceContexts.size(); ++i) {
298-
auto decl = TC.ConformanceContexts[i];
299-
if (auto *ext = dyn_cast<ExtensionDecl>(decl))
300-
TypeChecker::checkConformancesInContext(ext, ext);
301-
else {
302-
auto *ntd = cast<NominalTypeDecl>(decl);
303-
TypeChecker::checkConformancesInContext(ntd, ntd);
304-
305-
// Finally, we can check classes for missing initializers.
306-
if (auto *classDecl = dyn_cast<ClassDecl>(ntd))
307-
TypeChecker::maybeDiagnoseClassWithoutInitializers(classDecl);
308-
}
309-
}
310-
TC.ConformanceContexts.clear();
311-
312296
// Type check the body of each of the function in turn. Note that outside
313297
// functions must be visited before nested functions for type-checking to
314298
// work correctly.
@@ -329,8 +313,7 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
329313
}
330314

331315
} while (currentFunctionIdx < TC.definedFunctions.size() ||
332-
currentSynthesizedDecl < SF.SynthesizedDecls.size() ||
333-
!TC.ConformanceContexts.empty());
316+
currentSynthesizedDecl < SF.SynthesizedDecls.size());
334317

335318
// FIXME: Horrible hack. Store this somewhere more appropriate.
336319
SF.LastCheckedSynthesizedDecl = currentSynthesizedDecl;

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,6 @@ class TypeChecker final {
551551
/// The list of function definitions we've encountered.
552552
std::vector<AbstractFunctionDecl *> definedFunctions;
553553

554-
/// Declarations that need their conformances checked.
555-
llvm::SmallVector<Decl *, 8> ConformanceContexts;
556-
557554
/// A list of closures for the most recently type-checked function, which we
558555
/// will need to compute captures for.
559556
std::vector<AbstractClosureExpr *> ClosuresWithUncomputedCaptures;

test/Frontend/debug-generic-signatures.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct NonRecur: P2 {
7272

7373
// Conditional conformance.
7474

75+
// CHECK: Generic signature: <T>
76+
// CHECK-NEXT: Canonical generic signature: <τ_0_0>
77+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Generic
7578
struct Generic<T> {}
7679
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Generic
7780
// CHECK-NEXT: (normal_conformance type=Generic<T> protocol=P1
@@ -85,6 +88,10 @@ extension Generic: P1 where T: P1 {
8588

8689

8790
// Satisfying associated types with requirements with generic params
91+
92+
// CHECK: Generic signature: <T, U>
93+
// CHECK-NEXT: Canonical generic signature: <τ_0_0, τ_0_1>
94+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Super
8895
class Super<T, U> {}
8996
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Super
9097
// CHECK-NEXT: (normal_conformance type=Super<T, U> protocol=P2

test/Generics/conditional_conformances.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func free_bad<U>(_: U) {
3333

3434
struct Constrained<T: P1> {}
3535
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Constrained
36+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Constrained
3637
// CHECK-NEXT: (normal_conformance type=Constrained<T> protocol=P2
3738
// CHECK-NEXT: conforms_to: T P3)
3839
extension Constrained: P2 where T: P3 {} // expected-note {{requirement from conditional conformance of 'Constrained<U>' to 'P2'}}
@@ -45,16 +46,19 @@ func constrained_bad<U: P1>(_: U) {
4546

4647
struct RedundantSame<T: P1> {}
4748
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSame
49+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSame
4850
// CHECK-NEXT: (normal_conformance type=RedundantSame<T> protocol=P2)
4951
extension RedundantSame: P2 where T: P1 {}
5052

5153
struct RedundantSuper<T: P4> {}
5254
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSuper
55+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSuper
5356
// CHECK-NEXT: (normal_conformance type=RedundantSuper<T> protocol=P2)
5457
extension RedundantSuper: P2 where T: P1 {}
5558

5659
struct OverlappingSub<T: P1> {}
5760
// CHECK-LABEL: ExtensionDecl line={{.*}} base=OverlappingSub
61+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=OverlappingSub
5862
// CHECK-NEXT: (normal_conformance type=OverlappingSub<T> protocol=P2
5963
// CHECK-NEXT: conforms_to: T P4)
6064
extension OverlappingSub: P2 where T: P4 {} // expected-note {{requirement from conditional conformance of 'OverlappingSub<U>' to 'P2'}}
@@ -68,6 +72,7 @@ func overlapping_sub_bad<U: P1>(_: U) {
6872

6973
struct SameType<T> {}
7074
// CHECK-LABEL: ExtensionDecl line={{.*}} base=SameType
75+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=SameType
7176
// CHECK-NEXT: (normal_conformance type=SameType<T> protocol=P2
7277
// CHECK-NEXT: same_type: T Int)
7378
extension SameType: P2 where T == Int {}
@@ -84,6 +89,7 @@ func same_type_bad<U>(_: U) {
8489

8590
struct SameTypeGeneric<T, U> {}
8691
// CHECK-LABEL: ExtensionDecl line={{.*}} base=SameTypeGeneric
92+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=SameTypeGeneric
8793
// CHECK-NEXT: (normal_conformance type=SameTypeGeneric<T, U> protocol=P2
8894
// CHECK-NEXT: same_type: T U)
8995
extension SameTypeGeneric: P2 where T == U {}
@@ -109,6 +115,7 @@ func same_type_bad<U, V>(_: U, _: V) {
109115

110116
struct Infer<T, U> {}
111117
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Infer
118+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Infer
112119
// CHECK-NEXT: (normal_conformance type=Infer<T, U> protocol=P2
113120
// CHECK-NEXT: same_type: T Constrained<U>
114121
// CHECK-NEXT: conforms_to: U P1)
@@ -127,6 +134,7 @@ func infer_bad<U: P1, V>(_: U, _: V) {
127134

128135
struct InferRedundant<T, U: P1> {}
129136
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InferRedundant
137+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InferRedundant
130138
// CHECK-NEXT: (normal_conformance type=InferRedundant<T, U> protocol=P2
131139
// CHECK-NEXT: same_type: T Constrained<U>)
132140
extension InferRedundant: P2 where T == Constrained<U> {}
@@ -147,6 +155,7 @@ class C3: C2 {}
147155

148156
struct ClassFree<T> {}
149157
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassFree
158+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassFree
150159
// CHECK-NEXT: (normal_conformance type=ClassFree<T> protocol=P2
151160
// CHECK-NEXT: superclass: T C1)
152161
extension ClassFree: P2 where T: C1 {} // expected-note {{requirement from conditional conformance of 'ClassFree<U>' to 'P2'}}
@@ -160,6 +169,7 @@ func class_free_bad<U>(_: U) {
160169

161170
struct ClassMoreSpecific<T: C1> {}
162171
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassMoreSpecific
172+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassMoreSpecific
163173
// CHECK-NEXT: (normal_conformance type=ClassMoreSpecific<T> protocol=P2
164174
// CHECK-NEXT: superclass: T C3)
165175
extension ClassMoreSpecific: P2 where T: C3 {} // expected-note {{requirement from conditional conformance of 'ClassMoreSpecific<U>' to 'P2'}}
@@ -174,6 +184,7 @@ func class_more_specific_bad<U: C1>(_: U) {
174184

175185
struct ClassLessSpecific<T: C3> {}
176186
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassLessSpecific
187+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassLessSpecific
177188
// CHECK-NEXT: (normal_conformance type=ClassLessSpecific<T> protocol=P2)
178189
extension ClassLessSpecific: P2 where T: C1 {}
179190

@@ -196,10 +207,12 @@ func subclass_bad() {
196207

197208
struct InheritEqual<T> {}
198209
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual
210+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual
199211
// CHECK-NEXT: (normal_conformance type=InheritEqual<T> protocol=P2
200212
// CHECK-NEXT: conforms_to: T P1)
201213
extension InheritEqual: P2 where T: P1 {} // expected-note {{requirement from conditional conformance of 'InheritEqual<U>' to 'P2'}}
202214
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual
215+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual
203216
// CHECK-NEXT: (normal_conformance type=InheritEqual<T> protocol=P5
204217
// CHECK-NEXT: (normal_conformance type=InheritEqual<T> protocol=P2
205218
// CHECK-NEXT: conforms_to: T P1)
@@ -224,10 +237,12 @@ extension InheritLess: P5 {} // expected-error{{type 'T' does not conform to pro
224237

225238
struct InheritMore<T> {}
226239
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore
240+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore
227241
// CHECK-NEXT: (normal_conformance type=InheritMore<T> protocol=P2
228242
// CHECK-NEXT: conforms_to: T P1)
229243
extension InheritMore: P2 where T: P1 {} // expected-note {{requirement from conditional conformance of 'InheritMore<U>' to 'P2'}}
230244
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore
245+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore
231246
// CHECK-NEXT: (normal_conformance type=InheritMore<T> protocol=P5
232247
// CHECK-NEXT: (normal_conformance type=InheritMore<T> protocol=P2
233248
// CHECK-NEXT: conforms_to: T P1)
@@ -311,11 +326,13 @@ extension TwoDisjointConformances: P2 where T == String {}
311326
// true in the original type's generic signature.
312327
struct RedundancyOrderDependenceGood<T: P1, U> {}
313328
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceGood
329+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceGood
314330
// CHECK-NEXT: (normal_conformance type=RedundancyOrderDependenceGood<T, U> protocol=P2
315331
// CHECK-NEXT: same_type: T U)
316332
extension RedundancyOrderDependenceGood: P2 where U: P1, T == U {}
317333
struct RedundancyOrderDependenceBad<T, U: P1> {}
318334
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceBad
335+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceBad
319336
// CHECK-NEXT: (normal_conformance type=RedundancyOrderDependenceBad<T, U> protocol=P2
320337
// CHECK-NEXT: conforms_to: T P1
321338
// CHECK-NEXT: same_type: T U)

test/decl/ext/extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ protocol P3 {
103103
func foo() -> Assoc
104104
}
105105

106-
struct X3 : P3 { // expected-note{{'X3' declared here}}
106+
struct X3 : P3 {
107107
}
108108

109-
extension X3.Assoc { // expected-error{{'Assoc' is not a member type of 'X3'}}
109+
extension X3.Assoc {
110110
}
111111

112112
extension X3 {

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ struct XSubP0b : SubscriptP0 {
150150
struct XSubP0c : SubscriptP0 {
151151
// expected-error@-1 {{type 'XSubP0c' does not conform to protocol 'SubscriptP0'}}
152152
subscript (i: Index) -> Element { get { } }
153-
// expected-error@-1 {{reference to invalid associated type 'Element' of type 'XSubP0c'}}
154153
}
155154

156155
struct XSubP0d : SubscriptP0 {

test/refactoring/FillStubs/Outputs/basic/P59-12.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ extension C12 : P1 {
6161
<#code#>
6262
}
6363

64+
func foo1() {
65+
<#code#>
66+
}
67+
6468
func foo1() {}
6569
}
6670
extension C12 : P2 {

test/refactoring/RefactoringKind/basic.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func testConvertToIfLetExpr(idxOpt: Int?) {
309309
// RUN: %refactor -source-filename %s -pos=68:12 | %FileCheck %s -check-prefix=CHECK-RENAME-STUB
310310

311311
// RUN: %refactor -source-filename %s -pos=69:8 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
312-
// RUN: %refactor -source-filename %s -pos=70:12 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
312+
// RUN: %refactor -source-filename %s -pos=70:12 | %FileCheck %s -check-prefix=CHECK-RENAME-STUB
313313
// RUN: %refactor -source-filename %s -pos=74:12 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
314314

315315
// RUN: %refactor -source-filename %s -pos=79:8 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
@@ -321,7 +321,7 @@ func testConvertToIfLetExpr(idxOpt: Int?) {
321321
// RUN: %refactor -source-filename %s -pos=91:12 | %FileCheck %s -check-prefix=CHECK-RENAME-STUB
322322

323323
// RUN: %refactor -source-filename %s -pos=95:8 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
324-
// RUN: %refactor -source-filename %s -pos=96:12 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
324+
// RUN: %refactor -source-filename %s -pos=96:12 | %FileCheck %s -check-prefix=CHECK-RENAME-STUB
325325
// RUN: %refactor -source-filename %s -pos=100:12 | %FileCheck %s -check-prefix=CHECK-RENAME-STUB
326326

327327
// RUN: %refactor -source-filename %s -pos=104:8 | %FileCheck %s -check-prefix=CHECK-RENAME-ONLY
@@ -422,4 +422,4 @@ func testConvertToIfLetExpr(idxOpt: Int?) {
422422

423423
// CHECK-CONVERT-TO-GUARD-EXPRESSION: Convert To Guard Expression
424424

425-
// CHECK-CONVERT-TO-IFLET-EXPRESSION: Convert To IfLet Expression
425+
// CHECK-CONVERT-TO-IFLET-EXPRESSION: Convert To IfLet Expression

validation-test/compiler_crashers_2_fixed/0126-sr5905.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -o /dev/null
1+
// RUN: %target-typecheck-verify-swift
2+
23
protocol VectorIndex {
34
associatedtype Vector8 : Vector where Vector8.Index == Self, Vector8.Element == UInt8
45
}
@@ -18,7 +19,7 @@ struct Vector1<Element> : Vector {
1819
init(elementForIndex: (VectorIndex1) -> Element) {
1920
e0 = elementForIndex(.i0)
2021
}
21-
subscript(index: Index) -> Element {
22+
subscript(index: Index) -> Element { // expected-error {{reference to invalid associated type 'Index' of type 'Vector1<Element>'}}
2223
get { return e0 }
2324
set { e0 = newValue }
2425
}

0 commit comments

Comments
 (0)