@@ -1549,6 +1549,27 @@ unsigned GenericSignatureBuilder::PotentialArchetype::getNestingDepth() const {
1549
1549
return Depth;
1550
1550
}
1551
1551
1552
+ bool EquivalenceClass::recordConformanceConstraint (
1553
+ PotentialArchetype *pa,
1554
+ ProtocolDecl *proto,
1555
+ const RequirementSource *source) {
1556
+ // If we haven't seen a conformance to this protocol yet, add it.
1557
+ bool inserted = false ;
1558
+ auto known = conformsTo.find (proto);
1559
+ if (known == conformsTo.end ()) {
1560
+ known = conformsTo.insert ({ proto, { }}).first ;
1561
+ inserted = true ;
1562
+ modified (*pa->getBuilder ());
1563
+ ++NumConformances;
1564
+ }
1565
+
1566
+ // Record this conformance source.
1567
+ known->second .push_back ({pa, proto, source});
1568
+ ++NumConformanceConstraints;
1569
+
1570
+ return inserted;
1571
+ }
1572
+
1552
1573
Optional<ConcreteConstraint>
1553
1574
EquivalenceClass::findAnyConcreteConstraintAsWritten (
1554
1575
PotentialArchetype *preferredPA) const {
@@ -2119,11 +2140,8 @@ GenericSignatureBuilder::resolveConcreteConformance(PotentialArchetype *pa,
2119
2140
}
2120
2141
2121
2142
concreteSource = concreteSource->viaConcrete (*this , *conformance);
2122
- paEquivClass->conformsTo [proto].push_back ({pa, proto, concreteSource});
2123
- ++NumConformanceConstraints;
2124
-
2143
+ paEquivClass->recordConformanceConstraint (pa, proto, concreteSource);
2125
2144
addConditionalRequirements (*this , *conformance);
2126
-
2127
2145
return concreteSource;
2128
2146
}
2129
2147
@@ -2154,11 +2172,8 @@ const RequirementSource *GenericSignatureBuilder::resolveSuperConformance(
2154
2172
2155
2173
superclassSource =
2156
2174
superclassSource->viaSuperclass (*this , *conformance);
2157
- paEquivClass->conformsTo [proto].push_back ({pa, proto, superclassSource});
2158
- ++NumConformanceConstraints;
2159
-
2175
+ paEquivClass->recordConformanceConstraint (pa, proto, superclassSource);
2160
2176
addConditionalRequirements (*this , *conformance);
2161
-
2162
2177
return superclassSource;
2163
2178
}
2164
2179
@@ -2261,19 +2276,8 @@ bool PotentialArchetype::addConformance(ProtocolDecl *proto,
2261
2276
GenericSignatureBuilder &builder) {
2262
2277
// Check whether we already knew about this conformance.
2263
2278
auto equivClass = getOrCreateEquivalenceClass ();
2264
- auto known = equivClass->conformsTo .find (proto);
2265
- if (known != equivClass->conformsTo .end ()) {
2266
- // We already knew about this conformance; record this specific constraint.
2267
- known->second .push_back ({this , proto, source});
2268
- ++NumConformanceConstraints;
2279
+ if (!equivClass->recordConformanceConstraint (this , proto, source))
2269
2280
return false ;
2270
- }
2271
-
2272
- // Add the conformance along with this constraint.
2273
- equivClass->conformsTo [proto].push_back ({this , proto, source});
2274
- equivClass->modified (builder);
2275
- ++NumConformanceConstraints;
2276
- ++NumConformances;
2277
2281
2278
2282
// If there is a concrete type that resolves this conformance requirement,
2279
2283
// record the conformance.
@@ -3913,6 +3917,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
3913
3917
T1->addConformance (entry.first , entry.second .front ().source , *this );
3914
3918
3915
3919
auto &constraints1 = equivClass->conformsTo [entry.first ];
3920
+ // FIXME: Go through recordConformanceConstraint()?
3916
3921
constraints1.insert (constraints1.end (),
3917
3922
entry.second .begin () + 1 ,
3918
3923
entry.second .end ());
0 commit comments