@@ -6379,6 +6379,37 @@ GenericSignatureBuilder::finalize(TypeArrayView<GenericTypeParamType> genericPar
6379
6379
// Process any delayed requirements that we can handle now.
6380
6380
processDelayedRequirements ();
6381
6381
6382
+ {
6383
+ // In various places below, we iterate over the list of equivalence classes
6384
+ // and call getMinimalConformanceSource(). Unfortunately, this function
6385
+ // ends up calling maybeResolveEquivalenceClass(), which can delete equivalence
6386
+ // classes. The workaround is to first iterate safely over a copy of the list,
6387
+ // and pre-compute all minimal conformance sources, before proceeding with the
6388
+ // rest of the function.
6389
+ //
6390
+ // FIXME: This is not even correct, because we may not have reached fixed point
6391
+ // after one round of this. getMinimalConformanceSource() should be removed
6392
+ // instead.
6393
+ SmallVector<PotentialArchetype *, 8 > equivalenceClassPAs;
6394
+ for (auto &equivClass : Impl->EquivalenceClasses ) {
6395
+ equivalenceClassPAs.push_back (equivClass.members .front ());
6396
+ }
6397
+
6398
+ for (auto *pa : equivalenceClassPAs) {
6399
+ auto &equivClass = *pa->getOrCreateEquivalenceClass (*this );
6400
+
6401
+ // Copy the vector and iterate over the copy to avoid iterator invalidation
6402
+ // issues.
6403
+ auto conformsTo = equivClass.conformsTo ;
6404
+ for (auto entry : conformsTo) {
6405
+ for (const auto &constraint : entry.second ) {
6406
+ (void ) constraint.source ->getMinimalConformanceSource (
6407
+ *this , constraint.getSubjectDependentType ({ }), entry.first );
6408
+ }
6409
+ }
6410
+ }
6411
+ }
6412
+
6382
6413
computeRedundantRequirements (requirementSignatureSelfProto);
6383
6414
diagnoseProtocolRefinement (requirementSignatureSelfProto);
6384
6415
diagnoseRedundantRequirements ();
0 commit comments