@@ -378,22 +378,53 @@ bool GenericSignatureImpl::requiresProtocol(Type type,
378378 ProtocolDecl *proto) const {
379379 assert (type->isTypeParameter () && " Expected a type parameter" );
380380
381- auto &builder = *getGenericSignatureBuilder ();
382- auto equivClass =
383- builder.resolveEquivalenceClass (
384- type,
385- ArchetypeResolutionKind::CompleteWellFormed);
386- if (!equivClass) return false ;
381+ auto computeViaGSB = [&]() {
382+ auto &builder = *getGenericSignatureBuilder ();
383+ auto equivClass =
384+ builder.resolveEquivalenceClass (
385+ type,
386+ ArchetypeResolutionKind::CompleteWellFormed);
387+ if (!equivClass) return false ;
387388
388- // FIXME: Optionally deal with concrete conformances here
389- // or have a separate method do that additionally?
390- //
391- // If this type parameter was mapped to a concrete type, then there
392- // are no requirements.
393- if (equivClass->concreteType ) return false ;
389+ // FIXME: Optionally deal with concrete conformances here
390+ // or have a separate method do that additionally?
391+ //
392+ // If this type parameter was mapped to a concrete type, then there
393+ // are no requirements.
394+ if (equivClass->concreteType ) return false ;
395+
396+ // Check whether the representative conforms to this protocol.
397+ return equivClass->conformsTo .count (proto) > 0 ;
398+ };
399+
400+ auto computeViaRQM = [&]() {
401+ auto *machine = getRequirementMachine ();
402+ return machine->requiresProtocol (type, proto);
403+ };
394404
395- // Check whether the representative conforms to this protocol.
396- return equivClass->conformsTo .count (proto) > 0 ;
405+ auto &ctx = getASTContext ();
406+ if (ctx.LangOpts .EnableRequirementMachine ) {
407+ bool rqmResult = computeViaRQM ();
408+
409+ #ifndef NDEBUG
410+ bool gsbResult = computeViaGSB ();
411+
412+ if (gsbResult != rqmResult) {
413+ llvm::errs () << " RequirementMachine::requiresProtocol() is broken\n " ;
414+ llvm::errs () << " Generic signature: " << GenericSignature (this ) << " \n " ;
415+ llvm::errs () << " Dependent type: " ; type.dump (llvm::errs ());
416+ llvm::errs () << " Protocol: " ; proto->dumpRef (llvm::errs ());
417+ llvm::errs () << " \n " ;
418+ llvm::errs () << " GenericSignatureBuilder says: " << gsbResult << " \n " ;
419+ llvm::errs () << " RequirementMachine says: " << rqmResult << " \n " ;
420+ abort ();
421+ }
422+ #endif
423+
424+ return rqmResult;
425+ } else {
426+ return computeViaGSB ();
427+ }
397428}
398429
399430// / Determine whether the given dependent type is equal to a concrete type.
0 commit comments