Skip to content

Commit 2a1d539

Browse files
committed
[CSStep] Reset scope counter before attempting conjunction step
Each conjunction step should be executed in isolation from outer constraint system state, which should also include scope counter because otherwise, e.g. for large closures, solver might stop prematurely since all of the previous statements/expressions would contribute to the scope total.
1 parent 60f3d8a commit 2a1d539

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: lib/Sema/CSStep.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ bool ConjunctionStep::attempt(const ConjunctionElement &element) {
816816
// by dropping all scoring information.
817817
CS.CurrentScore = Score();
818818

819+
// Reset the scope counter to avoid "too complex" failures
820+
// when closure has a lot of elements in the body.
821+
CS.CountScopes = 0;
822+
819823
auto success = element.attempt(CS);
820824

821825
// If element attempt has failed, mark whole conjunction

Diff for: lib/Sema/CSStep.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
857857
/// The score established before conjunction is attempted.
858858
Score CurrentScore;
859859

860+
/// The number of constraint solver scopes already explored
861+
/// before accepting this conjunction.
862+
llvm::SaveAndRestore<unsigned> OuterScopeCount;
863+
860864
/// Conjunction constraint associated with this step.
861865
Constraint *Conjunction;
862866
/// Position of the conjunction in the inactive constraints
@@ -889,8 +893,8 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
889893
: BindingStep(cs, {cs, conjunction},
890894
conjunction->isIsolated() ? IsolatedSolutions : solutions),
891895
BestScore(getBestScore()), CurrentScore(getCurrentScore()),
892-
Conjunction(conjunction), AfterConjunction(erase(conjunction)),
893-
OuterSolutions(solutions) {
896+
OuterScopeCount(cs.CountScopes, 0), Conjunction(conjunction),
897+
AfterConjunction(erase(conjunction)), OuterSolutions(solutions) {
894898
assert(conjunction->getKind() == ConstraintKind::Conjunction);
895899

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

0 commit comments

Comments
 (0)