@@ -942,13 +942,10 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
942
942
// and scoring information.
943
943
Snapshot.reset ();
944
944
945
- // Restore original scores of outer context before
946
- // trying to produce a combined solution.
947
- restoreOriginalScores ();
948
-
949
945
// Apply all of the information deduced from the
950
946
// conjunction (up to the point of ambiguity)
951
947
// back to the outer context and form a joined solution.
948
+ unsigned numSolutions = 0 ;
952
949
for (auto &solution : Solutions) {
953
950
ConstraintSystem::SolverScope scope (CS);
954
951
@@ -958,34 +955,47 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
958
955
// of the constraint system, so they have to be
959
956
// restored right afterwards because score of the
960
957
// element does contribute to the overall score.
961
- restoreOriginalScores ();
958
+ restoreBestScore ();
959
+ restoreCurrentScore (solution.getFixedScore ());
962
960
963
961
// Transform all of the unbound outer variables into
964
962
// placeholders since we are not going to solve for
965
963
// 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
+ }
970
972
}
973
+ CS.increaseScore (SK_Hole, numHoles);
971
974
}
972
975
976
+ if (CS.worseThanBestSolution ())
977
+ continue ;
978
+
973
979
// Note that `worseThanBestSolution` isn't checked
974
980
// here because `Solutions` were pre-filtered, and
975
981
// outer score is the same for all of them.
976
982
OuterSolutions.push_back (CS.finalize ());
983
+ ++numSolutions;
977
984
}
978
985
979
- return done (/* isSuccess=*/ true );
986
+ return done (/* isSuccess=*/ numSolutions > 0 );
980
987
}
981
988
989
+ auto solution = Solutions.pop_back_val ();
990
+ auto score = solution.getFixedScore ();
991
+
982
992
// Restore outer type variables and prepare to solve
983
993
// constraints associated with outer context together
984
994
// with information deduced from the conjunction.
985
- Snapshot->setupOuterContext (Solutions. pop_back_val ( ));
995
+ Snapshot->setupOuterContext (std::move (solution ));
986
996
987
997
// Pretend that conjunction never happened.
988
- restoreOuterState ();
998
+ restoreOuterState (score );
989
999
990
1000
// Now that all of the information from the conjunction has
991
1001
// been applied, let's attempt to solve the outer scope.
@@ -997,10 +1007,11 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
997
1007
return take (prevFailed);
998
1008
}
999
1009
1000
- void ConjunctionStep::restoreOuterState () const {
1010
+ void ConjunctionStep::restoreOuterState (const Score &solutionScore ) const {
1001
1011
// Restore best/current score, since upcoming step is going to
1002
1012
// work with outer scope in relation to the conjunction.
1003
- restoreOriginalScores ();
1013
+ restoreBestScore ();
1014
+ restoreCurrentScore (solutionScore);
1004
1015
1005
1016
// Active all of the previously out-of-scope constraints
1006
1017
// because conjunction can propagate type information up
0 commit comments