@@ -790,6 +790,23 @@ void RewriteSystem::minimizeRewriteSystem() {
790790 verifyMinimizedRules ();
791791}
792792
793+ // / In a conformance-valid rewrite system, any rule with unresolved symbols on
794+ // / the left or right hand side should have been simplified by another rule.
795+ bool RewriteSystem::hasNonRedundantUnresolvedRules () const {
796+ assert (Complete);
797+ assert (Minimized);
798+
799+ for (const auto &rule : Rules) {
800+ if (!rule.isRedundant () &&
801+ !rule.isPermanent () &&
802+ rule.containsUnresolvedSymbols ()) {
803+ return true ;
804+ }
805+ }
806+
807+ return false ;
808+ }
809+
793810// / Collect all non-permanent, non-redundant rules whose domain is equal to
794811// / one of the protocols in \p proto. In other words, the first symbol of the
795812// / left hand side term is either a protocol symbol or associated type symbol
@@ -805,11 +822,11 @@ RewriteSystem::getMinimizedProtocolRules(
805822 for (unsigned ruleID : indices (Rules)) {
806823 const auto &rule = getRule (ruleID);
807824
808- if (rule.isPermanent ())
809- continue ;
810-
811- if (rule.isRedundant ())
825+ if (rule.isPermanent () ||
826+ rule.isRedundant () ||
827+ rule.containsUnresolvedSymbols ()) {
812828 continue ;
829+ }
813830
814831 auto domain = rule.getLHS ()[0 ].getProtocols ();
815832 assert (domain.size () == 1 );
@@ -834,11 +851,11 @@ RewriteSystem::getMinimizedGenericSignatureRules() const {
834851 for (unsigned ruleID : indices (Rules)) {
835852 const auto &rule = getRule (ruleID);
836853
837- if (rule.isPermanent ())
838- continue ;
839-
840- if (rule.isRedundant ())
854+ if (rule.isPermanent () ||
855+ rule.isRedundant () ||
856+ rule.containsUnresolvedSymbols ()) {
841857 continue ;
858+ }
842859
843860 if (rule.getLHS ()[0 ].getKind () != Symbol::Kind::GenericParam)
844861 continue ;
@@ -917,29 +934,17 @@ void RewriteSystem::verifyMinimizedRules() const {
917934 continue ;
918935 }
919936
920- if (rule.isRedundant ())
921- continue ;
922-
923937 // Simplified rules should be redundant, unless they're protocol conformance
924938 // rules, which unfortunately might no be redundant, because we try to keep
925939 // them in the original protocol definition for compatibility with the
926940 // GenericSignatureBuilder's minimization algorithm.
927- if (rule.isSimplified () && !rule.isProtocolConformanceRule ()) {
941+ if (rule.isSimplified () &&
942+ !rule.isRedundant () &&
943+ !rule.isProtocolConformanceRule ()) {
928944 llvm::errs () << " Simplified rule is not redundant: " << rule << " \n\n " ;
929945 dump (llvm::errs ());
930946 abort ();
931947 }
932-
933- // Rules with unresolved name symbols (other than permanent rules for
934- // associated type introduction) should be redundant.
935- //
936- // FIXME: What about invalid code?
937- if (rule.getLHS ().containsUnresolvedSymbols () ||
938- rule.getRHS ().containsUnresolvedSymbols ()) {
939- llvm::errs () << " Unresolved rule is not redundant: " << rule << " \n\n " ;
940- dump (llvm::errs ());
941- abort ();
942- }
943948 }
944949#endif
945950}
0 commit comments