@@ -1683,6 +1683,69 @@ getOperatorDesignatedNominalTypes(Constraint *bindOverload) {
1683
1683
return operatorDecl->getDesignatedNominalTypes ();
1684
1684
}
1685
1685
1686
+ void ConstraintSystem::partitionForDesignatedTypes (
1687
+ ArrayRef<Constraint *> Choices, ConstraintMatchLoop forEachChoice,
1688
+ PartitionAppendCallback appendPartition,
1689
+ SmallVectorImpl<SmallVector<unsigned , 4 >> &definedInDesignatedType,
1690
+ SmallVectorImpl<SmallVector<unsigned , 4 >>
1691
+ &definedInExtensionOfDesignatedType) {
1692
+
1693
+ auto designatedNominalTypes = getOperatorDesignatedNominalTypes (Choices[0 ]);
1694
+ if (designatedNominalTypes.empty ())
1695
+ return ;
1696
+
1697
+ forEachChoice (
1698
+ Choices, [&](unsigned constraintIndex, Constraint *constraint) -> bool {
1699
+ auto *decl = constraint->getOverloadChoice ().getDecl ();
1700
+ auto *funcDecl = cast<FuncDecl>(decl);
1701
+
1702
+ auto *parentDecl = funcDecl->getParent ()->getAsDecl ();
1703
+ for (auto designatedTypeIndex : indices (designatedNominalTypes)) {
1704
+ auto *designatedNominal =
1705
+ designatedNominalTypes[designatedTypeIndex];
1706
+ if (parentDecl == designatedNominal) {
1707
+ if (designatedTypeIndex >= definedInDesignatedType.size ())
1708
+ definedInDesignatedType.resize (designatedTypeIndex + 1 );
1709
+ auto &constraints = definedInDesignatedType[designatedTypeIndex];
1710
+ constraints.push_back (constraintIndex);
1711
+ return true ;
1712
+ }
1713
+
1714
+ if (auto *extensionDecl = dyn_cast<ExtensionDecl>(parentDecl)) {
1715
+ parentDecl = extensionDecl->getExtendedNominal ();
1716
+ if (parentDecl == designatedNominal) {
1717
+ if (designatedTypeIndex >=
1718
+ definedInExtensionOfDesignatedType.size ())
1719
+ definedInExtensionOfDesignatedType.resize (
1720
+ designatedTypeIndex + 1 );
1721
+
1722
+ auto &constraints =
1723
+ definedInExtensionOfDesignatedType[designatedTypeIndex];
1724
+ constraints.push_back (constraintIndex);
1725
+ return true ;
1726
+ }
1727
+ }
1728
+ }
1729
+
1730
+ return false ;
1731
+ });
1732
+
1733
+ // Now collect the overload choices that are defined within the type
1734
+ // that was designated in the operator declaration.
1735
+ // Add partitions for each of the overloads we found in types that
1736
+ // were designated as part of the operator declaration.
1737
+ for (auto designatedTypeIndex : indices (designatedNominalTypes)) {
1738
+ if (designatedTypeIndex < definedInDesignatedType.size ()) {
1739
+ auto &primary = definedInDesignatedType[designatedTypeIndex];
1740
+ appendPartition (primary);
1741
+ }
1742
+ if (designatedTypeIndex < definedInExtensionOfDesignatedType.size ()) {
1743
+ auto &secondary = definedInExtensionOfDesignatedType[designatedTypeIndex];
1744
+ appendPartition (secondary);
1745
+ }
1746
+ }
1747
+ }
1748
+
1686
1749
void ConstraintSystem::partitionDisjunction (
1687
1750
ArrayRef<Constraint *> Choices, SmallVectorImpl<unsigned > &Ordering,
1688
1751
SmallVectorImpl<unsigned > &PartitionBeginning) {
@@ -1707,9 +1770,9 @@ void ConstraintSystem::partitionDisjunction(
1707
1770
// Local function used to iterate over the untaken choices from the
1708
1771
// disjunction and use a higher-order function to determine if they
1709
1772
// should be part of a partition.
1710
- auto forEachChoice =
1773
+ ConstraintMatchLoop forEachChoice =
1711
1774
[&](ArrayRef<Constraint *>,
1712
- llvm::function_ref <bool (unsigned index, Constraint *)> fn) {
1775
+ std::function <bool (unsigned index, Constraint *)> fn) {
1713
1776
for (auto index : indices (Choices)) {
1714
1777
auto *constraint = Choices[index];
1715
1778
if (taken.count (constraint))
@@ -1723,7 +1786,6 @@ void ConstraintSystem::partitionDisjunction(
1723
1786
}
1724
1787
};
1725
1788
1726
-
1727
1789
// First collect some things that we'll generally put near the end
1728
1790
// of the partitioning.
1729
1791
@@ -1769,80 +1831,30 @@ void ConstraintSystem::partitionDisjunction(
1769
1831
1770
1832
// Local function to create the next partition based on the options
1771
1833
// 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
- };
1834
+ PartitionAppendCallback appendPartition =
1835
+ [&](SmallVectorImpl<unsigned > &options) {
1836
+ if (options.size ()) {
1837
+ PartitionBeginning.push_back (Ordering.size ());
1838
+ Ordering.insert (Ordering.end (), options.begin (), options.end ());
1839
+ }
1840
+ };
1778
1841
1779
1842
SmallVector<SmallVector<unsigned , 4 >, 4 > definedInDesignatedType;
1780
1843
SmallVector<SmallVector<unsigned , 4 >, 4 > definedInExtensionOfDesignatedType;
1781
- SmallVector<unsigned , 4 > everythingElse;
1782
-
1783
- // Now collect the overload choices that are defined within the type
1784
- // that was designated in the operator declaration.
1785
- auto designatedNominalTypes = getOperatorDesignatedNominalTypes (Choices[0 ]);
1786
- if (!designatedNominalTypes.empty ()) {
1787
- forEachChoice (
1788
- Choices, [&](unsigned constraintIndex, Constraint *constraint) -> bool {
1789
- auto *decl = constraint->getOverloadChoice ().getDecl ();
1790
- auto *funcDecl = cast<FuncDecl>(decl);
1791
-
1792
- auto *parentDecl = funcDecl->getParent ()->getAsDecl ();
1793
- for (auto designatedTypeIndex : indices (designatedNominalTypes)) {
1794
- auto *designatedNominal =
1795
- designatedNominalTypes[designatedTypeIndex];
1796
- if (parentDecl == designatedNominal) {
1797
- if (designatedTypeIndex >= definedInDesignatedType.size ())
1798
- definedInDesignatedType.resize (designatedTypeIndex + 1 );
1799
- auto &constraints = definedInDesignatedType[designatedTypeIndex];
1800
- constraints.push_back (constraintIndex);
1801
- return true ;
1802
- }
1803
-
1804
- if (auto *extensionDecl = dyn_cast<ExtensionDecl>(parentDecl)) {
1805
- parentDecl = extensionDecl->getExtendedNominal ();
1806
- if (parentDecl == designatedNominal) {
1807
- if (designatedTypeIndex >=
1808
- definedInExtensionOfDesignatedType.size ())
1809
- definedInExtensionOfDesignatedType.resize (
1810
- designatedTypeIndex + 1 );
1811
-
1812
- auto &constraints =
1813
- definedInExtensionOfDesignatedType[designatedTypeIndex];
1814
- constraints.push_back (constraintIndex);
1815
- return true ;
1816
- }
1817
- }
1818
- }
1819
-
1820
- return false ;
1821
- });
1822
- }
1823
1844
1824
- // Add partitions for each of the overloads we found in types that
1825
- // were designated as part of the operator declaration.
1826
- for (auto designatedTypeIndex : indices (designatedNominalTypes)) {
1827
- if (designatedTypeIndex < definedInDesignatedType.size ()) {
1828
- auto &primary = definedInDesignatedType[designatedTypeIndex];
1829
- appendPartition (primary);
1830
- }
1831
- if (designatedTypeIndex < definedInExtensionOfDesignatedType.size ()) {
1832
- auto &secondary = definedInExtensionOfDesignatedType[designatedTypeIndex];
1833
- appendPartition (secondary);
1834
- }
1835
- }
1845
+ partitionForDesignatedTypes (Choices, forEachChoice, appendPartition,
1846
+ definedInDesignatedType,
1847
+ definedInExtensionOfDesignatedType);
1836
1848
1849
+ SmallVector<unsigned , 4 > everythingElse;
1837
1850
// Gather the remaining options.
1838
1851
forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
1839
1852
everythingElse.push_back (index);
1840
1853
return true ;
1841
1854
});
1855
+ appendPartition (everythingElse);
1842
1856
1843
1857
// Now create the remaining partitions from what we previously collected.
1844
-
1845
- appendPartition (everythingElse);
1846
1858
appendPartition (globalScope);
1847
1859
appendPartition (unavailable);
1848
1860
appendPartition (disabled);
0 commit comments