@@ -186,7 +186,7 @@ swift::rewriting::desugarRequirement(Requirement req,
186
186
//
187
187
188
188
static void realizeTypeRequirement (Type subjectType, Type constraintType,
189
- SourceLoc loc, bool wasInferred,
189
+ SourceLoc loc,
190
190
SmallVectorImpl<StructuralRequirement> &result) {
191
191
// Check whether we have a reasonable constraint type at all.
192
192
if (!constraintType->isExistentialType () &&
@@ -207,7 +207,7 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
207
207
208
208
// Add source location information.
209
209
for (auto req : reqs)
210
- result.push_back ({req, loc, wasInferred});
210
+ result.push_back ({req, loc, /* wasInferred= */ false });
211
211
}
212
212
213
213
// / Infer requirements from applications of BoundGenericTypes to type
@@ -218,21 +218,22 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
218
218
// / We automatically infer 'T : Hashable' from the fact that 'struct Set'
219
219
// / declares a Hashable requirement on its generic parameter.
220
220
void swift::rewriting::inferRequirements (
221
- Type type, SourceLoc loc,
221
+ Type type, SourceLoc loc, ModuleDecl * module ,
222
222
SmallVectorImpl<StructuralRequirement> &result) {
223
223
// FIXME: Implement
224
224
}
225
225
226
226
// / Desugar a requirement and perform requirement inference if requested
227
227
// / to obtain zero or more structural requirements.
228
228
void swift::rewriting::realizeRequirement (
229
- Requirement req, RequirementRepr *reqRepr, bool infer,
229
+ Requirement req, RequirementRepr *reqRepr,
230
+ ModuleDecl *moduleForInference,
230
231
SmallVectorImpl<StructuralRequirement> &result) {
231
232
auto firstType = req.getFirstType ();
232
- if (infer ) {
233
+ if (moduleForInference ) {
233
234
auto firstLoc = (reqRepr ? reqRepr->getFirstTypeRepr ()->getStartLoc ()
234
235
: SourceLoc ());
235
- inferRequirements (firstType, firstLoc, result);
236
+ inferRequirements (firstType, firstLoc, moduleForInference, result);
236
237
}
237
238
238
239
auto loc = (reqRepr ? reqRepr->getSeparatorLoc () : SourceLoc ());
@@ -241,14 +242,13 @@ void swift::rewriting::realizeRequirement(
241
242
case RequirementKind::Superclass:
242
243
case RequirementKind::Conformance: {
243
244
auto secondType = req.getSecondType ();
244
- if (infer ) {
245
+ if (moduleForInference ) {
245
246
auto secondLoc = (reqRepr ? reqRepr->getSecondTypeRepr ()->getStartLoc ()
246
247
: SourceLoc ());
247
- inferRequirements (secondType, secondLoc, result);
248
+ inferRequirements (secondType, secondLoc, moduleForInference, result);
248
249
}
249
250
250
- realizeTypeRequirement (firstType, secondType, loc, /* wasInferred=*/ false ,
251
- result);
251
+ realizeTypeRequirement (firstType, secondType, loc, result);
252
252
break ;
253
253
}
254
254
@@ -264,10 +264,10 @@ void swift::rewriting::realizeRequirement(
264
264
265
265
case RequirementKind::SameType: {
266
266
auto secondType = req.getSecondType ();
267
- if (infer ) {
267
+ if (moduleForInference ) {
268
268
auto secondLoc = (reqRepr ? reqRepr->getSecondTypeRepr ()->getStartLoc ()
269
269
: SourceLoc ());
270
- inferRequirements (secondType, secondLoc, result);
270
+ inferRequirements (secondType, secondLoc, moduleForInference, result);
271
271
}
272
272
273
273
SmallVector<Requirement, 2 > reqs;
@@ -283,7 +283,7 @@ void swift::rewriting::realizeRequirement(
283
283
// / Collect structural requirements written in the inheritance clause of an
284
284
// / AssociatedTypeDecl or GenericTypeParamDecl.
285
285
void swift::rewriting::realizeInheritedRequirements (
286
- TypeDecl *decl, Type type, bool infer ,
286
+ TypeDecl *decl, Type type, ModuleDecl *moduleForInference ,
287
287
SmallVectorImpl<StructuralRequirement> &result) {
288
288
auto &ctx = decl->getASTContext ();
289
289
auto inheritedTypes = decl->getInherited ();
@@ -298,12 +298,11 @@ void swift::rewriting::realizeInheritedRequirements(
298
298
299
299
auto *typeRepr = inheritedTypes[index].getTypeRepr ();
300
300
SourceLoc loc = (typeRepr ? typeRepr->getStartLoc () : SourceLoc ());
301
- if (infer ) {
302
- inferRequirements (inheritedType, loc, result);
301
+ if (moduleForInference ) {
302
+ inferRequirements (inheritedType, loc, moduleForInference, result);
303
303
}
304
304
305
- realizeTypeRequirement (type, inheritedType, loc, /* wasInferred=*/ false ,
306
- result);
305
+ realizeTypeRequirement (type, inheritedType, loc, result);
307
306
}
308
307
}
309
308
@@ -319,12 +318,13 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
319
318
auto selfTy = proto->getSelfInterfaceType ();
320
319
321
320
realizeInheritedRequirements (proto, selfTy,
322
- /* infer =*/ false , result);
321
+ /* moduleForInference =*/ nullptr , result);
323
322
324
323
// Add requirements from the protocol's own 'where' clause.
325
324
WhereClauseOwner (proto).visitRequirements (TypeResolutionStage::Structural,
326
325
[&](const Requirement &req, RequirementRepr *reqRepr) {
327
- realizeRequirement (req, reqRepr, /* infer=*/ false , result);
326
+ realizeRequirement (req, reqRepr,
327
+ /* moduleForInference=*/ nullptr , result);
328
328
return false ;
329
329
});
330
330
@@ -343,14 +343,17 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
343
343
for (auto assocTypeDecl : proto->getAssociatedTypeMembers ()) {
344
344
// Add requirements placed directly on this associated type.
345
345
auto assocType = assocTypeDecl->getDeclaredInterfaceType ();
346
- realizeInheritedRequirements (assocTypeDecl, assocType, /* infer=*/ false ,
346
+ realizeInheritedRequirements (assocTypeDecl, assocType,
347
+ /* moduleForInference=*/ nullptr ,
347
348
result);
348
349
349
350
// Add requirements from this associated type's where clause.
350
351
WhereClauseOwner (assocTypeDecl).visitRequirements (
351
352
TypeResolutionStage::Structural,
352
353
[&](const Requirement &req, RequirementRepr *reqRepr) {
353
- realizeRequirement (req, reqRepr, /* infer=*/ false , result);
354
+ realizeRequirement (req, reqRepr,
355
+ /* moduleForInference=*/ nullptr ,
356
+ result);
354
357
return false ;
355
358
});
356
359
}
0 commit comments