Skip to content

Commit 983d9b3

Browse files
Merge pull request #34621 from LucianoPAlmeida/nfc-minor-fixme-cg
[NFC][ConstraintGraph] Address fixme and switch CG::Component dependsOn type
2 parents 1315ce8 + 72b594b commit 983d9b3

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

include/swift/Sema/ConstraintGraph.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,13 @@ class ConstraintGraph {
228228
/// The constraints in this component.
229229
TinyPtrVector<Constraint *> constraints;
230230

231-
public:
232231
/// The set of components that this component depends on, such that
233232
/// the partial solutions of the those components need to be available
234233
/// before this component can be solved.
235234
///
236-
/// FIXME: Use a TinyPtrVector here.
237-
std::vector<unsigned> dependsOn;
235+
SmallVector<unsigned, 2> dependencies;
238236

237+
public:
239238
Component(unsigned solutionIndex) : solutionIndex(solutionIndex) { }
240239

241240
/// Whether this component represents an orphaned constraint.
@@ -250,6 +249,11 @@ class ConstraintGraph {
250249
return constraints;
251250
}
252251

252+
/// Records a component which this component depends on.
253+
void recordDependency(const Component &component);
254+
255+
ArrayRef<unsigned> getDependencies() const { return dependencies; }
256+
253257
unsigned getNumDisjunctions() const { return numDisjunctions; }
254258
};
255259

lib/Sema/CSStep.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void SplitterStep::computeFollowupSteps(
125125
unsigned solutionIndex = components[i].solutionIndex;
126126

127127
// If there are no dependencies, build a normal component step.
128-
if (components[i].dependsOn.empty()) {
128+
if (components[i].getDependencies().empty()) {
129129
steps.push_back(std::make_unique<ComponentStep>(
130130
CS, solutionIndex, &Components[i], std::move(components[i]),
131131
PartialSolutions[solutionIndex]));
@@ -135,7 +135,7 @@ void SplitterStep::computeFollowupSteps(
135135
// Note that the partial results from any dependencies of this component
136136
// need not be included in the final merged results, because they'll
137137
// already be part of the partial results for this component.
138-
for (auto dependsOn : components[i].dependsOn) {
138+
for (auto dependsOn : components[i].getDependencies()) {
139139
IncludeInMergedResults[dependsOn] = false;
140140
}
141141

@@ -265,13 +265,13 @@ StepResult DependentComponentSplitterStep::take(bool prevFailed) {
265265

266266
// Figure out the sets of partial solutions that this component depends on.
267267
SmallVector<const SmallVector<Solution, 4> *, 2> dependsOnSets;
268-
for (auto index : Component.dependsOn) {
268+
for (auto index : Component.getDependencies()) {
269269
dependsOnSets.push_back(&AllPartialSolutions[index]);
270270
}
271271

272272
// Produce all combinations of partial solutions for the inputs.
273273
SmallVector<std::unique_ptr<SolverStep>, 4> followup;
274-
SmallVector<unsigned, 2> indices(Component.dependsOn.size(), 0);
274+
SmallVector<unsigned, 2> indices(Component.getDependencies().size(), 0);
275275
auto dependsOnSetsRef = llvm::makeArrayRef(dependsOnSets);
276276
do {
277277
// Form the set of input partial solutions.
@@ -296,8 +296,9 @@ StepResult DependentComponentSplitterStep::resume(bool prevFailed) {
296296

297297
void DependentComponentSplitterStep::print(llvm::raw_ostream &Out) {
298298
Out << "DependentComponentSplitterStep for dependencies on [";
299-
interleave(Component.dependsOn, [&](unsigned index) { Out << index; },
300-
[&] { Out << ", "; });
299+
interleave(
300+
Component.getDependencies(), [&](unsigned index) { Out << index; },
301+
[&] { Out << ", "; });
301302
Out << "]\n";
302303
}
303304

lib/Sema/CSStep.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class DependentComponentSplitterStep final : public SolverStep {
313313
: SolverStep(cs, allPartialSolutions[index]), Constraints(constraints),
314314
Index(index), Component(std::move(component)),
315315
AllPartialSolutions(allPartialSolutions) {
316-
assert(!Component.dependsOn.empty() && "Should use ComponentStep");
316+
assert(!Component.getDependencies().empty() && "Should use ComponentStep");
317317
injectConstraints();
318318
}
319319

@@ -421,7 +421,7 @@ class ComponentStep final : public SolverStep {
421421
Constraints->push_back(constraint);
422422
}
423423

424-
assert(component.dependsOn.empty());
424+
assert(component.getDependencies().empty());
425425
}
426426

427427
/// Create a component step that composes existing partial solutions before
@@ -437,7 +437,8 @@ class ComponentStep final : public SolverStep {
437437
Constraints(constraints),
438438
DependsOnPartialSolutions(std::move(dependsOnPartialSolutions)) {
439439
TypeVars = component.typeVars;
440-
assert(DependsOnPartialSolutions.size() == component.dependsOn.size());
440+
assert(DependsOnPartialSolutions.size() ==
441+
component.getDependencies().size());
441442

442443
for (auto constraint : component.getConstraints()) {
443444
constraints->erase(constraint);

lib/Sema/ConstraintGraph.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ namespace {
674674
if (validComponents.count(inAdj) == 0)
675675
continue;
676676

677-
component.dependsOn.push_back(getComponent(inAdj).solutionIndex);
677+
component.recordDependency(getComponent(inAdj));
678678
}
679679
}
680680
}
@@ -1054,6 +1054,10 @@ void ConstraintGraph::Component::addConstraint(Constraint *constraint) {
10541054
constraints.push_back(constraint);
10551055
}
10561056

1057+
void ConstraintGraph::Component::recordDependency(const Component &component) {
1058+
dependencies.push_back(component.solutionIndex);
1059+
}
1060+
10571061
SmallVector<ConstraintGraph::Component, 1>
10581062
ConstraintGraph::computeConnectedComponents(
10591063
ArrayRef<TypeVariableType *> typeVars) {
@@ -1277,13 +1281,13 @@ void ConstraintGraph::printConnectedComponents(
12771281
out << ' ';
12781282
});
12791283

1280-
if (component.dependsOn.empty())
1284+
if (component.getDependencies().empty())
12811285
continue;
12821286

12831287
// Print all of the one-way components.
12841288
out << " depends on ";
12851289
llvm::interleave(
1286-
component.dependsOn,
1290+
component.getDependencies(),
12871291
[&](unsigned index) { out << index; },
12881292
[&] { out << ", "; }
12891293
);

0 commit comments

Comments
 (0)