@@ -195,22 +195,9 @@ class MinimalConformances {
195
195
MutableTerm term, unsigned ruleID,
196
196
SmallVectorImpl<unsigned > &result) const ;
197
197
198
- enum class ConcreteConformances : uint8_t {
199
- // / Don't consider paths involving concrete conformances at all.
200
- Disallowed,
201
-
202
- // / Consider paths involving a concrete conformance only if it appears
203
- // / at the end of the path.
204
- AllowedAtEnd,
205
-
206
- // / Consider paths involving concrete conformances anywhere.
207
- AllowedAnywhere
208
- };
209
-
210
198
bool isValidConformancePath (
211
199
llvm::SmallDenseSet<unsigned , 4 > &visited,
212
- const llvm::SmallVectorImpl<unsigned > &path,
213
- ConcreteConformances allowConcrete) const ;
200
+ const llvm::SmallVectorImpl<unsigned > &path) const ;
214
201
215
202
bool isValidRefinementPath (
216
203
const llvm::SmallVectorImpl<unsigned > &path) const ;
@@ -240,7 +227,7 @@ class MinimalConformances {
240
227
241
228
void verifyMinimalConformanceEquations () const ;
242
229
243
- void computeMinimalConformances (bool firstPass );
230
+ void computeMinimalConformances ();
244
231
245
232
void verifyMinimalConformances () const ;
246
233
@@ -622,39 +609,12 @@ void MinimalConformances::computeCandidateConformancePaths() {
622
609
// / rules.
623
610
bool MinimalConformances::isValidConformancePath (
624
611
llvm::SmallDenseSet<unsigned , 4 > &visited,
625
- const llvm::SmallVectorImpl<unsigned > &path,
626
- ConcreteConformances allowConcrete) const {
627
-
628
- unsigned lastIdx = path.size () - 1 ;
612
+ const llvm::SmallVectorImpl<unsigned > &path) const {
629
613
630
- for (unsigned ruleIdx : indices (path)) {
631
- unsigned ruleID = path[ruleIdx];
614
+ for (unsigned ruleID : path) {
632
615
if (visited.count (ruleID) > 0 )
633
616
return false ;
634
617
635
- const auto &rule = System.getRule (ruleID);
636
-
637
- bool isLastElement = (ruleIdx == lastIdx);
638
- bool isConcreteConformance = rule.getLHS ().back ().getKind ()
639
- == Symbol::Kind::ConcreteConformance;
640
-
641
- // Concrete conformances cannot appear in the middle of a conformance path.
642
- if (isConcreteConformance) {
643
- switch (allowConcrete) {
644
- case ConcreteConformances::Disallowed:
645
- return false ;
646
-
647
- case ConcreteConformances::AllowedAtEnd:
648
- if (!isLastElement)
649
- return false ;
650
-
651
- break ;
652
-
653
- case ConcreteConformances::AllowedAnywhere:
654
- break ;
655
- }
656
- }
657
-
658
618
if (RedundantConformances.count (ruleID)) {
659
619
SWIFT_DEFER {
660
620
visited.erase (ruleID);
@@ -665,29 +625,9 @@ bool MinimalConformances::isValidConformancePath(
665
625
if (found == ConformancePaths.end ())
666
626
return false ;
667
627
668
- ConcreteConformances allowConcreteRec;
669
- switch (allowConcrete) {
670
- case ConcreteConformances::Disallowed:
671
- allowConcreteRec = ConcreteConformances::Disallowed;
672
- break ;
673
-
674
- case ConcreteConformances::AllowedAnywhere:
675
- allowConcreteRec = ConcreteConformances::AllowedAnywhere;
676
- break ;
677
-
678
- case ConcreteConformances::AllowedAtEnd:
679
- if (isLastElement)
680
- allowConcreteRec = ConcreteConformances::AllowedAtEnd;
681
- else
682
- allowConcreteRec = ConcreteConformances::Disallowed;
683
-
684
- break ;
685
- }
686
-
687
628
bool foundValidConformancePath = false ;
688
629
for (const auto &otherPath : found->second ) {
689
- if (isValidConformancePath (visited, otherPath,
690
- allowConcreteRec)) {
630
+ if (isValidConformancePath (visited, otherPath)) {
691
631
foundValidConformancePath = true ;
692
632
break ;
693
633
}
@@ -703,19 +643,11 @@ bool MinimalConformances::isValidConformancePath(
703
643
};
704
644
visited.insert (ruleID);
705
645
706
- ConcreteConformances allowConcreteRec;
707
- if (isConcreteConformance)
708
- allowConcreteRec = ConcreteConformances::AllowedAnywhere;
709
- else
710
- allowConcreteRec = ConcreteConformances::AllowedAtEnd;
711
-
712
646
// If 'req' is based on some other conformance requirement
713
647
// `T.[P.]A : Q', we want to make sure that we have a
714
648
// non-redundant derivation for 'T : P'.
715
- if (!isValidConformancePath (visited, found->second ,
716
- allowConcreteRec)) {
649
+ if (!isValidConformancePath (visited, found->second ))
717
650
return false ;
718
- }
719
651
}
720
652
}
721
653
}
@@ -857,48 +789,15 @@ void MinimalConformances::verifyMinimalConformanceEquations() const {
857
789
// /
858
790
// / In the first pass, we only consider conformance requirements that are
859
791
// / made redundant by concrete conformances.
860
- void MinimalConformances::computeMinimalConformances (bool firstPass ) {
792
+ void MinimalConformances::computeMinimalConformances () {
861
793
for (unsigned ruleID : ConformanceRules) {
862
794
auto found = ConformancePaths.find (ruleID);
863
795
if (found == ConformancePaths.end ())
864
796
continue ;
865
797
798
+ const auto &rule = System.getRule (ruleID);
866
799
const auto &paths = found->second ;
867
800
868
- if (firstPass) {
869
- bool derivedViaConcrete = false ;
870
- for (const auto &path : paths) {
871
- if (path.empty ())
872
- continue ;
873
-
874
- // If the rule is itself a concrete conformance, it is not
875
- // derived-via-concrete via itself.
876
- if (path.size () == 1 && path.front () == ruleID)
877
- continue ;
878
-
879
- if (System.getRule (path.back ()).getLHS ().back ().getKind () ==
880
- Symbol::Kind::ConcreteConformance) {
881
- derivedViaConcrete = true ;
882
- break ;
883
- }
884
- }
885
-
886
- // If this rule doesn't involve concrete conformances it will be
887
- // considered in the second pass.
888
- if (!derivedViaConcrete)
889
- continue ;
890
-
891
- if (Debug.contains (DebugFlags::MinimalConformances)) {
892
- llvm::dbgs () << " Derived-via-concrete: " ;
893
- dumpMinimalConformanceEquation (llvm::dbgs (), ruleID, paths);
894
- llvm::dbgs () << " \n " ;
895
- }
896
- } else {
897
- // Ignore rules already determined to be redundant by the first pass.
898
- if (RedundantConformances.count (ruleID) > 0 )
899
- continue ;
900
- }
901
-
902
801
bool isProtocolRefinement = ProtocolRefinements.count (ruleID) > 0 ;
903
802
904
803
for (const auto &path : paths) {
@@ -910,13 +809,10 @@ void MinimalConformances::computeMinimalConformances(bool firstPass) {
910
809
llvm::SmallDenseSet<unsigned , 4 > visited;
911
810
visited.insert (ruleID);
912
811
913
- if (isValidConformancePath (visited, path,
914
- ConcreteConformances::AllowedAtEnd)) {
812
+ if (isValidConformancePath (visited, path)) {
915
813
if (Debug.contains (DebugFlags::MinimalConformances)) {
916
- llvm::dbgs () << " Redundant rule in " ;
917
- llvm::dbgs () << (firstPass ? " first" : " second" );
918
- llvm::dbgs () << " pass: " ;
919
- llvm::dbgs () << System.getRule (ruleID).getLHS ();
814
+ llvm::dbgs () << " Redundant rule: " ;
815
+ llvm::dbgs () << rule.getLHS ();
920
816
llvm::dbgs () << " \n " ;
921
817
llvm::dbgs () << " -- via valid path: " ;
922
818
dumpConformancePath (llvm::errs (), path);
@@ -945,19 +841,7 @@ void MinimalConformances::verifyMinimalConformances() const {
945
841
llvm::SmallVector<unsigned , 1 > path;
946
842
path.push_back (ruleID);
947
843
948
- ConcreteConformances allowConcrete;
949
- if (rule.isProtocolConformanceRule ()) {
950
- // Protocol conformance rules are recoverable if the path
951
- // has a concrete conformance at the end.
952
- allowConcrete = ConcreteConformances::AllowedAtEnd;
953
- } else {
954
- // Concrete conformance rules are recoverable via paths
955
- // containing other concrete conformances anywhere.
956
- assert (rule.isAnyConformanceRule ());
957
- allowConcrete = ConcreteConformances::AllowedAnywhere;
958
- }
959
-
960
- if (!isValidConformancePath (visited, path, allowConcrete)) {
844
+ if (!isValidConformancePath (visited, path)) {
961
845
llvm::errs () << " Redundant conformance is not recoverable:\n " ;
962
846
llvm::errs () << rule << " \n\n " ;
963
847
dumpMinimalConformanceEquations (llvm::errs ());
@@ -1006,8 +890,7 @@ void RewriteSystem::computeMinimalConformances(
1006
890
}
1007
891
1008
892
builder.verifyMinimalConformanceEquations ();
1009
- builder.computeMinimalConformances (/* firstPass=*/ true );
1010
- builder.computeMinimalConformances (/* firstPass=*/ false );
893
+ builder.computeMinimalConformances ();
1011
894
builder.verifyMinimalConformances ();
1012
895
1013
896
if (Debug.contains (DebugFlags::MinimalConformances)) {
0 commit comments