Skip to content

Commit c554fca

Browse files
committed
[CSStep] Isolated conjunctions can't see outer solutions
All of the previously deduced solutions should be hidden until isolated conjunction is successfully solved.
1 parent ff4aca3 commit c554fca

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Diff for: lib/Sema/CSStep.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
851851
if (prevFailed)
852852
return failConjunction();
853853

854+
// There could be a local ambiguity related to
855+
// the current element, let's try to resolve it.
854856
if (Solutions.size() > 1) {
855857
filterSolutions(Solutions, /*minimize=*/true);
856858

@@ -918,7 +920,7 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
918920

919921
// Now that all of the information from the conjunction has
920922
// been applied, let's attempt to solve the outer scope.
921-
return suspend(std::make_unique<SplitterStep>(CS, Solutions));
923+
return suspend(std::make_unique<SplitterStep>(CS, OuterSolutions));
922924
}
923925
}
924926

Diff for: lib/Sema/CSStep.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,25 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
858858
/// system step before conjunction step.
859859
Optional<SolverSnapshot> Snapshot;
860860

861+
/// A set of previously deduced solutions. This is used upon
862+
/// successful solution of an isolated conjunction to introduce
863+
/// all of the inferred information back into the outer context.
864+
SmallVectorImpl<Solution> &OuterSolutions;
865+
866+
/// Solutions produced while attempting elements of an isolated conjunction.
867+
///
868+
/// Note that this is what `BindingStep` is initialized with
869+
/// in isolated mode.
870+
SmallVector<Solution, 4> IsolatedSolutions;
871+
861872
public:
862873
ConjunctionStep(ConstraintSystem &cs, Constraint *conjunction,
863874
SmallVectorImpl<Solution> &solutions)
864-
: BindingStep(cs, {cs, conjunction}, solutions),
875+
: BindingStep(cs, {cs, conjunction},
876+
conjunction->isIsolated() ? IsolatedSolutions : solutions),
865877
BestScore(getBestScore()), CurrentScore(getCurrentScore()),
866-
Conjunction(conjunction), AfterConjunction(erase(conjunction)) {
878+
Conjunction(conjunction), AfterConjunction(erase(conjunction)),
879+
OuterSolutions(solutions) {
867880
assert(conjunction->getKind() == ConstraintKind::Conjunction);
868881

869882
// Make a snapshot of the constraint system state before conjunction.

0 commit comments

Comments
 (0)