[GSB] Use result of recordSameTypeConstraint() to short-circuit.

Centralizes the logic for short-circuiting based on same-type
constraints.
This commit is contained in:
Doug Gregor
2017-10-23 21:51:54 -07:00
parent bd0625f083
commit 642b45835c
2 changed files with 10 additions and 18 deletions

View File

@@ -215,8 +215,7 @@ public:
///
/// \returns true if this same-type constraint merges two equivalence
/// classes, and false otherwise.
bool recordSameTypeConstraint(GenericSignatureBuilder &builder,
PotentialArchetype *type1,
bool recordSameTypeConstraint(PotentialArchetype *type1,
PotentialArchetype *type2,
const RequirementSource *source);

View File

@@ -1642,14 +1642,13 @@ bool EquivalenceClass::recordConformanceConstraint(
}
bool EquivalenceClass::recordSameTypeConstraint(
GenericSignatureBuilder &builder,
PotentialArchetype *type1,
PotentialArchetype *type2,
const RequirementSource *source) {
// FIXME: Drop builder?
sameTypeConstraints.push_back({type1, type2, source});
++NumSameTypeConstraints;
return true;
return type1->getEquivalenceClassIfPresent() !=
type2->getEquivalenceClassIfPresent();
}
template<typename T>
@@ -3977,23 +3976,20 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
PotentialArchetype *OrigT2,
const RequirementSource *Source)
{
// Record the same-type constraint, and bail out if it was already known.
if (!OrigT1->getOrCreateEquivalenceClass(*this)
->recordSameTypeConstraint(OrigT1, OrigT2, Source))
return ConstraintResult::Resolved;
// Operate on the representatives
auto T1 = OrigT1->getRepresentative();
auto T2 = OrigT2->getRepresentative();
// If the representatives are already the same, we're done.
if (T1 == T2) {
T1->getOrCreateEquivalenceClass(*this)
->recordSameTypeConstraint(*this, OrigT1, OrigT2, Source);
return ConstraintResult::Resolved;
}
unsigned nestingDepth1 = T1->getNestingDepth();
unsigned nestingDepth2 = T2->getNestingDepth();
// Decide which potential archetype is to be considered the representative.
// We prefer potential archetypes with lower nesting depths, because it
// prevents us from unnecessarily building deeply nested potential archetypes.
unsigned nestingDepth1 = T1->getNestingDepth();
unsigned nestingDepth2 = T2->getNestingDepth();
if (nestingDepth2 < nestingDepth1) {
std::swap(T1, T2);
std::swap(OrigT1, OrigT2);
@@ -4003,9 +3999,6 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
auto equivClass = T1->getOrCreateEquivalenceClass(*this);
equivClass->modified(*this);
// Record the same-type constraint.
equivClass->recordSameTypeConstraint(*this, OrigT1, OrigT2, Source);
auto equivClass1Members = equivClass->members;
auto equivClass2Members = T2->getEquivalenceClassMembers();
for (auto equiv : equivClass2Members)