@@ -281,66 +281,54 @@ static void desugarConformanceRequirement(Requirement req,
281
281
SourceLoc loc,
282
282
SmallVectorImpl<Requirement> &result,
283
283
SmallVectorImpl<RequirementError> &errors) {
284
+ SmallVector<Requirement, 2 > subReqs;
285
+
286
+ auto constraintType = req.getSecondType ();
287
+
284
288
// Fast path.
285
- if (req. getSecondType () ->is <ProtocolType>()) {
289
+ if (constraintType ->is <ProtocolType>()) {
286
290
if (req.getFirstType ()->isTypeParameter ()) {
287
291
result.push_back (req);
288
292
return ;
289
293
}
290
294
291
295
// Check if the subject type actually conforms.
292
- auto *protoDecl = req.getProtocolDecl ();
293
- auto *module = protoDecl->getParentModule ();
294
- auto conformance = module ->lookupConformance (
295
- req.getFirstType (), protoDecl, /* allowMissing=*/ true );
296
- if (conformance.isInvalid ()) {
296
+ switch (req.checkRequirement (subReqs, /* allowMissing=*/ true )) {
297
+ case CheckRequirementResult::Success:
298
+ case CheckRequirementResult::PackRequirement:
299
+ case CheckRequirementResult::ConditionalConformance:
300
+ errors.push_back (RequirementError::forRedundantRequirement (req, loc));
301
+ break ;
302
+
303
+ case CheckRequirementResult::RequirementFailure:
297
304
errors.push_back (RequirementError::forInvalidRequirementSubject (req, loc));
298
- return ;
299
- }
300
-
301
- errors.push_back (RequirementError::forRedundantRequirement (req, loc));
305
+ break ;
302
306
303
- if (conformance.isConcrete ()) {
304
- // Introduce conditional requirements if the conformance is concrete.
305
- for (auto condReq : conformance.getConcrete ()->getConditionalRequirements ()) {
306
- desugarRequirement (condReq, loc, result, errors);
307
- }
307
+ case CheckRequirementResult::SubstitutionFailure:
308
+ break ;
309
+ }
310
+ } else if (auto *paramType = constraintType->getAs <ParameterizedProtocolType>()) {
311
+ subReqs.emplace_back (RequirementKind::Conformance, req.getFirstType (),
312
+ paramType->getBaseType ());
313
+ paramType->getRequirements (req.getFirstType (), subReqs);
314
+ } else if (auto *compositionType = constraintType->castTo <ProtocolCompositionType>()) {
315
+ if (compositionType->hasExplicitAnyObject ()) {
316
+ subReqs.emplace_back (RequirementKind::Layout, req.getFirstType (),
317
+ LayoutConstraint::getLayoutConstraint (
318
+ LayoutConstraintKind::Class));
308
319
}
309
320
310
- return ;
311
- }
312
-
313
- if (auto *paramType = req.getSecondType ()->getAs <ParameterizedProtocolType>()) {
314
- SmallVector<Requirement, 2 > reqs;
315
-
316
- reqs.emplace_back (RequirementKind::Conformance, req.getFirstType (),
317
- paramType->getBaseType ());
318
- paramType->getRequirements (req.getFirstType (), reqs);
319
-
320
- for (const auto &req : reqs)
321
- desugarRequirement (req, loc, result, errors);
322
-
323
- return ;
324
- }
325
-
326
- auto *compositionType = req.getSecondType ()->castTo <ProtocolCompositionType>();
327
- SmallVector<Requirement, 2 > memberReqs;
328
- if (compositionType->hasExplicitAnyObject ()) {
329
- memberReqs.emplace_back (RequirementKind::Layout, req.getFirstType (),
330
- LayoutConstraint::getLayoutConstraint (
331
- LayoutConstraintKind::Class));
332
- }
333
-
334
- for (auto memberType : compositionType->getMembers ()) {
335
- memberReqs.emplace_back (
336
- memberType->isConstraintType ()
337
- ? RequirementKind::Conformance
338
- : RequirementKind::Superclass,
339
- req.getFirstType (), memberType);
321
+ for (auto memberType : compositionType->getMembers ()) {
322
+ subReqs.emplace_back (
323
+ memberType->isConstraintType ()
324
+ ? RequirementKind::Conformance
325
+ : RequirementKind::Superclass,
326
+ req.getFirstType (), memberType);
327
+ }
340
328
}
341
329
342
- for (auto memberReq : memberReqs )
343
- desugarRequirement (memberReq , loc, result, errors);
330
+ for (auto subReq : subReqs )
331
+ desugarRequirement (subReq , loc, result, errors);
344
332
}
345
333
346
334
// / Desugar same-shape requirements by equating the shapes of the
0 commit comments