Skip to content

Commit 1a18d70

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 24de22a commit 1a18d70

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
@@ -2697,10 +2697,6 @@ class ConstraintSystem {
26972697
/// we're exploring.
26982698
SolverState *solverState = nullptr;
26992699

2700-
bool isRecordingChanges() const {
2701-
return solverState && !solverState->Trail.isUndoActive();
2702-
}
2703-
27042700
void recordChange(SolverTrail::Change change) {
27052701
solverState->Trail.recordChange(change);
27062702
}

lib/Sema/CSBindings.cpp

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

17731773
// Record the change, if there are active scopes.
1774-
if (CS.isRecordingChanges())
1774+
if (CS.solverState && !CS.solverState->Trail.isUndoActive())
17751775
CS.recordChange(SolverTrail::Change::InferredBindings(TypeVar, constraint));
17761776

17771777
switch (constraint->getKind()) {
@@ -1945,7 +1945,7 @@ void PotentialBindings::retract(Constraint *constraint) {
19451945
return;
19461946

19471947
// Record the change, if there are active scopes.
1948-
if (CS.isRecordingChanges())
1948+
if (CS.solverState && !CS.solverState->Trail.isUndoActive())
19491949
CS.recordChange(SolverTrail::Change::RetractedBindings(TypeVar, constraint));
19501950

19511951
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
}
@@ -507,7 +503,7 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
507503
auto &repNode = (*this)[typeVar1];
508504

509505
// Record the change, if there are active scopes.
510-
if (CS.isRecordingChanges()) {
506+
if (CS.solverState) {
511507
CS.recordChange(
512508
SolverTrail::Change::ExtendedEquivalenceClass(
513509
typeVar1,
@@ -560,7 +556,7 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
560556
node.addReferencedVar(otherTypeVar);
561557

562558
// Record the change, if there are active scopes.
563-
if (CS.isRecordingChanges())
559+
if (CS.solverState)
564560
CS.recordChange(SolverTrail::Change::RelatedTypeVariables(typeVar, otherTypeVar));
565561
}
566562
}

0 commit comments

Comments
 (0)