@@ -186,7 +186,7 @@ swift::rewriting::desugarRequirement(Requirement req,
186186//
187187
188188static void realizeTypeRequirement (Type subjectType, Type constraintType,
189- SourceLoc loc, bool wasInferred,
189+ SourceLoc loc,
190190 SmallVectorImpl<StructuralRequirement> &result) {
191191 // Check whether we have a reasonable constraint type at all.
192192 if (!constraintType->isExistentialType () &&
@@ -207,7 +207,7 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
207207
208208 // Add source location information.
209209 for (auto req : reqs)
210- result.push_back ({req, loc, wasInferred});
210+ result.push_back ({req, loc, /* wasInferred= */ false });
211211}
212212
213213// / Infer requirements from applications of BoundGenericTypes to type
@@ -218,21 +218,22 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
218218// / We automatically infer 'T : Hashable' from the fact that 'struct Set'
219219// / declares a Hashable requirement on its generic parameter.
220220void swift::rewriting::inferRequirements (
221- Type type, SourceLoc loc,
221+ Type type, SourceLoc loc, ModuleDecl * module ,
222222 SmallVectorImpl<StructuralRequirement> &result) {
223223 // FIXME: Implement
224224}
225225
226226// / Desugar a requirement and perform requirement inference if requested
227227// / to obtain zero or more structural requirements.
228228void swift::rewriting::realizeRequirement (
229- Requirement req, RequirementRepr *reqRepr, bool infer,
229+ Requirement req, RequirementRepr *reqRepr,
230+ ModuleDecl *moduleForInference,
230231 SmallVectorImpl<StructuralRequirement> &result) {
231232 auto firstType = req.getFirstType ();
232- if (infer ) {
233+ if (moduleForInference ) {
233234 auto firstLoc = (reqRepr ? reqRepr->getFirstTypeRepr ()->getStartLoc ()
234235 : SourceLoc ());
235- inferRequirements (firstType, firstLoc, result);
236+ inferRequirements (firstType, firstLoc, moduleForInference, result);
236237 }
237238
238239 auto loc = (reqRepr ? reqRepr->getSeparatorLoc () : SourceLoc ());
@@ -241,14 +242,13 @@ void swift::rewriting::realizeRequirement(
241242 case RequirementKind::Superclass:
242243 case RequirementKind::Conformance: {
243244 auto secondType = req.getSecondType ();
244- if (infer ) {
245+ if (moduleForInference ) {
245246 auto secondLoc = (reqRepr ? reqRepr->getSecondTypeRepr ()->getStartLoc ()
246247 : SourceLoc ());
247- inferRequirements (secondType, secondLoc, result);
248+ inferRequirements (secondType, secondLoc, moduleForInference, result);
248249 }
249250
250- realizeTypeRequirement (firstType, secondType, loc, /* wasInferred=*/ false ,
251- result);
251+ realizeTypeRequirement (firstType, secondType, loc, result);
252252 break ;
253253 }
254254
@@ -264,10 +264,10 @@ void swift::rewriting::realizeRequirement(
264264
265265 case RequirementKind::SameType: {
266266 auto secondType = req.getSecondType ();
267- if (infer ) {
267+ if (moduleForInference ) {
268268 auto secondLoc = (reqRepr ? reqRepr->getSecondTypeRepr ()->getStartLoc ()
269269 : SourceLoc ());
270- inferRequirements (secondType, secondLoc, result);
270+ inferRequirements (secondType, secondLoc, moduleForInference, result);
271271 }
272272
273273 SmallVector<Requirement, 2 > reqs;
@@ -283,7 +283,7 @@ void swift::rewriting::realizeRequirement(
283283// / Collect structural requirements written in the inheritance clause of an
284284// / AssociatedTypeDecl or GenericTypeParamDecl.
285285void swift::rewriting::realizeInheritedRequirements (
286- TypeDecl *decl, Type type, bool infer ,
286+ TypeDecl *decl, Type type, ModuleDecl *moduleForInference ,
287287 SmallVectorImpl<StructuralRequirement> &result) {
288288 auto &ctx = decl->getASTContext ();
289289 auto inheritedTypes = decl->getInherited ();
@@ -298,12 +298,11 @@ void swift::rewriting::realizeInheritedRequirements(
298298
299299 auto *typeRepr = inheritedTypes[index].getTypeRepr ();
300300 SourceLoc loc = (typeRepr ? typeRepr->getStartLoc () : SourceLoc ());
301- if (infer ) {
302- inferRequirements (inheritedType, loc, result);
301+ if (moduleForInference ) {
302+ inferRequirements (inheritedType, loc, moduleForInference, result);
303303 }
304304
305- realizeTypeRequirement (type, inheritedType, loc, /* wasInferred=*/ false ,
306- result);
305+ realizeTypeRequirement (type, inheritedType, loc, result);
307306 }
308307}
309308
@@ -319,12 +318,13 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
319318 auto selfTy = proto->getSelfInterfaceType ();
320319
321320 realizeInheritedRequirements (proto, selfTy,
322- /* infer =*/ false , result);
321+ /* moduleForInference =*/ nullptr , result);
323322
324323 // Add requirements from the protocol's own 'where' clause.
325324 WhereClauseOwner (proto).visitRequirements (TypeResolutionStage::Structural,
326325 [&](const Requirement &req, RequirementRepr *reqRepr) {
327- realizeRequirement (req, reqRepr, /* infer=*/ false , result);
326+ realizeRequirement (req, reqRepr,
327+ /* moduleForInference=*/ nullptr , result);
328328 return false ;
329329 });
330330
@@ -343,14 +343,17 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
343343 for (auto assocTypeDecl : proto->getAssociatedTypeMembers ()) {
344344 // Add requirements placed directly on this associated type.
345345 auto assocType = assocTypeDecl->getDeclaredInterfaceType ();
346- realizeInheritedRequirements (assocTypeDecl, assocType, /* infer=*/ false ,
346+ realizeInheritedRequirements (assocTypeDecl, assocType,
347+ /* moduleForInference=*/ nullptr ,
347348 result);
348349
349350 // Add requirements from this associated type's where clause.
350351 WhereClauseOwner (assocTypeDecl).visitRequirements (
351352 TypeResolutionStage::Structural,
352353 [&](const Requirement &req, RequirementRepr *reqRepr) {
353- realizeRequirement (req, reqRepr, /* infer=*/ false , result);
354+ realizeRequirement (req, reqRepr,
355+ /* moduleForInference=*/ nullptr ,
356+ result);
354357 return false ;
355358 });
356359 }
0 commit comments