Skip to content

Commit 877c60e

Browse files
committed
Sema: Rename applySolution() to replaySolution()
1 parent 1323953 commit 877c60e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,8 @@ class ConstraintSystem {
29052905
/// This operation is used to take a solution computed based on some
29062906
/// subset of the constraints and then apply it back to the
29072907
/// constraint system for further exploration.
2908-
void applySolution(const Solution &solution);
2908+
void replaySolution(const Solution &solution,
2909+
bool shouldIncreaseScore=true);
29092910

29102911
// FIXME: Perhaps these belong on ConstraintSystem itself.
29112912
friend std::optional<BraceStmt *>

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func, Type builderType) {
10821082
}
10831083

10841084
// FIXME: Shouldn't need to do this.
1085-
cs.applySolution(solutions.front());
1085+
cs.replaySolution(solutions.front());
10861086

10871087
// Apply the solution to the function body.
10881088
if (auto result = cs.applySolution(solutions.front(), target)) {

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ Solution ConstraintSystem::finalize() {
272272
return solution;
273273
}
274274

275-
void ConstraintSystem::applySolution(const Solution &solution) {
276-
// Update the score.
277-
CurrentScore += solution.getFixedScore();
275+
void ConstraintSystem::replaySolution(const Solution &solution,
276+
bool shouldIncreaseScore) {
277+
if (shouldIncreaseScore)
278+
CurrentScore += solution.getFixedScore();
278279

279280
// Assign fixed types to the type variables solved by this solution.
280281
for (auto binding : solution.typeBindings) {

lib/Sema/CSStep.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ bool SplitterStep::mergePartialSolutions() const {
234234
if (!IncludeInMergedResults[i])
235235
continue;
236236

237-
CS.applySolution(PartialSolutions[i][indices[i]]);
237+
CS.replaySolution(PartialSolutions[i][indices[i]]);
238238
}
239239

240240
// This solution might be worse than the best solution found so far.
@@ -328,7 +328,7 @@ StepResult ComponentStep::take(bool prevFailed) {
328328
// If there are any dependent partial solutions to compose, do so now.
329329
if (!DependsOnPartialSolutions.empty()) {
330330
for (auto partial : DependsOnPartialSolutions) {
331-
CS.applySolution(*partial);
331+
CS.replaySolution(*partial);
332332
}
333333

334334
// Activate all of the one-way constraints.
@@ -879,7 +879,8 @@ bool ConjunctionStep::attempt(const ConjunctionElement &element) {
879879
// Note that solution is removed here. This is done
880880
// because we want build a single complete solution
881881
// incrementally.
882-
CS.applySolution(Solutions.pop_back_val());
882+
CS.replaySolution(Solutions.pop_back_val(),
883+
/*shouldIncrementScore=*/false);
883884
}
884885

885886
// Make sure that element is solved in isolation
@@ -1024,9 +1025,10 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
10241025
for (auto &solution : Solutions) {
10251026
ConstraintSystem::SolverScope scope(CS);
10261027

1027-
CS.applySolution(solution);
1028+
CS.replaySolution(solution,
1029+
/*shouldIncrementScore=*/false);
10281030

1029-
// `applySolution` changes best/current scores
1031+
// `replaySolution` changes best/current scores
10301032
// of the constraint system, so they have to be
10311033
// restored right afterwards because score of the
10321034
// element does contribute to the overall score.
@@ -1100,8 +1102,9 @@ void ConjunctionStep::restoreOuterState(const Score &solutionScore) const {
11001102
}
11011103
}
11021104

1103-
void ConjunctionStep::SolverSnapshot::applySolution(const Solution &solution) {
1104-
CS.applySolution(solution);
1105+
void ConjunctionStep::SolverSnapshot::replaySolution(const Solution &solution) {
1106+
CS.replaySolution(solution,
1107+
/*shouldIncreaseScore=*/false);
11051108

11061109
if (!CS.shouldAttemptFixes())
11071110
return;

lib/Sema/CSStep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
865865
IsolationScope = std::make_unique<Scope>(CS);
866866

867867
// Apply solution inferred for the conjunction.
868-
applySolution(solution);
868+
replaySolution(solution);
869869

870870
// Add constraints to the graph after solution
871871
// has been applied to make sure that all type
@@ -901,7 +901,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
901901
CG.addConstraint(&constraint);
902902
}
903903

904-
void applySolution(const Solution &solution);
904+
void replaySolution(const Solution &solution);
905905
};
906906

907907
/// Best solution solver reached so far.

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
461461
// Apply this solution to the constraint system.
462462
// FIXME: This shouldn't be necessary.
463463
auto &solution = (*viable)[0];
464-
cs.applySolution(solution);
464+
cs.replaySolution(solution);
465465

466466
// Apply the solution to the expression.
467467
auto resultTarget = cs.applySolution(solution, target);
@@ -753,7 +753,7 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
753753

754754
auto &solution = (*viable)[0];
755755

756-
cs.applySolution(solution);
756+
cs.replaySolution(solution);
757757

758758
if (auto result = cs.applySolution(solution, defaultExprTarget)) {
759759
// Perform syntactic diagnostics on the type-checked target.

0 commit comments

Comments
 (0)