@@ -85,15 +85,9 @@ bool IterativeTypeChecker::isTypeCheckInheritedClauseEntrySatisfied(
85
85
return !inherited.getType ().isNull ();
86
86
}
87
87
88
- void IterativeTypeChecker::enumerateDependenciesOfTypeCheckInheritedClauseEntry (
88
+ void IterativeTypeChecker::processTypeCheckInheritedClauseEntry (
89
89
TypeCheckRequest::InheritedClauseEntryPayloadType payload,
90
- llvm::function_ref<void (TypeCheckRequest)>) {
91
- // FIXME: depends on type checking the TypeRepr for this inheritance
92
- // clause entry.
93
- }
94
-
95
- void IterativeTypeChecker::satisfyTypeCheckInheritedClauseEntry (
96
- TypeCheckRequest::InheritedClauseEntryPayloadType payload) {
90
+ llvm::function_ref<void (TypeCheckRequest)> recordDependency) {
97
91
TypeResolutionOptions options;
98
92
DeclContext *dc;
99
93
TypeLoc *inherited;
@@ -122,36 +116,31 @@ bool IterativeTypeChecker::isTypeCheckSuperclassSatisfied(ClassDecl *payload) {
122
116
return payload->LazySemanticInfo .Superclass .getInt ();
123
117
}
124
118
125
- void IterativeTypeChecker::enumerateDependenciesOfTypeCheckSuperclass (
126
- ClassDecl *payload ,
127
- llvm::function_ref<void (TypeCheckRequest)> fn ) {
119
+ void IterativeTypeChecker::processTypeCheckSuperclass (
120
+ ClassDecl *classDecl ,
121
+ llvm::function_ref<void (TypeCheckRequest)> recordDependency ) {
128
122
// The superclass should be the first inherited type. However, so
129
123
// long as we see already-resolved types that refer to protocols,
130
124
// skip over them to keep looking for a misplaced superclass. The
131
125
// actual error will be diagnosed when we perform full semantic
132
126
// analysis on the class itself.
133
- auto inheritedClause = payload->getInherited ();
127
+ Type superclassType;
128
+ auto inheritedClause = classDecl->getInherited ();
134
129
for (unsigned i = 0 , n = inheritedClause.size (); i != n; ++i) {
135
130
TypeLoc &inherited = inheritedClause[i];
136
131
137
132
// If this inherited type has not been resolved, we depend on it.
138
133
if (!inherited.getType ()) {
139
- fn (TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
140
- { payload, i }));
134
+ recordDependency (
135
+ TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
136
+ { classDecl, i }));
141
137
return ;
142
138
}
143
139
144
140
// If this resolved inherited type is existential, keep going.
145
141
if (inherited.getType ()->isExistentialType ()) continue ;
146
142
147
- break ;
148
- }
149
- }
150
-
151
- void IterativeTypeChecker::satisfyTypeCheckSuperclass (ClassDecl *classDecl) {
152
- // Loop through the inheritance clause looking for a class type.
153
- Type superclassType;
154
- for (const auto &inherited : classDecl->getInherited ()) {
143
+ // If this resolved type is a class, we're done.
155
144
if (inherited.getType ()->getClassOrBoundGenericClass ()) {
156
145
superclassType = inherited.getType ();
157
146
break ;
@@ -169,42 +158,30 @@ bool IterativeTypeChecker::isTypeCheckRawTypeSatisfied(EnumDecl *payload) {
169
158
return payload->LazySemanticInfo .RawType .getInt ();
170
159
}
171
160
172
- void IterativeTypeChecker::enumerateDependenciesOfTypeCheckRawType (
173
- EnumDecl *payload ,
174
- llvm::function_ref<void (TypeCheckRequest)> fn ) {
161
+ void IterativeTypeChecker::processTypeCheckRawType (
162
+ EnumDecl *enumDecl ,
163
+ llvm::function_ref<void (TypeCheckRequest)> recordDependency ) {
175
164
// The raw type should be the first inherited type. However, so
176
165
// long as we see already-resolved types that refer to protocols,
177
166
// skip over them to keep looking for a misplaced raw type. The
178
167
// actual error will be diagnosed when we perform full semantic
179
168
// analysis on the enum itself.
180
- auto inheritedClause = payload->getInherited ();
169
+ Type rawType;
170
+ auto inheritedClause = enumDecl->getInherited ();
181
171
for (unsigned i = 0 , n = inheritedClause.size (); i != n; ++i) {
182
172
TypeLoc &inherited = inheritedClause[i];
183
173
184
174
// If this inherited type has not been resolved, we depend on it.
185
175
if (!inherited.getType ()) {
186
- fn (TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
187
- { payload, i }));
176
+ recordDependency (
177
+ TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
178
+ { enumDecl, i }));
188
179
return ;
189
180
}
190
181
191
182
// If this resolved inherited type is existential, keep going.
192
183
if (inherited.getType ()->isExistentialType ()) continue ;
193
184
194
- break ;
195
- }
196
- }
197
-
198
- void IterativeTypeChecker::satisfyTypeCheckRawType (EnumDecl *enumDecl) {
199
- // Loop through the inheritance clause looking for a non-existential
200
- // nominal type.
201
- Type rawType;
202
- for (const auto &inherited : enumDecl->getInherited ()) {
203
- if (!inherited.getType ()) break ;
204
-
205
- // Skip existential types.
206
- if (inherited.getType ()->isExistentialType ()) continue ;
207
-
208
185
// Record this raw type.
209
186
rawType = inherited.getType ();
210
187
break ;
@@ -221,40 +198,40 @@ bool IterativeTypeChecker::isInheritedProtocolsSatisfied(ProtocolDecl *payload){
221
198
return payload->isInheritedProtocolsValid ();
222
199
}
223
200
224
- void IterativeTypeChecker::enumerateDependenciesOfInheritedProtocols (
225
- ProtocolDecl *payload ,
226
- llvm::function_ref<void (TypeCheckRequest)> fn ) {
201
+ void IterativeTypeChecker::processInheritedProtocols (
202
+ ProtocolDecl *protocol ,
203
+ llvm::function_ref<void (TypeCheckRequest)> recordDependency ) {
227
204
// Computing the set of inherited protocols depends on the complete
228
205
// inheritance clause.
229
206
// FIXME: Technically, we only need very basic name binding.
230
- auto inheritedClause = payload->getInherited ();
207
+ auto inheritedClause = protocol->getInherited ();
208
+ bool anyDependencies = false ;
209
+ llvm::SmallSetVector<ProtocolDecl *, 4 > allProtocols;
231
210
for (unsigned i = 0 , n = inheritedClause.size (); i != n; ++i) {
232
211
TypeLoc &inherited = inheritedClause[i];
233
212
234
213
// If this inherited type has not been resolved, we depend on it.
235
214
if (!inherited.getType ()) {
236
- fn (TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
237
- { payload, i }));
215
+ recordDependency (
216
+ TypeCheckRequest (TypeCheckRequest::TypeCheckInheritedClauseEntry,
217
+ { protocol, i }));
218
+ anyDependencies = true ;
219
+ continue ;
238
220
}
239
- }
240
- }
241
-
242
- void IterativeTypeChecker::satisfyInheritedProtocols (ProtocolDecl *protocol) {
243
- // Gather all of the existential types in the inherited list.
244
- // Loop through the inheritance clause looking for a non-existential
245
- // nominal type.
246
- llvm::SmallSetVector<ProtocolDecl *, 4 > allProtocols;
247
- for (const auto &inherited : protocol->getInherited ()) {
248
- if (!inherited.getType ()) continue ;
249
221
250
222
// Collect existential types.
251
223
// FIXME: We'd prefer to keep what the user wrote here.
252
224
SmallVector<ProtocolDecl *, 4 > protocols;
253
225
if (inherited.getType ()->isExistentialType (protocols)) {
254
226
allProtocols.insert (protocols.begin (), protocols.end ());
227
+ continue ;
255
228
}
256
229
}
257
230
231
+ // If we enumerated any dependencies, we can't complete this request.
232
+ if (anyDependencies)
233
+ return ;
234
+
258
235
// FIXME: Hack to deal with recursion elsewhere.
259
236
if (protocol->isInheritedProtocolsValid ())
260
237
return ;
0 commit comments