Skip to content

Commit f66a852

Browse files
committed
[ConstraintSystem] Minor refactor to disjunction partitioning.
Change the order of statements but nothing functional.
1 parent 72a425a commit f66a852

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,12 +1702,6 @@ void ConstraintSystem::partitionDisjunction(
17021702
return;
17031703
}
17041704

1705-
SmallVector<unsigned, 4> disabled;
1706-
SmallVector<unsigned, 4> unavailable;
1707-
SmallVector<unsigned, 4> globalScope;
1708-
SmallVector<SmallVector<unsigned, 4>, 4> definedInDesignatedType;
1709-
SmallVector<SmallVector<unsigned, 4>, 4> definedInExtensionOfDesignatedType;
1710-
SmallVector<unsigned, 4> everythingElse;
17111705
SmallSet<Constraint *, 16> taken;
17121706

17131707
// Local function used to iterate over the untaken choices from the
@@ -1729,6 +1723,14 @@ void ConstraintSystem::partitionDisjunction(
17291723
}
17301724
};
17311725

1726+
1727+
// First collect some things that we'll generally put near the end
1728+
// of the partitioning.
1729+
1730+
SmallVector<unsigned, 4> disabled;
1731+
SmallVector<unsigned, 4> unavailable;
1732+
SmallVector<unsigned, 4> globalScope;
1733+
17321734
// First collect disabled constraints.
17331735
forEachChoice(Choices, [&](unsigned index, Constraint *constraint) -> bool {
17341736
if (!constraint->isDisabled())
@@ -1765,6 +1767,19 @@ void ConstraintSystem::partitionDisjunction(
17651767
return true;
17661768
});
17671769

1770+
// Local function to create the next partition based on the options
1771+
// passed in.
1772+
auto appendPartition = [&](SmallVectorImpl<unsigned> &options) {
1773+
if (options.size()) {
1774+
PartitionBeginning.push_back(Ordering.size());
1775+
Ordering.insert(Ordering.end(), options.begin(), options.end());
1776+
}
1777+
};
1778+
1779+
SmallVector<SmallVector<unsigned, 4>, 4> definedInDesignatedType;
1780+
SmallVector<SmallVector<unsigned, 4>, 4> definedInExtensionOfDesignatedType;
1781+
SmallVector<unsigned, 4> everythingElse;
1782+
17681783
// Now collect the overload choices that are defined within the type
17691784
// that was designated in the operator declaration.
17701785
auto designatedNominalTypes = getOperatorDesignatedNominalTypes(Choices[0]);
@@ -1806,25 +1821,8 @@ void ConstraintSystem::partitionDisjunction(
18061821
});
18071822
}
18081823

1809-
// Gather the remaining options.
1810-
forEachChoice(Choices, [&](unsigned index, Constraint *constraint) -> bool {
1811-
everythingElse.push_back(index);
1812-
return true;
1813-
});
1814-
1815-
// Local function to create the next partition based on the options
1816-
// passed in.
1817-
auto appendPartition = [&](SmallVectorImpl<unsigned> &options) {
1818-
if (options.size()) {
1819-
PartitionBeginning.push_back(Ordering.size());
1820-
Ordering.insert(Ordering.end(), options.begin(), options.end());
1821-
}
1822-
};
1823-
1824-
// Now create the partitioning based on what was collected.
1825-
1826-
// First we'll add partitions for each of the overloads we found in
1827-
// types that were designated as part of the operator declaration.
1824+
// Add partitions for each of the overloads we found in types that
1825+
// were designated as part of the operator declaration.
18281826
for (auto designatedTypeIndex : indices(designatedNominalTypes)) {
18291827
if (designatedTypeIndex < definedInDesignatedType.size()) {
18301828
auto &primary = definedInDesignatedType[designatedTypeIndex];
@@ -1835,6 +1833,15 @@ void ConstraintSystem::partitionDisjunction(
18351833
appendPartition(secondary);
18361834
}
18371835
}
1836+
1837+
// Gather the remaining options.
1838+
forEachChoice(Choices, [&](unsigned index, Constraint *constraint) -> bool {
1839+
everythingElse.push_back(index);
1840+
return true;
1841+
});
1842+
1843+
// Now create the remaining partitions from what we previously collected.
1844+
18381845
appendPartition(everythingElse);
18391846
appendPartition(globalScope);
18401847
appendPartition(unavailable);

0 commit comments

Comments
 (0)