Skip to content

Commit 49ca2d0

Browse files
authored
[CS] A couple of cleanups (swiftlang#31155)
[CS] A couple of cleanups
2 parents b29558d + 6036f88 commit 49ca2d0

File tree

4 files changed

+6
-71
lines changed

4 files changed

+6
-71
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10087,22 +10087,13 @@ void ConstraintSystem::simplifyDisjunctionChoice(Constraint *choice) {
1008710087
case ConstraintSystem::SolutionKind::Error:
1008810088
if (!failedConstraint)
1008910089
failedConstraint = choice;
10090-
if (solverState)
10091-
solverState->retireConstraint(choice);
1009210090
break;
1009310091

1009410092
case ConstraintSystem::SolutionKind::Solved:
10095-
if (solverState)
10096-
solverState->retireConstraint(choice);
1009710093
break;
1009810094

1009910095
case ConstraintSystem::SolutionKind::Unsolved:
10100-
InactiveConstraints.push_back(choice);
10101-
CG.addConstraint(choice);
10096+
addUnsolvedConstraint(choice);
1010210097
break;
1010310098
}
10104-
10105-
// Record this as a generated constraint.
10106-
if (solverState)
10107-
solverState->addGeneratedConstraint(choice);
1010810099
}

lib/Sema/ConstraintGraph.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,8 +1165,8 @@ bool ConstraintGraph::contractEdges() {
11651165
log << "\n";
11661166
}
11671167

1168-
// Merge the edges and remove the constraint.
1169-
removeEdge(constraint);
1168+
// Merge the edges and retire the constraint.
1169+
CS.retireConstraint(constraint);
11701170
if (rep1 != rep2)
11711171
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
11721172
didContractEdges = true;
@@ -1175,35 +1175,6 @@ bool ConstraintGraph::contractEdges() {
11751175
return didContractEdges;
11761176
}
11771177

1178-
void ConstraintGraph::removeEdge(Constraint *constraint) {
1179-
bool isExistingConstraint = false;
1180-
1181-
for (auto &active : CS.ActiveConstraints) {
1182-
if (&active == constraint) {
1183-
CS.ActiveConstraints.erase(constraint);
1184-
isExistingConstraint = true;
1185-
break;
1186-
}
1187-
}
1188-
1189-
for (auto &inactive : CS.InactiveConstraints) {
1190-
if (&inactive == constraint) {
1191-
CS.InactiveConstraints.erase(constraint);
1192-
isExistingConstraint = true;
1193-
break;
1194-
}
1195-
}
1196-
1197-
if (CS.solverState) {
1198-
if (isExistingConstraint)
1199-
CS.solverState->retireConstraint(constraint);
1200-
else
1201-
CS.solverState->removeGeneratedConstraint(constraint);
1202-
}
1203-
1204-
removeConstraint(constraint);
1205-
}
1206-
12071178
void ConstraintGraph::optimize() {
12081179
// Merge equivalence classes until a fixed point is reached.
12091180
while (contractEdges()) {}

lib/Sema/ConstraintGraph.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ class ConstraintGraph {
333333
/// classes until a fixed point is reached.
334334
bool contractEdges();
335335

336-
/// To support edge contraction, remove a constraint from both the constraint
337-
/// graph and its enclosing constraint system.
338-
void removeEdge(Constraint *constraint);
339-
340336
/// The constraint system.
341337
ConstraintSystem &CS;
342338

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,24 +1932,6 @@ class ConstraintSystem {
19321932
generatedConstraints.push_back(constraint);
19331933
}
19341934

1935-
/// Erase given constraint from the list of generated constraints
1936-
/// along the current solver path. Note that this operation doesn't
1937-
/// guarantee any ordering of the after it's application.
1938-
///
1939-
/// \param constraint The constraint to erase.
1940-
void removeGeneratedConstraint(Constraint *constraint) {
1941-
for (auto *&generated : generatedConstraints) {
1942-
// When we find the constraint we're erasing, overwrite its
1943-
// value with the last element in the generated constraints
1944-
// vector and then pop that element from the vector.
1945-
if (generated == constraint) {
1946-
generated = generatedConstraints.back();
1947-
generatedConstraints.pop_back();
1948-
return;
1949-
}
1950-
}
1951-
}
1952-
19531935
/// Register given scope to be tracked by the current solver state,
19541936
/// this helps to make sure that all of the retired/generated constraints
19551937
/// are dealt with correctly when the life time of the scope ends.
@@ -2954,14 +2936,8 @@ class ConstraintSystem {
29542936
/// Add a new constraint that we know fails.
29552937
void addNewFailingConstraint(Constraint *constraint) {
29562938
assert(shouldAddNewFailingConstraint());
2939+
assert(!constraint->isActive());
29572940
failedConstraint = constraint;
2958-
failedConstraint->setActive(false);
2959-
2960-
// Record this as a newly-generated constraint.
2961-
if (solverState) {
2962-
solverState->addGeneratedConstraint(constraint);
2963-
solverState->retireConstraint(constraint);
2964-
}
29652941
}
29662942

29672943
/// Add a newly-generated constraint that is known not to be solvable
@@ -4215,7 +4191,8 @@ class ConstraintSystem {
42154191
/// The set of potential bindings.
42164192
SmallVector<PotentialBinding, 4> Bindings;
42174193

4218-
/// Whether this type variable is fully bound by one of its constraints.
4194+
/// Whether these bindings should be delayed until the rest of the
4195+
/// constraint system is considered "fully bound".
42194196
bool FullyBound = false;
42204197

42214198
/// Whether the bindings of this type involve other type variables.

0 commit comments

Comments
 (0)