@@ -942,13 +942,10 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
942942 // and scoring information.
943943 Snapshot.reset ();
944944
945- // Restore original scores of outer context before
946- // trying to produce a combined solution.
947- restoreOriginalScores ();
948-
949945 // Apply all of the information deduced from the
950946 // conjunction (up to the point of ambiguity)
951947 // back to the outer context and form a joined solution.
948+ unsigned numSolutions = 0 ;
952949 for (auto &solution : Solutions) {
953950 ConstraintSystem::SolverScope scope (CS);
954951
@@ -958,34 +955,47 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
958955 // of the constraint system, so they have to be
959956 // restored right afterwards because score of the
960957 // element does contribute to the overall score.
961- restoreOriginalScores ();
958+ restoreBestScore ();
959+ restoreCurrentScore (solution.getFixedScore ());
962960
963961 // Transform all of the unbound outer variables into
964962 // placeholders since we are not going to solve for
965963 // each ambguous solution.
966- for (auto *typeVar : CS.getTypeVariables ()) {
967- if (!typeVar->getImpl ().hasRepresentativeOrFixed ()) {
968- CS.assignFixedType (
969- typeVar, PlaceholderType::get (CS.getASTContext (), typeVar));
964+ {
965+ unsigned numHoles = 0 ;
966+ for (auto *typeVar : CS.getTypeVariables ()) {
967+ if (!typeVar->getImpl ().hasRepresentativeOrFixed ()) {
968+ CS.assignFixedType (
969+ typeVar, PlaceholderType::get (CS.getASTContext (), typeVar));
970+ ++numHoles;
971+ }
970972 }
973+ CS.increaseScore (SK_Hole, numHoles);
971974 }
972975
976+ if (CS.worseThanBestSolution ())
977+ continue ;
978+
973979 // Note that `worseThanBestSolution` isn't checked
974980 // here because `Solutions` were pre-filtered, and
975981 // outer score is the same for all of them.
976982 OuterSolutions.push_back (CS.finalize ());
983+ ++numSolutions;
977984 }
978985
979- return done (/* isSuccess=*/ true );
986+ return done (/* isSuccess=*/ numSolutions > 0 );
980987 }
981988
989+ auto solution = Solutions.pop_back_val ();
990+ auto score = solution.getFixedScore ();
991+
982992 // Restore outer type variables and prepare to solve
983993 // constraints associated with outer context together
984994 // with information deduced from the conjunction.
985- Snapshot->setupOuterContext (Solutions. pop_back_val ( ));
995+ Snapshot->setupOuterContext (std::move (solution ));
986996
987997 // Pretend that conjunction never happened.
988- restoreOuterState ();
998+ restoreOuterState (score );
989999
9901000 // Now that all of the information from the conjunction has
9911001 // been applied, let's attempt to solve the outer scope.
@@ -997,10 +1007,11 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
9971007 return take (prevFailed);
9981008}
9991009
1000- void ConjunctionStep::restoreOuterState () const {
1010+ void ConjunctionStep::restoreOuterState (const Score &solutionScore ) const {
10011011 // Restore best/current score, since upcoming step is going to
10021012 // work with outer scope in relation to the conjunction.
1003- restoreOriginalScores ();
1013+ restoreBestScore ();
1014+ restoreCurrentScore (solutionScore);
10041015
10051016 // Active all of the previously out-of-scope constraints
10061017 // because conjunction can propagate type information up
0 commit comments