mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Constraint graph] Handle orphaned constraints within connected components
Move the logic for creating connected components of orphaned constraints into the connected-components algorithm code, rather than making it a special part of SplitterStep.
This commit is contained in:
@@ -97,32 +97,13 @@ void SplitterStep::computeFollowupSteps(
|
||||
|
||||
// Compute the connected components of the constraint graph.
|
||||
auto components = CG.computeConnectedComponents(CS.TypeVariables);
|
||||
unsigned numComponents =
|
||||
components.size() + CG.getOrphanedConstraints().size();
|
||||
unsigned numComponents = components.size();
|
||||
if (numComponents < 2) {
|
||||
componentSteps.push_back(llvm::make_unique<ComponentStep>(
|
||||
CS, 0, &CS.InactiveConstraints, Solutions));
|
||||
return;
|
||||
}
|
||||
|
||||
Components.resize(numComponents);
|
||||
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
|
||||
new SmallVector<Solution, 4>[numComponents]);
|
||||
|
||||
// Add components.
|
||||
for (unsigned i : indices(components)) {
|
||||
componentSteps.push_back(llvm::make_unique<ComponentStep>(
|
||||
CS, i, &Components[i], std::move(components[i]), PartialSolutions[i]));
|
||||
}
|
||||
|
||||
// Add components for the orphaned constraints.
|
||||
OrphanedConstraints = CG.takeOrphanedConstraints();
|
||||
for (unsigned i : range(components.size(), numComponents)) {
|
||||
auto orphaned = OrphanedConstraints[i - components.size()];
|
||||
componentSteps.push_back(llvm::make_unique<ComponentStep>(
|
||||
CS, i, &Components[i], orphaned, PartialSolutions[i]));
|
||||
}
|
||||
|
||||
if (isDebugMode()) {
|
||||
auto &log = getDebugLogger();
|
||||
// Verify that the constraint graph is valid.
|
||||
@@ -135,6 +116,19 @@ void SplitterStep::computeFollowupSteps(
|
||||
CG.printConnectedComponents(CS.TypeVariables, log);
|
||||
}
|
||||
|
||||
// Take the orphaned constraints, because they'll go into a component now.
|
||||
OrphanedConstraints = CG.takeOrphanedConstraints();
|
||||
|
||||
Components.resize(numComponents);
|
||||
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
|
||||
new SmallVector<Solution, 4>[numComponents]);
|
||||
|
||||
// Add components.
|
||||
for (unsigned i : indices(components)) {
|
||||
componentSteps.push_back(llvm::make_unique<ComponentStep>(
|
||||
CS, i, &Components[i], std::move(components[i]), PartialSolutions[i]));
|
||||
}
|
||||
|
||||
// Create component ordering based on the information associated
|
||||
// with constraints in each step - e.g. number of disjunctions,
|
||||
// since components are going to be executed in LIFO order, we'd
|
||||
|
||||
Reference in New Issue
Block a user