@@ -778,6 +778,9 @@ void RewriteSystem::minimizeRewriteSystem() {
778
778
loop.normalize (*this );
779
779
}
780
780
781
+ // Check invariants before homotopy reduction.
782
+ verifyHomotopyGenerators ();
783
+
781
784
// First pass: Eliminate all redundant rules involving unresolved types.
782
785
performHomotopyReduction (/* firstPass=*/ true ,
783
786
/* redundantConformances=*/ nullptr );
@@ -798,57 +801,10 @@ void RewriteSystem::minimizeRewriteSystem() {
798
801
performHomotopyReduction (/* firstPass=*/ false ,
799
802
/* redundantConformances=*/ &redundantConformances);
800
803
801
- // Assert if homotopy reduction failed to eliminate a redundant conformance,
802
- // since this suggests a misunderstanding on my part.
803
- for (unsigned ruleID : redundantConformances) {
804
- const auto &rule = getRule (ruleID);
805
- assert (rule.isProtocolConformanceRule () &&
806
- " Redundant conformance is not a conformance rule?" );
807
-
808
- if (!rule.isRedundant ()) {
809
- llvm::errs () << " Homotopy reduction did not eliminate redundant "
810
- << " conformance?\n " ;
811
- llvm::errs () << " (#" << ruleID << " ) " << rule << " \n\n " ;
812
- dump (llvm::errs ());
813
- abort ();
814
- }
815
- }
816
-
817
- // Assert if homotopy reduction failed to eliminate a rewrite rule which was
818
- // deleted because either it's left hand side can be reduced by some other
819
- // rule, or because it's right hand side can be reduced further.
820
- for (const auto &rule : Rules) {
821
- // Note that sometimes permanent rules can be simplified, but they can never
822
- // be redundant.
823
- if (rule.isPermanent ()) {
824
- if (rule.isRedundant ()) {
825
- llvm::errs () << " Permanent rule is redundant: " << rule << " \n\n " ;
826
- dump (llvm::errs ());
827
- abort ();
828
- }
829
-
830
- continue ;
831
- }
832
-
833
- if (rule.isRedundant ())
834
- continue ;
835
-
836
- // Simplified rules should be redundant.
837
- if (rule.isSimplified ()) {
838
- llvm::errs () << " Simplified rule is not redundant: " << rule << " \n\n " ;
839
- dump (llvm::errs ());
840
- abort ();
841
- }
842
-
843
- // Rules with unresolved name symbols (other than permanent rules for
844
- // associated type introduction) should be redundant.
845
- if (rule.getLHS ().containsUnresolvedSymbols () ||
846
- rule.getRHS ().containsUnresolvedSymbols ()) {
847
- llvm::errs () << " Unresolved rule is not redundant: " << rule << " \n\n " ;
848
- dump (llvm::errs ());
849
- abort ();
850
- }
851
- }
804
+ // Check invariants after homotopy reduction.
805
+ verifyHomotopyGenerators ();
806
+ verifyRedundantConformances (redundantConformances);
807
+ verifyMinimizedRules ();
852
808
}
853
809
854
810
// / Collect all non-permanent, non-redundant rules whose domain is equal to
@@ -897,4 +853,60 @@ void RewriteSystem::verifyHomotopyGenerators() const {
897
853
}
898
854
}
899
855
#endif
856
+ }
857
+
858
+ // / Assert if homotopy reduction failed to eliminate a redundant conformance,
859
+ // / since this suggests a misunderstanding on my part.
860
+ void RewriteSystem::verifyRedundantConformances (
861
+ llvm::DenseSet<unsigned > redundantConformances) const {
862
+ for (unsigned ruleID : redundantConformances) {
863
+ const auto &rule = getRule (ruleID);
864
+ assert (rule.isProtocolConformanceRule () &&
865
+ " Redundant conformance is not a conformance rule?" );
866
+
867
+ if (!rule.isRedundant ()) {
868
+ llvm::errs () << " Homotopy reduction did not eliminate redundant "
869
+ << " conformance?\n " ;
870
+ llvm::errs () << " (#" << ruleID << " ) " << rule << " \n\n " ;
871
+ dump (llvm::errs ());
872
+ abort ();
873
+ }
874
+ }
875
+ }
876
+
877
+ // Assert if homotopy reduction failed to eliminate a rewrite rule it was
878
+ // supposed to delete.
879
+ void RewriteSystem::verifyMinimizedRules () const {
880
+ for (const auto &rule : Rules) {
881
+ // Note that sometimes permanent rules can be simplified, but they can never
882
+ // be redundant.
883
+ if (rule.isPermanent ()) {
884
+ if (rule.isRedundant ()) {
885
+ llvm::errs () << " Permanent rule is redundant: " << rule << " \n\n " ;
886
+ dump (llvm::errs ());
887
+ abort ();
888
+ }
889
+
890
+ continue ;
891
+ }
892
+
893
+ if (rule.isRedundant ())
894
+ continue ;
895
+
896
+ // Simplified rules should be redundant.
897
+ if (rule.isSimplified ()) {
898
+ llvm::errs () << " Simplified rule is not redundant: " << rule << " \n\n " ;
899
+ dump (llvm::errs ());
900
+ abort ();
901
+ }
902
+
903
+ // Rules with unresolved name symbols (other than permanent rules for
904
+ // associated type introduction) should be redundant.
905
+ if (rule.getLHS ().containsUnresolvedSymbols () ||
906
+ rule.getRHS ().containsUnresolvedSymbols ()) {
907
+ llvm::errs () << " Unresolved rule is not redundant: " << rule << " \n\n " ;
908
+ dump (llvm::errs ());
909
+ abort ();
910
+ }
911
+ }
900
912
}
0 commit comments