Skip to content

Commit 58a6a64

Browse files
committed
Sema: SolverTrail::Change::RetiredConstraint now remembers the position
1 parent d502e55 commit 58a6a64

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

include/swift/Sema/CSTrail.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ CLOSURE_CHANGE(RecordedPreconcurrencyClosure)
6969
CONSTRAINT_CHANGE(DisabledConstraint)
7070
CONSTRAINT_CHANGE(FavoredConstraint)
7171
CONSTRAINT_CHANGE(GeneratedConstraint)
72-
CONSTRAINT_CHANGE(RetiredConstraint)
7372

7473
GRAPH_NODE_CHANGE(AddedConstraint)
7574
GRAPH_NODE_CHANGE(RemovedConstraint)
@@ -97,8 +96,9 @@ CHANGE(RecordedCaseLabelItemInfo)
9796
CHANGE(RecordedPotentialThrowSite)
9897
CHANGE(RecordedIsolatedParam)
9998
CHANGE(RecordedKeyPath)
99+
CHANGE(RetiredConstraint)
100100

101-
LAST_CHANGE(RecordedKeyPath)
101+
LAST_CHANGE(RetiredConstraint)
102102

103103
#undef LOCATOR_CHANGE
104104
#undef EXPR_CHANGE

include/swift/Sema/CSTrail.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "swift/AST/AnyFunctionRef.h"
2121
#include "swift/AST/Type.h"
2222
#include "swift/AST/Types.h"
23+
#include "swift/Sema/Constraint.h"
24+
#include "llvm/ADT/ilist.h"
2325
#include <vector>
2426

2527
namespace llvm {
@@ -103,7 +105,6 @@ class SolverTrail {
103105
Type DstType;
104106
} Restriction;
105107

106-
107108
struct {
108109
GenericTypeParamType *GP;
109110
Type ReqTy;
@@ -119,6 +120,14 @@ class SolverTrail {
119120
Type OldType;
120121
} KeyPath;
121122

123+
struct {
124+
/// It's former position in the inactive constraints list.
125+
llvm::ilist<Constraint>::iterator Where;
126+
127+
/// The constraint.
128+
Constraint *Constraint;
129+
} Retiree;
130+
122131
ConstraintFix *TheFix;
123132
ConstraintLocator *TheLocator;
124133
PackExpansionType *TheExpansion;
@@ -213,6 +222,10 @@ class SolverTrail {
213222
/// Create a change that recorded a key path expression.
214223
static Change RecordedKeyPath(KeyPathExpr *expr);
215224

225+
/// Create a change that removed a constraint from the inactive constraint list.
226+
static Change RetiredConstraint(llvm::ilist<Constraint>::iterator where,
227+
Constraint *constraint);
228+
216229
/// Undo this change, reverting the constraint graph to the state it
217230
/// had prior to this change.
218231
///

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,13 +2538,6 @@ class ConstraintSystem {
25382538
#define CS_STATISTIC(Name, Description) unsigned Name = 0;
25392539
#include "ConstraintSolverStats.def"
25402540

2541-
/// Mark given constraint as retired along current solver path.
2542-
///
2543-
/// \param constraint The constraint to retire temporarily.
2544-
void retireConstraint(Constraint *constraint) {
2545-
Trail.recordChange(SolverTrail::Change::RetiredConstraint(constraint));
2546-
}
2547-
25482541
/// Add new "generated" constraint along the current solver path.
25492542
///
25502543
/// \param constraint The newly generated constraint.
@@ -3924,7 +3917,10 @@ class ConstraintSystem {
39243917
/// Remove an inactive constraint from the current constraint graph.
39253918
void removeInactiveConstraint(Constraint *constraint) {
39263919
CG.removeConstraint(constraint);
3927-
InactiveConstraints.erase(constraint);
3920+
3921+
auto where = InactiveConstraints.erase(constraint);
3922+
if (solverState)
3923+
recordChange(SolverTrail::Change::RetiredConstraint(where, constraint));
39283924

39293925
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
39303926
auto &log = llvm::errs();
@@ -3934,9 +3930,6 @@ class ConstraintSystem {
39343930
solverState->getCurrentIndent() + 4);
39353931
log << ")\n";
39363932
}
3937-
3938-
if (solverState)
3939-
solverState->retireConstraint(constraint);
39403933
}
39413934

39423935
/// Transfer given constraint from to active list

lib/Sema/CSTrail.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ SolverTrail::Change::RecordedKeyPath(KeyPathExpr *expr) {
296296
return result;
297297
}
298298

299+
SolverTrail::Change
300+
SolverTrail::Change::RetiredConstraint(ConstraintList::iterator where,
301+
Constraint *constraint) {
302+
Change result;
303+
result.Kind = ChangeKind::RetiredConstraint;
304+
result.Retiree.Where = where;
305+
result.Retiree.Constraint = constraint;
306+
return result;
307+
}
308+
299309
SyntacticElementTargetKey
300310
SolverTrail::Change::getSyntacticElementTargetKey() const {
301311
ASSERT(Kind == ChangeKind::RecordedTarget);
@@ -481,7 +491,8 @@ void SolverTrail::Change::undo(ConstraintSystem &cs) const {
481491
}
482492

483493
case ChangeKind::RetiredConstraint:
484-
cs.InactiveConstraints.push_back(TheConstraint.Constraint);
494+
cs.InactiveConstraints.insert(Retiree.Where,
495+
Retiree.Constraint);
485496
break;
486497
}
487498
}
@@ -674,6 +685,13 @@ void SolverTrail::Change::dump(llvm::raw_ostream &out,
674685
simple_display(out, KeyPath.Expr);
675686
out << ")\n";
676687
break;
688+
689+
case ChangeKind::RetiredConstraint:
690+
out << "(RetiredConstraint ";
691+
TheConstraint.Constraint->print(out, &cs.getASTContext().SourceMgr,
692+
indent + 2);
693+
out << ")\n";
694+
break;
677695
}
678696
}
679697

0 commit comments

Comments
 (0)