@@ -6534,6 +6534,39 @@ GenericSignatureBuilder::finalize(TypeArrayView<GenericTypeParamType> genericPar
6534
6534
// Process any delayed requirements that we can handle now.
6535
6535
processDelayedRequirements ();
6536
6536
6537
+ {
6538
+ // In various places below, we iterate over the list of equivalence classes
6539
+ // and call getMinimalConformanceSource(). Unfortunately, this function
6540
+ // ends up calling maybeResolveEquivalenceClass(), which can delete equivalence
6541
+ // classes. The workaround is to first iterate safely over a copy of the list,
6542
+ // and pre-compute all minimal conformance sources, before proceeding with the
6543
+ // rest of the function.
6544
+ //
6545
+ // FIXME: This is not even correct, because we may not have reached fixed point
6546
+ // after one round of this. getMinimalConformanceSource() should be removed
6547
+ // instead.
6548
+ SmallVector<PotentialArchetype *, 8 > equivalenceClassPAs;
6549
+ for (auto &equivClass : Impl->EquivalenceClasses ) {
6550
+ equivalenceClassPAs.push_back (equivClass.members .front ());
6551
+ }
6552
+
6553
+ for (auto *pa : equivalenceClassPAs) {
6554
+ auto &equivClass = *pa->getOrCreateEquivalenceClass (*this );
6555
+
6556
+ // Copy the vector and iterate over the copy to avoid iterator invalidation
6557
+ // issues.
6558
+ auto conformsTo = equivClass.conformsTo ;
6559
+ for (auto entry : conformsTo) {
6560
+ for (const auto &constraint : entry.second ) {
6561
+ bool derivedViaConcrete = false ;
6562
+ (void ) constraint.source ->getMinimalConformanceSource (
6563
+ *this , constraint.getSubjectDependentType ({ }), entry.first ,
6564
+ derivedViaConcrete);
6565
+ }
6566
+ }
6567
+ }
6568
+ }
6569
+
6537
6570
computeRedundantRequirements ();
6538
6571
diagnoseRedundantRequirements ();
6539
6572
diagnoseConflictingConcreteTypeRequirements ();
0 commit comments