Skip to content

Commit 45699ce

Browse files
authored
Merge pull request swiftlang#38061 from ahoppen/pr-5.5/solutions-scoring
[5.5][Sema] Use different solution vectors for `ComponentStep`s created by `DependentComponentSplitterStep`
2 parents 7475607 + 7021282 commit 45699ce

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

lib/Sema/CSStep.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,22 @@ StepResult DependentComponentSplitterStep::take(bool prevFailed) {
282282
for (auto index : swift::indices(indices)) {
283283
dependsOnSolutions.push_back(&(*dependsOnSets[index])[indices[index]]);
284284
}
285+
ContextualSolutions.push_back(std::make_unique<SmallVector<Solution, 2>>());
285286

286-
followup.push_back(
287-
std::make_unique<ComponentStep>(CS, Index, Constraints, Component,
288-
std::move(dependsOnSolutions),
289-
Solutions));
287+
followup.push_back(std::make_unique<ComponentStep>(
288+
CS, Index, Constraints, Component, std::move(dependsOnSolutions),
289+
*ContextualSolutions.back()));
290290
} while (nextCombination(dependsOnSetsRef, indices));
291291

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

296296
StepResult DependentComponentSplitterStep::resume(bool prevFailed) {
297+
for (auto &ComponentStepSolutions : ContextualSolutions) {
298+
Solutions.append(std::make_move_iterator(ComponentStepSolutions->begin()),
299+
std::make_move_iterator(ComponentStepSolutions->end()));
300+
}
297301
return done(/*isSuccess=*/!Solutions.empty());
298302
}
299303

lib/Sema/CSStep.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ class DependentComponentSplitterStep final : public SolverStep {
294294
/// Array containing all of the partial solutions for the parent split.
295295
MutableArrayRef<SmallVector<Solution, 4>> AllPartialSolutions;
296296

297+
/// The solutions computed the \c ComponentSteps created for each partial
298+
/// solution combinations. Will be merged into the final \c Solutions vector
299+
/// in \c resume.
300+
std::vector<std::unique_ptr<SmallVector<Solution, 2>>> ContextualSolutions;
301+
297302
/// Take all of the constraints in this component and put them into
298303
/// \c Constraints.
299304
void injectConstraints() {

validation-test/Sema/sr14692.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
enum Foo { case foo }
4+
enum Bar { case bar }
5+
6+
@resultBuilder struct ViewBuilder2 {
7+
static func buildBlock(_ content: MyView) -> MyView { fatalError() }
8+
static func buildIf(_ content: MyView?) -> MyView { fatalError() }
9+
}
10+
11+
func makeView(@ViewBuilder2 content: () -> MyView) { fatalError() }
12+
13+
struct MyView {
14+
init() { fatalError() }
15+
16+
func qadding(bar: Foo) -> MyView { fatalError() } // expected-note{{incorrect labels for candidate (have: '(_:)', expected: '(bar:)')}}
17+
func qadding(foo: Foo) -> MyView { fatalError() } // expected-note{{incorrect labels for candidate (have: '(_:)', expected: '(foo:)')}}
18+
}
19+
20+
func testCase() {
21+
let array: [Int]? = []
22+
23+
makeView() {
24+
if array?.isEmpty == false {
25+
MyView().qadding(.foo) // expected-error{{no exact matches in call to instance method 'qadding'}}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)