Skip to content

Commit 5cfa61c

Browse files
committed
[ConstraintSystem] Address review feedback from @xedin.
1 parent f6710a5 commit 5cfa61c

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,41 +1685,40 @@ getOperatorDesignatedNominalTypes(Constraint *bindOverload) {
16851685

16861686
void ConstraintSystem::partitionForDesignatedTypes(
16871687
ArrayRef<Constraint *> Choices, ConstraintMatchLoop forEachChoice,
1688-
PartitionAppendCallback appendPartition,
1689-
SmallVectorImpl<SmallVector<unsigned, 4>> &definedInDesignatedType,
1690-
SmallVectorImpl<SmallVector<unsigned, 4>>
1691-
&definedInExtensionOfDesignatedType) {
1688+
PartitionAppendCallback appendPartition) {
16921689

16931690
auto designatedNominalTypes = getOperatorDesignatedNominalTypes(Choices[0]);
16941691
if (designatedNominalTypes.empty())
16951692
return;
16961693

1694+
SmallVector<SmallVector<unsigned, 4>, 4> definedInDesignatedType;
1695+
SmallVector<SmallVector<unsigned, 4>, 4> definedInExtensionOfDesignatedType;
1696+
16971697
auto examineConstraint =
16981698
[&](unsigned constraintIndex, Constraint *constraint) -> bool {
16991699
auto *decl = constraint->getOverloadChoice().getDecl();
17001700
auto *funcDecl = cast<FuncDecl>(decl);
17011701

1702-
auto *parentDecl = funcDecl->getParent()->getAsDecl();
1702+
auto *parentDC = funcDecl->getParent();
1703+
auto *parentDecl = parentDC->getAsDecl();
1704+
1705+
if (parentDC->isExtensionContext())
1706+
parentDecl = cast<ExtensionDecl>(parentDecl)->getExtendedNominal();
1707+
17031708
for (auto designatedTypeIndex : indices(designatedNominalTypes)) {
17041709
auto *designatedNominal =
17051710
designatedNominalTypes[designatedTypeIndex];
17061711

1707-
if (parentDecl == designatedNominal) {
1708-
auto &constraints = definedInDesignatedType[designatedTypeIndex];
1709-
constraints.push_back(constraintIndex);
1710-
return true;
1711-
}
1712-
1713-
auto *extensionDecl = dyn_cast<ExtensionDecl>(parentDecl);
1714-
if (!extensionDecl)
1712+
if (parentDecl != designatedNominal)
17151713
continue;
17161714

1717-
if (extensionDecl->getExtendedNominal() == designatedNominal) {
1718-
auto &constraints =
1719-
definedInExtensionOfDesignatedType[designatedTypeIndex];
1720-
constraints.push_back(constraintIndex);
1721-
return true;
1722-
}
1715+
auto &constraints =
1716+
parentDC->isExtensionContext()
1717+
? definedInExtensionOfDesignatedType[designatedTypeIndex]
1718+
: definedInDesignatedType[designatedTypeIndex];
1719+
1720+
constraints.push_back(constraintIndex);
1721+
return true;
17231722
}
17241723

17251724
return false;
@@ -1839,12 +1838,7 @@ void ConstraintSystem::partitionDisjunction(
18391838
}
18401839
};
18411840

1842-
SmallVector<SmallVector<unsigned, 4>, 4> definedInDesignatedType;
1843-
SmallVector<SmallVector<unsigned, 4>, 4> definedInExtensionOfDesignatedType;
1844-
1845-
partitionForDesignatedTypes(Choices, forEachChoice, appendPartition,
1846-
definedInDesignatedType,
1847-
definedInExtensionOfDesignatedType);
1841+
partitionForDesignatedTypes(Choices, forEachChoice, appendPartition);
18481842

18491843
SmallVector<unsigned, 4> everythingElse;
18501844
// Gather the remaining options.

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,12 +3230,9 @@ class ConstraintSystem {
32303230
// Partition the choices in a disjunction based on those that match
32313231
// the designated types for the operator that the disjunction was
32323232
// formed for.
3233-
void partitionForDesignatedTypes(
3234-
ArrayRef<Constraint *> Choices, ConstraintMatchLoop forEachChoice,
3235-
PartitionAppendCallback appendPartition,
3236-
SmallVectorImpl<SmallVector<unsigned, 4>> &definedInDesignatedType,
3237-
SmallVectorImpl<SmallVector<unsigned, 4>>
3238-
&definedInExtensionOfDesignatedType);
3233+
void partitionForDesignatedTypes(ArrayRef<Constraint *> Choices,
3234+
ConstraintMatchLoop forEachChoice,
3235+
PartitionAppendCallback appendPartition);
32393236

32403237
// Partition the choices in the disjunction into groups that we will
32413238
// iterate over in an order appropriate to attempt to stop before we

0 commit comments

Comments
 (0)