@@ -353,26 +353,62 @@ GenericSignature::RequiredProtocols
353
353
GenericSignatureImpl::getRequiredProtocols (Type type) const {
354
354
assert (type->isTypeParameter () && " Expected a type parameter" );
355
355
356
- auto &builder = *getGenericSignatureBuilder ();
357
- auto equivClass =
358
- builder.resolveEquivalenceClass (
359
- type,
360
- ArchetypeResolutionKind::CompleteWellFormed);
361
- if (!equivClass) return { };
356
+ auto computeViaGSB = [&]() -> GenericSignature::RequiredProtocols {
357
+ auto &builder = *getGenericSignatureBuilder ();
358
+ auto equivClass =
359
+ builder.resolveEquivalenceClass (
360
+ type,
361
+ ArchetypeResolutionKind::CompleteWellFormed);
362
+ if (!equivClass) return { };
362
363
363
- // If this type parameter was mapped to a concrete type, then there
364
- // are no requirements.
365
- if (equivClass->concreteType ) return { };
364
+ // If this type parameter was mapped to a concrete type, then there
365
+ // are no requirements.
366
+ if (equivClass->concreteType ) return { };
366
367
367
- // Retrieve the protocols to which this type conforms.
368
- GenericSignature::RequiredProtocols result;
369
- for (const auto &conforms : equivClass->conformsTo )
370
- result.push_back (conforms.first );
368
+ // Retrieve the protocols to which this type conforms.
369
+ GenericSignature::RequiredProtocols result;
370
+ for (const auto &conforms : equivClass->conformsTo )
371
+ result.push_back (conforms.first );
371
372
372
- // Canonicalize the resulting set of protocols.
373
- ProtocolType::canonicalizeProtocols (result);
373
+ // Canonicalize the resulting set of protocols.
374
+ ProtocolType::canonicalizeProtocols (result);
374
375
375
- return result;
376
+ return result;
377
+ };
378
+
379
+ auto computeViaRQM = [&]() {
380
+ auto *machine = getRequirementMachine ();
381
+ return machine->getRequiredProtocols (type);
382
+ };
383
+
384
+ auto &ctx = getASTContext ();
385
+ if (ctx.LangOpts .EnableRequirementMachine ) {
386
+ auto rqmResult = computeViaRQM ();
387
+
388
+ #ifndef NDEBUG
389
+ auto gsbResult = computeViaGSB ();
390
+
391
+ if (gsbResult != rqmResult) {
392
+ llvm::errs () << " RequirementMachine::getRequiredProtocols() is broken\n " ;
393
+ llvm::errs () << " Generic signature: " << GenericSignature (this ) << " \n " ;
394
+ llvm::errs () << " Dependent type: " ; type.dump (llvm::errs ());
395
+ llvm::errs () << " GenericSignatureBuilder says: " ;
396
+ for (auto *otherProto : gsbResult)
397
+ llvm::errs () << " " << otherProto->getName ();
398
+ llvm::errs () << " \n " ;
399
+ llvm::errs () << " RequirementMachine says: " ;
400
+ for (auto *otherProto : rqmResult)
401
+ llvm::errs () << " " << otherProto->getName ();
402
+ llvm::errs () << " \n " ;
403
+ getRequirementMachine ()->dump (llvm::errs ());
404
+ abort ();
405
+ }
406
+ #endif
407
+
408
+ return rqmResult;
409
+ } else {
410
+ return computeViaGSB ();
411
+ }
376
412
}
377
413
378
414
bool GenericSignatureImpl::requiresProtocol (Type type,
0 commit comments