Skip to content

Commit bb877ce

Browse files
committed
[CS] Remove ConstraintSystemPhase
1 parent dc2392f commit bb877ce

File tree

3 files changed

+4
-47
lines changed

3 files changed

+4
-47
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,11 +2129,6 @@ class SyntacticElementTargetRewriter {
21292129
virtual ~SyntacticElementTargetRewriter() = default;
21302130
};
21312131

2132-
enum class ConstraintSystemPhase {
2133-
ConstraintGeneration,
2134-
Solving
2135-
};
2136-
21372132
/// Retrieve the closure type from the constraint system.
21382133
struct GetClosureType {
21392134
ConstraintSystem &cs;
@@ -2195,9 +2190,6 @@ class ConstraintSystem {
21952190
/// Do not set directly, call \c recordFailedConstraint instead.
21962191
Constraint *failedConstraint = nullptr;
21972192

2198-
/// Current phase of the constraint system lifetime.
2199-
ConstraintSystemPhase Phase = ConstraintSystemPhase::ConstraintGeneration;
2200-
22012193
/// The set of expressions for which we have generated constraints.
22022194
llvm::SetVector<Expr *> InputExprs;
22032195

@@ -2675,30 +2667,6 @@ class ConstraintSystem {
26752667
/// \c nullptr if no constraint has failed.
26762668
Constraint *getFailedConstraint() const { return failedConstraint; }
26772669

2678-
ConstraintSystemPhase getPhase() const { return Phase; }
2679-
2680-
/// Move constraint system to a new phase of its lifetime.
2681-
void setPhase(ConstraintSystemPhase newPhase) {
2682-
if (Phase == newPhase)
2683-
return;
2684-
2685-
#ifndef NDEBUG
2686-
switch (Phase) {
2687-
case ConstraintSystemPhase::ConstraintGeneration:
2688-
assert(newPhase == ConstraintSystemPhase::Solving);
2689-
break;
2690-
2691-
case ConstraintSystemPhase::Solving:
2692-
// We can come back to constraint generation phase while
2693-
// processing result builder body.
2694-
assert(newPhase == ConstraintSystemPhase::ConstraintGeneration);
2695-
break;
2696-
}
2697-
#endif
2698-
2699-
Phase = newPhase;
2700-
}
2701-
27022670
/// Check whether constraint system is in valid state e.g.
27032671
/// has left-over active/inactive constraints which should
27042672
/// have been simplified.
@@ -3906,7 +3874,7 @@ class ConstraintSystem {
39063874
// Add this constraint to the constraint graph.
39073875
CG.addConstraint(constraint);
39083876

3909-
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
3877+
if (isDebugMode() && solverState) {
39103878
auto &log = llvm::errs();
39113879
log.indent(solverState->getCurrentIndent() + 4) << "(added constraint: ";
39123880
constraint->print(log, &getASTContext().SourceMgr,
@@ -3927,7 +3895,7 @@ class ConstraintSystem {
39273895
if (solverState)
39283896
recordChange(SolverTrail::Change::RetiredConstraint(where, constraint));
39293897

3930-
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
3898+
if (isDebugMode() && solverState) {
39313899
auto &log = llvm::errs();
39323900
log.indent(solverState->getCurrentIndent() + 4)
39333901
<< "(removed constraint: ";

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ namespace {
944944
class ConstraintGenerator : public ExprVisitor<ConstraintGenerator, Type> {
945945
ConstraintSystem &CS;
946946
DeclContext *CurDC;
947-
ConstraintSystemPhase CurrPhase;
948947

949948
/// A map from each UnresolvedMemberExpr to the respective (implicit) base
950949
/// found during our walk.
@@ -1253,23 +1252,15 @@ namespace {
12531252

12541253
public:
12551254
ConstraintGenerator(ConstraintSystem &CS, DeclContext *DC)
1256-
: CS(CS), CurDC(DC ? DC : CS.DC), CurrPhase(CS.getPhase()) {
1257-
// Although constraint system is initialized in `constraint
1258-
// generation` phase, we have to set it here manually because e.g.
1259-
// result builders could generate constraints for its body
1260-
// in the middle of the solving.
1261-
CS.setPhase(ConstraintSystemPhase::ConstraintGeneration);
1262-
1255+
: CS(CS), CurDC(DC ? DC : CS.DC) {
12631256
// Pick up the saved stack of pack expansions so we can continue
12641257
// to handle pack element references inside the closure body.
12651258
if (auto *ACE = dyn_cast<AbstractClosureExpr>(CurDC)) {
12661259
OuterExpansions = CS.getCapturedExpansions(ACE);
12671260
}
12681261
}
12691262

1270-
virtual ~ConstraintGenerator() {
1271-
CS.setPhase(CurrPhase);
1272-
}
1263+
virtual ~ConstraintGenerator() = default;
12731264

12741265
ConstraintSystem &getConstraintSystem() const { return CS; }
12751266

lib/Sema/CSSolver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,6 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
15771577
void ConstraintSystem::solveImpl(SmallVectorImpl<Solution> &solutions) {
15781578
assert(solverState);
15791579

1580-
setPhase(ConstraintSystemPhase::Solving);
1581-
15821580
// If constraint system failed while trying to
15831581
// genenerate constraints, let's stop right here.
15841582
if (failedConstraint)

0 commit comments

Comments
 (0)