Skip to content

[Sema] Use different solution vectors for ComponentSteps created by DependentComponentSplitterStep #37964

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 1 commit into from
Jun 23, 2021
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
12 changes: 8 additions & 4 deletions lib/Sema/CSStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,22 @@ StepResult DependentComponentSplitterStep::take(bool prevFailed) {
for (auto index : swift::indices(indices)) {
dependsOnSolutions.push_back(&(*dependsOnSets[index])[indices[index]]);
}
ContextualSolutions.push_back(std::make_unique<SmallVector<Solution, 2>>());

followup.push_back(
std::make_unique<ComponentStep>(CS, Index, Constraints, Component,
std::move(dependsOnSolutions),
Solutions));
followup.push_back(std::make_unique<ComponentStep>(
CS, Index, Constraints, Component, std::move(dependsOnSolutions),
*ContextualSolutions.back()));
} while (nextCombination(dependsOnSetsRef, indices));

/// Wait until all of the component steps are done.
return suspend(followup);
}

StepResult DependentComponentSplitterStep::resume(bool prevFailed) {
for (auto &ComponentStepSolutions : ContextualSolutions) {
Solutions.append(std::make_move_iterator(ComponentStepSolutions->begin()),
std::make_move_iterator(ComponentStepSolutions->end()));
}
return done(/*isSuccess=*/!Solutions.empty());
}

Expand Down
5 changes: 5 additions & 0 deletions lib/Sema/CSStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ class DependentComponentSplitterStep final : public SolverStep {
/// Array containing all of the partial solutions for the parent split.
MutableArrayRef<SmallVector<Solution, 4>> AllPartialSolutions;

/// The solutions computed the \c ComponentSteps created for each partial
/// solution combinations. Will be merged into the final \c Solutions vector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: combination*

/// in \c resume.
std::vector<std::unique_ptr<SmallVector<Solution, 2>>> ContextualSolutions;

/// Take all of the constraints in this component and put them into
/// \c Constraints.
void injectConstraints() {
Expand Down
28 changes: 28 additions & 0 deletions validation-test/Sema/sr14692.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift

enum Foo { case foo }
enum Bar { case bar }

@resultBuilder struct ViewBuilder2 {
static func buildBlock(_ content: MyView) -> MyView { fatalError() }
static func buildIf(_ content: MyView?) -> MyView { fatalError() }
}

func makeView(@ViewBuilder2 content: () -> MyView) { fatalError() }

struct MyView {
init() { fatalError() }

func qadding(bar: Foo) -> MyView { fatalError() } // expected-note{{incorrect labels for candidate (have: '(_:)', expected: '(bar:)')}}
func qadding(foo: Foo) -> MyView { fatalError() } // expected-note{{incorrect labels for candidate (have: '(_:)', expected: '(foo:)')}}
}

func testCase() {
let array: [Int]? = []

makeView() {
if array?.isEmpty == false {
MyView().qadding(.foo) // expected-error{{no exact matches in call to instance method 'qadding'}}
}
}
}