Skip to content

[CS] A couple of cleanups #31155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10080,22 +10080,13 @@ void ConstraintSystem::simplifyDisjunctionChoice(Constraint *choice) {
case ConstraintSystem::SolutionKind::Error:
if (!failedConstraint)
failedConstraint = choice;
if (solverState)
solverState->retireConstraint(choice);
break;

case ConstraintSystem::SolutionKind::Solved:
if (solverState)
solverState->retireConstraint(choice);
break;

case ConstraintSystem::SolutionKind::Unsolved:
InactiveConstraints.push_back(choice);
CG.addConstraint(choice);
addUnsolvedConstraint(choice);
break;
}

// Record this as a generated constraint.
if (solverState)
solverState->addGeneratedConstraint(choice);
}
33 changes: 2 additions & 31 deletions lib/Sema/ConstraintGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,8 +1165,8 @@ bool ConstraintGraph::contractEdges() {
log << "\n";
}

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

void ConstraintGraph::removeEdge(Constraint *constraint) {
bool isExistingConstraint = false;

for (auto &active : CS.ActiveConstraints) {
if (&active == constraint) {
CS.ActiveConstraints.erase(constraint);
isExistingConstraint = true;
break;
}
}

for (auto &inactive : CS.InactiveConstraints) {
if (&inactive == constraint) {
CS.InactiveConstraints.erase(constraint);
isExistingConstraint = true;
break;
}
}

if (CS.solverState) {
if (isExistingConstraint)
CS.solverState->retireConstraint(constraint);
else
CS.solverState->removeGeneratedConstraint(constraint);
}

removeConstraint(constraint);
}

void ConstraintGraph::optimize() {
// Merge equivalence classes until a fixed point is reached.
while (contractEdges()) {}
Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/ConstraintGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@ class ConstraintGraph {
/// classes until a fixed point is reached.
bool contractEdges();

/// To support edge contraction, remove a constraint from both the constraint
/// graph and its enclosing constraint system.
void removeEdge(Constraint *constraint);

/// The constraint system.
ConstraintSystem &CS;

Expand Down
29 changes: 3 additions & 26 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1928,24 +1928,6 @@ class ConstraintSystem {
generatedConstraints.push_back(constraint);
}

/// Erase given constraint from the list of generated constraints
/// along the current solver path. Note that this operation doesn't
/// guarantee any ordering of the after it's application.
///
/// \param constraint The constraint to erase.
void removeGeneratedConstraint(Constraint *constraint) {
for (auto *&generated : generatedConstraints) {
// When we find the constraint we're erasing, overwrite its
// value with the last element in the generated constraints
// vector and then pop that element from the vector.
if (generated == constraint) {
generated = generatedConstraints.back();
generatedConstraints.pop_back();
return;
}
}
}

/// Register given scope to be tracked by the current solver state,
/// this helps to make sure that all of the retired/generated constraints
/// are dealt with correctly when the life time of the scope ends.
Expand Down Expand Up @@ -2950,14 +2932,8 @@ class ConstraintSystem {
/// Add a new constraint that we know fails.
void addNewFailingConstraint(Constraint *constraint) {
assert(shouldAddNewFailingConstraint());
assert(!constraint->isActive());
failedConstraint = constraint;
failedConstraint->setActive(false);

// Record this as a newly-generated constraint.
if (solverState) {
solverState->addGeneratedConstraint(constraint);
solverState->retireConstraint(constraint);
}
}

/// Add a newly-generated constraint that is known not to be solvable
Expand Down Expand Up @@ -4211,7 +4187,8 @@ class ConstraintSystem {
/// The set of potential bindings.
SmallVector<PotentialBinding, 4> Bindings;

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

/// Whether the bindings of this type involve other type variables.
Expand Down