Skip to content

Commit 8c60dd0

Browse files
committed
Sema: Remove ConstraintSystem::SolverState::isRecordingChanges()
All but two remaining call sites can be changed to just check for a non-null solverState, because we want to assert if we're inside of an active undo. The two places inside binding inference can check isUndoActive() directly.
1 parent 7060cea commit 8c60dd0

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,10 +2689,6 @@ class ConstraintSystem {
26892689
/// we're exploring.
26902690
SolverState *solverState = nullptr;
26912691

2692-
bool isRecordingChanges() const {
2693-
return solverState && !solverState->Trail.isUndoActive();
2694-
}
2695-
26962692
void recordChange(SolverTrail::Change change) {
26972693
solverState->Trail.recordChange(change);
26982694
}

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ void PotentialBindings::infer(Constraint *constraint) {
17831783
return;
17841784

17851785
// Record the change, if there are active scopes.
1786-
if (CS.isRecordingChanges())
1786+
if (CS.solverState && !CS.solverState->Trail.isUndoActive())
17871787
CS.recordChange(SolverTrail::Change::InferredBindings(TypeVar, constraint));
17881788

17891789
switch (constraint->getKind()) {
@@ -1957,7 +1957,7 @@ void PotentialBindings::retract(Constraint *constraint) {
19571957
return;
19581958

19591959
// Record the change, if there are active scopes.
1960-
if (CS.isRecordingChanges())
1960+
if (CS.solverState && !CS.solverState->Trail.isUndoActive())
19611961
CS.recordChange(SolverTrail::Change::RetractedBindings(TypeVar, constraint));
19621962

19631963
LLVM_DEBUG(

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4930,7 +4930,7 @@ bool ConstraintSystem::generateConstraints(
49304930
// Cache the outer generic environment, if it exists.
49314931
if (target.getPackElementEnv()) {
49324932
PackElementGenericEnvironments.push_back(target.getPackElementEnv());
4933-
ASSERT(!isRecordingChanges() && "Need to record a change");
4933+
ASSERT(!solverState && "Need to record a change");
49344934
}
49354935

49364936
// For a for-each statement, generate constraints for the pattern, where

lib/Sema/ConstraintGraph.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ void ConstraintGraph::addTypeVariable(TypeVariableType *typeVar) {
7777
// Record this type variable.
7878
TypeVariables.push_back(typeVar);
7979

80-
// Record the change, if there are active scopes. Note that we specifically
81-
// check CS.solverState and not CS.isRecordingChanges(), because we want
82-
// recordChange() to assert if there's an active undo. It is not valid to
83-
// create new nodes during an undo.
8480
if (CS.solverState)
8581
CS.recordChange(SolverTrail::Change::AddedTypeVariable(typeVar));
8682
}
@@ -504,7 +500,7 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
504500
auto &repNode = (*this)[typeVar1];
505501

506502
// Record the change, if there are active scopes.
507-
if (CS.isRecordingChanges()) {
503+
if (CS.solverState) {
508504
CS.recordChange(
509505
SolverTrail::Change::ExtendedEquivalenceClass(
510506
typeVar1,
@@ -557,7 +553,7 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
557553
node.addReferencedVar(otherTypeVar);
558554

559555
// Record the change, if there are active scopes.
560-
if (CS.isRecordingChanges())
556+
if (CS.solverState)
561557
CS.recordChange(SolverTrail::Change::RelatedTypeVariables(typeVar, otherTypeVar));
562558
}
563559
}

0 commit comments

Comments
 (0)