@@ -150,8 +150,11 @@ namespace {
150
150
// / Utility class to encapsulate some shared state.
151
151
class GeneratingConformances {
152
152
const RewriteSystem &System;
153
+
153
154
RewriteContext &Context;
154
155
156
+ DebugOptions Debug;
157
+
155
158
// All conformance rules, sorted by (isExplicit(), getLHS()), with non-explicit
156
159
// rules with longer left hand sides coming first.
157
160
//
@@ -209,6 +212,7 @@ class GeneratingConformances {
209
212
llvm::DenseSet<unsigned > &redundantConformances)
210
213
: System(system),
211
214
Context(system.getRewriteContext()),
215
+ Debug(system.getDebugOptions()),
212
216
RedundantConformances(redundantConformances) {}
213
217
214
218
void collectConformanceRules ();
@@ -481,7 +485,7 @@ void GeneratingConformances::computeCandidateConformancePaths() {
481
485
if (result.empty ())
482
486
continue ;
483
487
484
- if (System. getDebugOptions () .contains (DebugFlags::GeneratingConformances)) {
488
+ if (Debug .contains (DebugFlags::GeneratingConformances)) {
485
489
llvm::dbgs () << " Candidate homotopy generator: " ;
486
490
loop.dump (llvm::dbgs (), System);
487
491
llvm::dbgs () << " \n " ;
@@ -497,7 +501,7 @@ void GeneratingConformances::computeCandidateConformancePaths() {
497
501
if (inEmptyContext.empty ())
498
502
continue ;
499
503
500
- if (System. getDebugOptions () .contains (DebugFlags::GeneratingConformances)) {
504
+ if (Debug .contains (DebugFlags::GeneratingConformances)) {
501
505
llvm::dbgs () << " * Protocol " << proto->getName () << " :\n " ;
502
506
llvm::dbgs () << " ** Conformance rules not in context:\n " ;
503
507
for (unsigned ruleID : inEmptyContext) {
@@ -755,7 +759,7 @@ void GeneratingConformances::verifyGeneratingConformanceEquations() const {
755
759
llvm::errs () << " Mismatched conformance:\n " ;
756
760
llvm::errs () << " Base rule: " << rule << " \n " ;
757
761
llvm::errs () << " Final rule: " << otherRule << " \n\n " ;
758
- System. dump (llvm::errs ());
762
+ dumpGeneratingConformanceEquations (llvm::errs ());
759
763
abort ();
760
764
}
761
765
@@ -772,7 +776,7 @@ void GeneratingConformances::verifyGeneratingConformanceEquations() const {
772
776
pair.first , pair.second );
773
777
llvm::errs () << " \n " ;
774
778
llvm::errs () << " Term: " << rule << " \n " ;
775
- System. dump (llvm::errs ());
779
+ dumpGeneratingConformanceEquations (llvm::errs ());
776
780
abort ();
777
781
}
778
782
@@ -789,7 +793,7 @@ void GeneratingConformances::verifyGeneratingConformanceEquations() const {
789
793
llvm::errs () << " Invalid conformance path:\n " ;
790
794
llvm::errs () << " Expected: " << baseTerm << " \n " ;
791
795
llvm::errs () << " Got: " << otherTerm << " \n\n " ;
792
- System. dump (llvm::errs ());
796
+ dumpGeneratingConformanceEquations (llvm::errs ());
793
797
abort ();
794
798
}
795
799
}
@@ -811,7 +815,12 @@ void GeneratingConformances::computeGeneratingConformances(
811
815
bool derivedViaConcrete = false ;
812
816
for (const auto &path : paths) {
813
817
if (path.empty ())
814
- break ;
818
+ continue ;
819
+
820
+ // If the rule is itself a concrete conformance, it is not
821
+ // derived-via-concrete via itself.
822
+ if (path.size () == 1 && path.front () == ruleID)
823
+ continue ;
815
824
816
825
if (System.getRule (path.back ()).getLHS ().back ().getKind () ==
817
826
Symbol::Kind::ConcreteConformance) {
@@ -824,6 +833,12 @@ void GeneratingConformances::computeGeneratingConformances(
824
833
// considered in the second pass.
825
834
if (!derivedViaConcrete)
826
835
continue ;
836
+
837
+ if (Debug.contains (DebugFlags::GeneratingConformances)) {
838
+ llvm::dbgs () << " Derived-via-concrete: " ;
839
+ dumpGeneratingConformanceEquation (llvm::dbgs (), ruleID, paths);
840
+ llvm::dbgs () << " \n " ;
841
+ }
827
842
} else {
828
843
// Ignore rules already determined to be redundant by the first pass.
829
844
if (RedundantConformances.count (ruleID) > 0 )
@@ -843,6 +858,14 @@ void GeneratingConformances::computeGeneratingConformances(
843
858
844
859
if (isValidConformancePath (visited, path,
845
860
/* allowConcrete=*/ true )) {
861
+ if (Debug.contains (DebugFlags::GeneratingConformances)) {
862
+ llvm::dbgs () << " Redundant rule in " ;
863
+ llvm::dbgs () << (firstPass ? " first" : " second" );
864
+ llvm::dbgs () << " pass: " ;
865
+ llvm::dbgs () << System.getRule (ruleID).getLHS ();
866
+ llvm::dbgs () << " \n " ;
867
+ }
868
+
846
869
RedundantConformances.insert (ruleID);
847
870
break ;
848
871
}
@@ -869,7 +892,7 @@ void GeneratingConformances::verifyGeneratingConformances() const {
869
892
/* allowConcrete=*/ true )) {
870
893
llvm::errs () << " Redundant conformance is not recoverable:\n " ;
871
894
llvm::errs () << rule << " \n\n " ;
872
- System. dump (llvm::errs ());
895
+ dumpGeneratingConformanceEquations (llvm::errs ());
873
896
abort ();
874
897
}
875
898
@@ -879,14 +902,14 @@ void GeneratingConformances::verifyGeneratingConformances() const {
879
902
if (rule.isRedundant ()) {
880
903
llvm::errs () << " Generating conformance is redundant: " ;
881
904
llvm::errs () << rule << " \n\n " ;
882
- System. dump (llvm::errs ());
905
+ dumpGeneratingConformanceEquations (llvm::errs ());
883
906
abort ();
884
907
}
885
908
886
909
if (rule.getLHS ().containsUnresolvedSymbols ()) {
887
910
llvm::errs () << " Generating conformance contains unresolved symbols: " ;
888
911
llvm::errs () << rule << " \n\n " ;
889
- System. dump (llvm::errs ());
912
+ dumpGeneratingConformanceEquations (llvm::errs ());
890
913
abort ();
891
914
}
892
915
}
0 commit comments