@@ -1909,21 +1909,6 @@ void ConstraintSystem::partitionForDesignatedTypes(
19091909void ConstraintSystem::partitionDisjunction (
19101910 ArrayRef<Constraint *> Choices, SmallVectorImpl<unsigned > &Ordering,
19111911 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-
19271912 SmallSet<Constraint *, 16 > taken;
19281913
19291914 // Local function used to iterate over the untaken choices from the
@@ -1937,33 +1922,45 @@ void ConstraintSystem::partitionDisjunction(
19371922 if (taken.count (constraint))
19381923 continue ;
19391924
1940- assert (constraint->getKind () == ConstraintKind::BindOverload);
1941- assert (constraint->getOverloadChoice ().isDecl ());
1942-
19431925 if (fn (index, constraint))
19441926 taken.insert (constraint);
19451927 }
19461928 };
19471929
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.
19501932
1933+ SmallVector<unsigned , 4 > favored;
19511934 SmallVector<unsigned , 4 > disabled;
19521935 SmallVector<unsigned , 4 > unavailable;
19531936
1954- // First collect disabled constraints.
1937+ // First collect disabled and favored constraints.
19551938 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 ;
19601950 });
19611951
19621952 // Then unavailable constraints if we're skipping them.
19631953 if (!shouldAttemptFixes ()) {
19641954 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+
19651960 auto *decl = constraint->getOverloadChoice ().getDecl ();
1966- auto *funcDecl = cast<FuncDecl>(decl);
1961+ auto *funcDecl = dyn_cast<FuncDecl>(decl);
1962+ if (!funcDecl)
1963+ return false ;
19671964
19681965 if (!funcDecl->getAttrs ().isUnavailable (getASTContext ()))
19691966 return false ;
@@ -1983,14 +1980,18 @@ void ConstraintSystem::partitionDisjunction(
19831980 }
19841981 };
19851982
1986- partitionForDesignatedTypes (Choices, forEachChoice, appendPartition);
1983+ if (TC.getLangOpts ().SolverEnableOperatorDesignatedTypes &&
1984+ isOperatorBindOverload (Choices[0 ])) {
1985+ partitionForDesignatedTypes (Choices, forEachChoice, appendPartition);
1986+ }
19871987
19881988 SmallVector<unsigned , 4 > everythingElse;
19891989 // Gather the remaining options.
19901990 forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
19911991 everythingElse.push_back (index);
19921992 return true ;
19931993 });
1994+ appendPartition (favored);
19941995 appendPartition (everythingElse);
19951996
19961997 // Now create the remaining partitions from what we previously collected.
0 commit comments