@@ -752,6 +752,16 @@ struct InferredTypeWitnessesSolution {
752
752
LLVM_ATTRIBUTE_USED
753
753
#endif
754
754
void dump (llvm::raw_ostream &out) const ;
755
+
756
+ bool operator ==(const InferredTypeWitnessesSolution &other) const {
757
+ for (const auto &otherTypeWitness : other.TypeWitnesses ) {
758
+ auto typeWitness = TypeWitnesses.find (otherTypeWitness.first );
759
+ if (!typeWitness->second .first ->isEqual (otherTypeWitness.second .first ))
760
+ return false ;
761
+ }
762
+
763
+ return true ;
764
+ }
755
765
};
756
766
757
767
void InferredTypeWitnessesSolution::dump (llvm::raw_ostream &out) const {
@@ -3059,17 +3069,7 @@ void AssociatedTypeInference::findSolutionsRec(
3059
3069
3060
3070
// We fold away non-viable solutions that have the same type witnesses.
3061
3071
if (invalid) {
3062
- auto matchesSolution = [&](const InferredTypeWitnessesSolution &other) {
3063
- for (const auto &otherTypeWitness : other.TypeWitnesses ) {
3064
- auto typeWitness = solution.TypeWitnesses .find (otherTypeWitness.first );
3065
- if (!typeWitness->second .first ->isEqual (otherTypeWitness.second .first ))
3066
- return false ;
3067
- }
3068
-
3069
- return true ;
3070
- };
3071
-
3072
- if (llvm::any_of (nonViableSolutions, matchesSolution)) {
3072
+ if (llvm::find (nonViableSolutions, solution) != nonViableSolutions.end ()) {
3073
3073
LLVM_DEBUG (llvm::dbgs () << std::string (valueWitnesses.size (), ' +' )
3074
3074
<< " + Duplicate invalid solution found\n " ;);
3075
3075
++NumDuplicateSolutionStates;
@@ -3871,7 +3871,13 @@ auto AssociatedTypeInference::solve()
3871
3871
}
3872
3872
}
3873
3873
3874
- // Happy case: we found exactly one viable solution.
3874
+ // If we still have multiple solutions, they might have identical
3875
+ // type witnesses.
3876
+ while (solutions.size () > 1 && solutions.front () == solutions.back ()) {
3877
+ solutions.pop_back ();
3878
+ }
3879
+
3880
+ // Happy case: we found exactly one unique viable solution.
3875
3881
if (solutions.size () == 1 ) {
3876
3882
// Form the resulting solution.
3877
3883
auto &typeWitnesses = solutions.front ().TypeWitnesses ;
0 commit comments