@@ -763,48 +763,14 @@ static void addKeyPathDynamicMemberOverloads(
763763 }
764764}
765765
766- SolutionCompareResult compareSolutionsForCodeCompletion (
767- ConstraintSystem &cs, ArrayRef<Solution> solutions, unsigned idx1,
768- unsigned idx2) {
769-
770- // When solving for code completion we can't consider one solution worse than
771- // another according to the same rules as regular compilation. For example,
772- // with the code below:
773- //
774- // func foo(_ x: Int) -> Int {}
775- // func foo<T>(_ x: T) -> String {}
776- // foo(3).<complete here> // Still want solutions with for both foo
777- // // overloads - String and Int members are both
778- // // valid here.
779- //
780- // the comparison for regular compilation considers the solution with the more
781- // specialized `foo` overload `foo(_: Int)` to be better than the solution
782- // with the generic overload `foo(_: T)` even though both are otherwise
783- // viable. For code completion purposes offering members of 'String' based
784- // on the solution with the generic overload is equally as import as offering
785- // members of 'Int' as choosing one of those completions will then result in
786- // regular compilation resolving the call to the generic overload instead.
787-
788- if (solutions[idx1].getFixedScore () == solutions[idx2].getFixedScore ())
789- return SolutionCompareResult::Incomparable;
790- return solutions[idx1].getFixedScore () < solutions[idx2].getFixedScore ()
791- ? SolutionCompareResult::Better
792- : SolutionCompareResult::Worse;
793- }
794-
795-
796766SolutionCompareResult ConstraintSystem::compareSolutions (
797767 ConstraintSystem &cs, ArrayRef<Solution> solutions,
798- const SolutionDiff &diff, unsigned idx1, unsigned idx2,
799- bool isForCodeCompletion) {
768+ const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
800769 if (cs.isDebugMode ()) {
801770 llvm::errs ().indent (cs.solverState ->depth * 2 )
802771 << " comparing solutions " << idx1 << " and " << idx2 <<" \n " ;
803772 }
804773
805- if (isForCodeCompletion)
806- return compareSolutionsForCodeCompletion (cs, solutions, idx1, idx2);
807-
808774 // Whether the solutions are identical.
809775 bool identical = true ;
810776
@@ -1340,8 +1306,7 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
13401306 SmallVector<bool , 16 > losers (viable.size (), false );
13411307 unsigned bestIdx = 0 ;
13421308 for (unsigned i = 1 , n = viable.size (); i != n; ++i) {
1343- switch (compareSolutions (*this , viable, diff, i, bestIdx,
1344- isForCodeCompletion ())) {
1309+ switch (compareSolutions (*this , viable, diff, i, bestIdx)) {
13451310 case SolutionCompareResult::Identical:
13461311 // FIXME: Might want to warn about this in debug builds, so we can
13471312 // find a way to eliminate the redundancy in the search space.
@@ -1365,8 +1330,7 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
13651330 if (i == bestIdx)
13661331 continue ;
13671332
1368- switch (compareSolutions (*this , viable, diff, bestIdx, i,
1369- isForCodeCompletion ())) {
1333+ switch (compareSolutions (*this , viable, diff, bestIdx, i)) {
13701334 case SolutionCompareResult::Identical:
13711335 // FIXME: Might want to warn about this in debug builds, so we can
13721336 // find a way to eliminate the redundancy in the search space.
@@ -1418,8 +1382,7 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
14181382 if (losers[j])
14191383 continue ;
14201384
1421- switch (compareSolutions (*this , viable, diff, i, j,
1422- isForCodeCompletion ())) {
1385+ switch (compareSolutions (*this , viable, diff, i, j)) {
14231386 case SolutionCompareResult::Identical:
14241387 // FIXME: Dub one of these the loser arbitrarily?
14251388 break ;
0 commit comments