Skip to content

Commit 7259926

Browse files
authored
Merge pull request #8262 from rudkx/propagate-constraints
2 parents 655b6e3 + 4a4e0f4 commit 7259926

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,10 +3064,6 @@ Expr *ConstraintSystem::generateConstraints(Expr *expr) {
30643064
if (result)
30653065
this->optimizeConstraints(result);
30663066

3067-
// If the experimental constraint propagation pass is enabled, run it.
3068-
if (TC.Context.LangOpts.EnableConstraintPropagation)
3069-
propagateConstraints();
3070-
30713067
return result;
30723068
}
30733069

lib/Sema/CSPropagate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "ConstraintGraph.h"
1717
#include "ConstraintSystem.h"
1818
#include "llvm/ADT/DenseSet.h"
19-
#include "llvm/Support/CommandLine.h"
2019
#include "llvm/Support/Debug.h"
2120
using namespace swift;
2221
using namespace constraints;
2322

24-
void ConstraintSystem::propagateConstraints() {
23+
bool ConstraintSystem::propagateConstraints() {
24+
assert(getActiveConstraints().empty() && "Expected no active constraints!");
25+
26+
return false;
2527
}

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,8 @@ matchCallArguments(ConstraintSystem &cs, ConstraintKind kind,
745745
if (!haveOneNonUserConversion) {
746746
subflags |= ConstraintSystem::TMF_ApplyingOperatorParameter;
747747
}
748-
749-
switch (cs.matchTypes(argTy,paramTy,
750-
subKind, subflags,
751-
loc)) {
748+
749+
switch (cs.matchTypes(argTy, paramTy, subKind, subflags, loc)) {
752750
case ConstraintSystem::SolutionKind::Error:
753751
return ConstraintSystem::SolutionKind::Error;
754752

lib/Sema/CSSolver.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,12 @@ void ConstraintSystem::Candidate::applySolutions(
15791579
}
15801580

15811581
void ConstraintSystem::shrink(Expr *expr) {
1582+
// Disable the shrink pass when constraint propagation is
1583+
// enabled. They achieve similar effects, and the shrink pass is
1584+
// known to have bad behavior in some cases.
1585+
if (TC.Context.LangOpts.EnableConstraintPropagation)
1586+
return;
1587+
15821588
typedef llvm::SmallDenseMap<Expr *, ArrayRef<ValueDecl *>> DomainMap;
15831589

15841590
// A collection of original domains of all of the expressions,
@@ -1977,6 +1983,17 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
19771983
// Set up solver state.
19781984
SolverState state(*this);
19791985

1986+
// Simplify any constraints left active after constraint generation
1987+
// and optimization. Return if the resulting system has no
1988+
// solutions.
1989+
if (simplify())
1990+
return true;
1991+
1992+
// If the experimental constraint propagation pass is enabled, run it.
1993+
if (TC.Context.LangOpts.EnableConstraintPropagation)
1994+
if (propagateConstraints())
1995+
return true;
1996+
19801997
// Solve the system.
19811998
solveRec(solutions, allowFreeTypeVariables);
19821999

@@ -2322,7 +2339,7 @@ void ConstraintSystem::collectDisjunctions(
23222339
}
23232340
}
23242341

2325-
std::pair<PotentialBindings, TypeVariableType *>
2342+
static std::pair<PotentialBindings, TypeVariableType *>
23262343
determineBestBindings(ConstraintSystem &CS) {
23272344
// Look for potential type variable bindings.
23282345
TypeVariableType *bestTypeVar = nullptr;

lib/Sema/ConstraintSystem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,10 @@ class ConstraintSystem {
20542054

20552055
/// \brief Propagate constraints in an effort to enforce local
20562056
/// consistency to reduce the time to solve the system.
2057-
void propagateConstraints();
2057+
///
2058+
/// \returns true if the system is known to be inconsistent (have no
2059+
/// solutions).
2060+
bool propagateConstraints();
20582061

20592062
/// \brief The result of attempting to resolve a constraint or set of
20602063
/// constraints.

0 commit comments

Comments
 (0)