@@ -1909,21 +1909,6 @@ void ConstraintSystem::partitionForDesignatedTypes(
1909
1909
void ConstraintSystem::partitionDisjunction (
1910
1910
ArrayRef<Constraint *> Choices, SmallVectorImpl<unsigned > &Ordering,
1911
1911
SmallVectorImpl<unsigned > &PartitionBeginning) {
1912
- // Maintain the original ordering, and make a single partition of
1913
- // disjunction choices.
1914
- auto originalOrdering = [&]() {
1915
- for (unsigned long i = 0 , e = Choices.size (); i != e; ++i)
1916
- Ordering.push_back (i);
1917
-
1918
- PartitionBeginning.push_back (0 );
1919
- };
1920
-
1921
- if (!TC.getLangOpts ().SolverEnableOperatorDesignatedTypes ||
1922
- !isOperatorBindOverload (Choices[0 ])) {
1923
- originalOrdering ();
1924
- return ;
1925
- }
1926
-
1927
1912
SmallSet<Constraint *, 16 > taken;
1928
1913
1929
1914
// Local function used to iterate over the untaken choices from the
@@ -1937,33 +1922,45 @@ void ConstraintSystem::partitionDisjunction(
1937
1922
if (taken.count (constraint))
1938
1923
continue ;
1939
1924
1940
- assert (constraint->getKind () == ConstraintKind::BindOverload);
1941
- assert (constraint->getOverloadChoice ().isDecl ());
1942
-
1943
1925
if (fn (index, constraint))
1944
1926
taken.insert (constraint);
1945
1927
}
1946
1928
};
1947
1929
1948
- // First collect some things that we'll generally put near the end
1949
- // of the partitioning.
1930
+ // First collect some things that we'll generally put near the beginning or
1931
+ // end of the partitioning.
1950
1932
1933
+ SmallVector<unsigned , 4 > favored;
1951
1934
SmallVector<unsigned , 4 > disabled;
1952
1935
SmallVector<unsigned , 4 > unavailable;
1953
1936
1954
- // First collect disabled constraints.
1937
+ // First collect disabled and favored constraints.
1955
1938
forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
1956
- if (!constraint->isDisabled ())
1957
- return false ;
1958
- disabled.push_back (index);
1959
- return true ;
1939
+ if (constraint->isDisabled ()) {
1940
+ disabled.push_back (index);
1941
+ return true ;
1942
+ }
1943
+
1944
+ if (constraint->isFavored ()) {
1945
+ favored.push_back (index);
1946
+ return true ;
1947
+ }
1948
+
1949
+ return false ;
1960
1950
});
1961
1951
1962
1952
// Then unavailable constraints if we're skipping them.
1963
1953
if (!shouldAttemptFixes ()) {
1964
1954
forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
1955
+ if (constraint->getKind () != ConstraintKind::BindOverload)
1956
+ return false ;
1957
+ if (!constraint->getOverloadChoice ().isDecl ())
1958
+ return false ;
1959
+
1965
1960
auto *decl = constraint->getOverloadChoice ().getDecl ();
1966
- auto *funcDecl = cast<FuncDecl>(decl);
1961
+ auto *funcDecl = dyn_cast<FuncDecl>(decl);
1962
+ if (!funcDecl)
1963
+ return false ;
1967
1964
1968
1965
if (!funcDecl->getAttrs ().isUnavailable (getASTContext ()))
1969
1966
return false ;
@@ -1983,14 +1980,18 @@ void ConstraintSystem::partitionDisjunction(
1983
1980
}
1984
1981
};
1985
1982
1986
- partitionForDesignatedTypes (Choices, forEachChoice, appendPartition);
1983
+ if (TC.getLangOpts ().SolverEnableOperatorDesignatedTypes &&
1984
+ isOperatorBindOverload (Choices[0 ])) {
1985
+ partitionForDesignatedTypes (Choices, forEachChoice, appendPartition);
1986
+ }
1987
1987
1988
1988
SmallVector<unsigned , 4 > everythingElse;
1989
1989
// Gather the remaining options.
1990
1990
forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
1991
1991
everythingElse.push_back (index);
1992
1992
return true ;
1993
1993
});
1994
+ appendPartition (favored);
1994
1995
appendPartition (everythingElse);
1995
1996
1996
1997
// Now create the remaining partitions from what we previously collected.
0 commit comments