@@ -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,24 +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 ());
960+
961+ // Transform all of the unbound outer variables into
962+ // placeholders since we are not going to solve for
963+ // each ambguous solution.
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+ }
972+ }
973+ CS.increaseScore (SK_Hole, numHoles);
974+ }
975+
976+ if (CS.worseThanBestSolution ())
977+ continue ;
962978
963979 // Note that `worseThanBestSolution` isn't checked
964980 // here because `Solutions` were pre-filtered, and
965981 // outer score is the same for all of them.
966982 OuterSolutions.push_back (CS.finalize ());
983+ ++numSolutions;
967984 }
968985
969- return done (/* isSuccess=*/ true );
986+ return done (/* isSuccess=*/ numSolutions > 0 );
970987 }
971988
989+ auto solution = Solutions.pop_back_val ();
990+ auto score = solution.getFixedScore ();
991+
972992 // Restore outer type variables and prepare to solve
973993 // constraints associated with outer context together
974994 // with information deduced from the conjunction.
975- Snapshot->setupOuterContext (Solutions. pop_back_val ( ));
995+ Snapshot->setupOuterContext (std::move (solution ));
976996
977997 // Pretend that conjunction never happened.
978- restoreOuterState ();
998+ restoreOuterState (score );
979999
9801000 // Now that all of the information from the conjunction has
9811001 // been applied, let's attempt to solve the outer scope.
@@ -987,10 +1007,11 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
9871007 return take (prevFailed);
9881008}
9891009
990- void ConjunctionStep::restoreOuterState () const {
1010+ void ConjunctionStep::restoreOuterState (const Score &solutionScore ) const {
9911011 // Restore best/current score, since upcoming step is going to
9921012 // work with outer scope in relation to the conjunction.
993- restoreOriginalScores ();
1013+ restoreBestScore ();
1014+ restoreCurrentScore (solutionScore);
9941015
9951016 // Active all of the previously out-of-scope constraints
9961017 // because conjunction can propagate type information up
0 commit comments