Skip to content

Commit 9fb6d92

Browse files
slavapestovxedin
authored andcommitted
Sema: Remove DependentComponentSplitterStep
1 parent dd3e49c commit 9fb6d92

File tree

4 files changed

+6
-183
lines changed

4 files changed

+6
-183
lines changed

include/swift/Sema/ConstraintGraph.h

-11
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,6 @@ class ConstraintGraph {
332332
/// The constraints in this component.
333333
TinyPtrVector<Constraint *> constraints;
334334

335-
/// The set of components that this component depends on, such that
336-
/// the partial solutions of the those components need to be available
337-
/// before this component can be solved.
338-
///
339-
SmallVector<unsigned, 2> dependencies;
340-
341335
public:
342336
Component(unsigned solutionIndex) : solutionIndex(solutionIndex) { }
343337

@@ -353,11 +347,6 @@ class ConstraintGraph {
353347
return constraints;
354348
}
355349

356-
/// Records a component which this component depends on.
357-
void recordDependency(const Component &component);
358-
359-
ArrayRef<unsigned> getDependencies() const { return dependencies; }
360-
361350
unsigned getNumDisjunctions() const { return numDisjunctions; }
362351
};
363352

lib/Sema/CSStep.cpp

+5-89
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ void SplitterStep::computeFollowupSteps(
120120
// Take the orphaned constraints, because they'll go into a component now.
121121
OrphanedConstraints = CG.takeOrphanedConstraints();
122122

123-
IncludeInMergedResults.resize(numComponents, true);
124123
Components.resize(numComponents);
125124
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
126125
new SmallVector<Solution, 4>[numComponents]);
@@ -129,26 +128,9 @@ void SplitterStep::computeFollowupSteps(
129128
for (unsigned i : indices(components)) {
130129
unsigned solutionIndex = components[i].solutionIndex;
131130

132-
// If there are no dependencies, build a normal component step.
133-
if (components[i].getDependencies().empty()) {
134-
steps.push_back(std::make_unique<ComponentStep>(
135-
CS, solutionIndex, &Components[i], std::move(components[i]),
136-
PartialSolutions[solutionIndex]));
137-
continue;
138-
}
139-
140-
// Note that the partial results from any dependencies of this component
141-
// need not be included in the final merged results, because they'll
142-
// already be part of the partial results for this component.
143-
for (auto dependsOn : components[i].getDependencies()) {
144-
IncludeInMergedResults[dependsOn] = false;
145-
}
146-
147-
// Otherwise, build a dependent component "splitter" step, which
148-
// handles all combinations of incoming partial solutions.
149-
steps.push_back(std::make_unique<DependentComponentSplitterStep>(
150-
CS, &Components[i], solutionIndex, std::move(components[i]),
151-
llvm::MutableArrayRef(PartialSolutions.get(), numComponents)));
131+
steps.push_back(std::make_unique<ComponentStep>(
132+
CS, solutionIndex, &Components[i], std::move(components[i]),
133+
PartialSolutions[solutionIndex]));
152134
}
153135

154136
assert(CS.InactiveConstraints.empty() && "Missed a constraint");
@@ -217,8 +199,7 @@ bool SplitterStep::mergePartialSolutions() const {
217199
SmallVector<unsigned, 2> countsVec;
218200
countsVec.reserve(numComponents);
219201
for (unsigned idx : range(numComponents)) {
220-
countsVec.push_back(
221-
IncludeInMergedResults[idx] ? PartialSolutions[idx].size() : 1);
202+
countsVec.push_back(PartialSolutions[idx].size());
222203
}
223204

224205
// Produce all combinations of partial solutions.
@@ -231,9 +212,6 @@ bool SplitterStep::mergePartialSolutions() const {
231212
// solutions.
232213
ConstraintSystem::SolverScope scope(CS);
233214
for (unsigned i : range(numComponents)) {
234-
if (!IncludeInMergedResults[i])
235-
continue;
236-
237215
CS.replaySolution(PartialSolutions[i][indices[i]]);
238216
}
239217

@@ -265,77 +243,15 @@ bool SplitterStep::mergePartialSolutions() const {
265243
return anySolutions;
266244
}
267245

268-
StepResult DependentComponentSplitterStep::take(bool prevFailed) {
269-
// "split" is considered a failure if previous step failed,
270-
// or there is a failure recorded by constraint system, or
271-
// system can't be simplified.
272-
if (prevFailed || CS.getFailedConstraint() || CS.simplify())
273-
return done(/*isSuccess=*/false);
274-
275-
// Figure out the sets of partial solutions that this component depends on.
276-
SmallVector<const SmallVector<Solution, 4> *, 2> dependsOnSets;
277-
for (auto index : Component.getDependencies()) {
278-
dependsOnSets.push_back(&AllPartialSolutions[index]);
279-
}
280-
281-
// Produce all combinations of partial solutions for the inputs.
282-
SmallVector<std::unique_ptr<SolverStep>, 4> followup;
283-
SmallVector<unsigned, 2> indices(Component.getDependencies().size(), 0);
284-
auto dependsOnSetsRef = llvm::ArrayRef(dependsOnSets);
285-
do {
286-
// Form the set of input partial solutions.
287-
SmallVector<const Solution *, 2> dependsOnSolutions;
288-
for (auto index : swift::indices(indices)) {
289-
dependsOnSolutions.push_back(&(*dependsOnSets[index])[indices[index]]);
290-
}
291-
ContextualSolutions.push_back(std::make_unique<SmallVector<Solution, 2>>());
292-
293-
followup.push_back(std::make_unique<ComponentStep>(
294-
CS, Index, Constraints, Component, std::move(dependsOnSolutions),
295-
*ContextualSolutions.back()));
296-
} while (nextCombination(dependsOnSetsRef, indices));
297-
298-
/// Wait until all of the component steps are done.
299-
return suspend(followup);
300-
}
301-
302-
StepResult DependentComponentSplitterStep::resume(bool prevFailed) {
303-
for (auto &ComponentStepSolutions : ContextualSolutions) {
304-
Solutions.append(std::make_move_iterator(ComponentStepSolutions->begin()),
305-
std::make_move_iterator(ComponentStepSolutions->end()));
306-
}
307-
return done(/*isSuccess=*/!Solutions.empty());
308-
}
309-
310-
void DependentComponentSplitterStep::print(llvm::raw_ostream &Out) {
311-
Out << "DependentComponentSplitterStep for dependencies on [";
312-
interleave(
313-
Component.getDependencies(), [&](unsigned index) { Out << index; },
314-
[&] { Out << ", "; });
315-
Out << "]\n";
316-
}
317-
318246
StepResult ComponentStep::take(bool prevFailed) {
319247
// One of the previous components created by "split"
320248
// failed, it means that we can't solve this component.
321-
if ((prevFailed && DependsOnPartialSolutions.empty()) ||
322-
CS.isTooComplex(Solutions) || CS.worseThanBestSolution())
249+
if (prevFailed || CS.isTooComplex(Solutions) || CS.worseThanBestSolution())
323250
return done(/*isSuccess=*/false);
324251

325252
// Setup active scope, only if previous component didn't fail.
326253
setupScope();
327254

328-
// If there are any dependent partial solutions to compose, do so now.
329-
if (!DependsOnPartialSolutions.empty()) {
330-
for (auto partial : DependsOnPartialSolutions) {
331-
CS.replaySolution(*partial);
332-
}
333-
334-
// Simplify again.
335-
if (CS.failedConstraint || CS.simplify())
336-
return done(/*isSuccess=*/false);
337-
}
338-
339255
/// Try to figure out what this step is going to be,
340256
/// after the scope has been established.
341257
SmallString<64> potentialBindings;

lib/Sema/CSStep.h

+1-65
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ class SplitterStep final : public SolverStep {
240240

241241
SmallVector<Constraint *, 4> OrphanedConstraints;
242242

243-
/// Whether to include the partial results of this component in the final
244-
/// merged results.
245-
SmallVector<bool, 4> IncludeInMergedResults;
246-
247243
public:
248244
SplitterStep(ConstraintSystem &cs, SmallVectorImpl<Solution> &solutions)
249245
: SolverStep(cs, solutions) {}
@@ -269,56 +265,6 @@ class SplitterStep final : public SolverStep {
269265
bool mergePartialSolutions() const;
270266
};
271267

272-
/// `DependentComponentSplitterStep` is responsible for composing the partial
273-
/// solutions from other components (on which this component depends) into
274-
/// the inputs based on which we can solve a particular component.
275-
class DependentComponentSplitterStep final : public SolverStep {
276-
/// Constraints "in scope" of this step.
277-
ConstraintList *Constraints;
278-
279-
/// Index into the parent splitter step.
280-
unsigned Index;
281-
282-
/// The component that has dependencies.
283-
ConstraintGraph::Component Component;
284-
285-
/// Array containing all of the partial solutions for the parent split.
286-
MutableArrayRef<SmallVector<Solution, 4>> AllPartialSolutions;
287-
288-
/// The solutions computed the \c ComponentSteps created for each partial
289-
/// solution combinations. Will be merged into the final \c Solutions vector
290-
/// in \c resume.
291-
std::vector<std::unique_ptr<SmallVector<Solution, 2>>> ContextualSolutions;
292-
293-
/// Take all of the constraints in this component and put them into
294-
/// \c Constraints.
295-
void injectConstraints() {
296-
for (auto constraint : Component.getConstraints()) {
297-
Constraints->erase(constraint);
298-
Constraints->push_back(constraint);
299-
}
300-
}
301-
302-
public:
303-
DependentComponentSplitterStep(
304-
ConstraintSystem &cs,
305-
ConstraintList *constraints,
306-
unsigned index,
307-
ConstraintGraph::Component &&component,
308-
MutableArrayRef<SmallVector<Solution, 4>> allPartialSolutions)
309-
: SolverStep(cs, allPartialSolutions[index]), Constraints(constraints),
310-
Index(index), Component(std::move(component)),
311-
AllPartialSolutions(allPartialSolutions) {
312-
assert(!Component.getDependencies().empty() && "Should use ComponentStep");
313-
injectConstraints();
314-
}
315-
316-
StepResult take(bool prevFailed) override;
317-
StepResult resume(bool prevFailed) override;
318-
319-
void print(llvm::raw_ostream &Out) override;
320-
};
321-
322268

323269
/// `ComponentStep` represents a set of type variables and related
324270
/// constraints which could be solved independently. It's further
@@ -381,10 +327,6 @@ class ComponentStep final : public SolverStep {
381327
/// Constraints "in scope" of this step.
382328
ConstraintList *Constraints;
383329

384-
/// The set of partial solutions that should be composed before evaluating
385-
/// this component.
386-
SmallVector<const Solution *, 2> DependsOnPartialSolutions;
387-
388330
/// Constraint which doesn't have any free type variables associated
389331
/// with it, which makes it disconnected in the graph.
390332
Constraint *OrphanedConstraint = nullptr;
@@ -419,8 +361,6 @@ class ComponentStep final : public SolverStep {
419361
constraints->erase(constraint);
420362
Constraints->push_back(constraint);
421363
}
422-
423-
assert(component.getDependencies().empty());
424364
}
425365

426366
/// Create a component step that composes existing partial solutions before
@@ -429,15 +369,11 @@ class ComponentStep final : public SolverStep {
429369
ConstraintSystem &cs, unsigned index,
430370
ConstraintList *constraints,
431371
const ConstraintGraph::Component &component,
432-
llvm::SmallVectorImpl<const Solution *> &&dependsOnPartialSolutions,
433372
SmallVectorImpl<Solution> &solutions)
434373
: SolverStep(cs, solutions), Index(index), IsSingle(false),
435374
OriginalScore(getCurrentScore()), OriginalBestScore(getBestScore()),
436-
Constraints(constraints),
437-
DependsOnPartialSolutions(std::move(dependsOnPartialSolutions)) {
375+
Constraints(constraints) {
438376
TypeVars = component.typeVars;
439-
assert(DependsOnPartialSolutions.size() ==
440-
component.getDependencies().size());
441377

442378
for (auto constraint : component.getConstraints()) {
443379
constraints->erase(constraint);

lib/Sema/ConstraintGraph.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,6 @@ void ConstraintGraph::Component::addConstraint(Constraint *constraint) {
882882
constraints.push_back(constraint);
883883
}
884884

885-
void ConstraintGraph::Component::recordDependency(const Component &component) {
886-
dependencies.push_back(component.solutionIndex);
887-
}
888-
889885
SmallVector<ConstraintGraph::Component, 1>
890886
ConstraintGraph::computeConnectedComponents(
891887
ArrayRef<TypeVariableType *> typeVars) {
@@ -1139,20 +1135,6 @@ void ConstraintGraph::printConnectedComponents(
11391135
[&] {
11401136
out << ' ';
11411137
});
1142-
1143-
auto dependencies = component.getDependencies();
1144-
if (dependencies.empty())
1145-
continue;
1146-
1147-
SmallVector<unsigned, 4> indices{dependencies.begin(), dependencies.end()};
1148-
// Sort dependencies so output is stable.
1149-
llvm::sort(indices);
1150-
1151-
// Print all of the one-way components.
1152-
out << " depends on ";
1153-
llvm::interleave(
1154-
indices, [&out](unsigned index) { out << index; },
1155-
[&out] { out << ", "; });
11561138
}
11571139
}
11581140

0 commit comments

Comments
 (0)