@@ -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-
318246StepResult 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;
0 commit comments