@@ -42,7 +42,6 @@ namespace constraints {
4242
4343class Constraint ;
4444class ConstraintGraph ;
45- class ConstraintGraphScope ;
4645class ConstraintSystem ;
4746class TypeVariableBinding ;
4847
@@ -58,6 +57,13 @@ class ConstraintGraphNode {
5857 // / Retrieve the type variable this node represents.
5958 TypeVariableType *getTypeVariable () const { return TypeVar; }
6059
60+ void reset ();
61+
62+ void initTypeVariable (TypeVariableType *typeVar) {
63+ ASSERT (!TypeVar);
64+ TypeVar = typeVar;
65+ }
66+
6167 // / Retrieve the set of constraints that mention this type variable.
6268 // /
6369 // / These are the hyperedges of the graph, connecting this node to
@@ -148,9 +154,7 @@ class ConstraintGraphNode {
148154 void introduceToInference (Type fixedType);
149155
150156 // / Opposite of \c introduceToInference(Type)
151- void
152- retractFromInference (Type fixedType,
153- SmallPtrSetImpl<TypeVariableType *> &referencedVars);
157+ void retractFromInference (Type fixedType);
154158
155159 // / Drop all previously collected bindings and re-infer based on the
156160 // / current set constraints associated with this equivalence class.
@@ -216,6 +220,7 @@ class ConstraintGraphNode {
216220 friend class ConstraintGraph ;
217221 friend class ConstraintSystem ;
218222 friend class TypeVariableBinding ;
223+ friend class SolverTrail ;
219224};
220225
221226// / A graph that describes the relationships among the various type variables
@@ -266,6 +271,9 @@ class ConstraintGraph {
266271 // / Bind the given type variable to the given fixed type.
267272 void bindTypeVariable (TypeVariableType *typeVar, Type fixedType);
268273
274+ // / Introduce the type variable's fixed type to inference.
275+ void introduceToInference (TypeVariableType *typeVar, Type fixedType);
276+
269277 // / Describes which constraints \c gatherConstraints should gather.
270278 enum class GatheringKind {
271279 // / Gather constraints associated with all of the variables within the
@@ -387,7 +395,6 @@ class ConstraintGraph {
387395 // / Print the graph.
388396 void print (ArrayRef<TypeVariableType *> typeVars, llvm::raw_ostream &out);
389397 void dump (llvm::raw_ostream &out);
390- void dumpActiveScopeChanges (llvm::raw_ostream &out, unsigned indent = 0 );
391398
392399 // FIXME: Potentially side-effectful.
393400 SWIFT_DEBUG_HELPER (void dump ());
@@ -423,6 +430,12 @@ class ConstraintGraph {
423430 // / caution.
424431 void unbindTypeVariable (TypeVariableType *typeVar, Type fixedType);
425432
433+ // / Retract the given type variable from inference.
434+ // /
435+ // / Note that this change is not recorded and cannot be undone. Use with
436+ // / caution.
437+ void retractFromInference (TypeVariableType *typeVar, Type fixedType);
438+
426439 // / Perform edge contraction on the constraint graph, merging equivalence
427440 // / classes until a fixed point is reached.
428441 bool contractEdges ();
@@ -436,90 +449,14 @@ class ConstraintGraph {
436449 // / Constraints that are "orphaned" because they contain no type variables.
437450 SmallVector<Constraint *, 4 > OrphanedConstraints;
438451
452+ // / Unused nodes.
453+ SmallVector<ConstraintGraphNode *> FreeList;
454+
439455 // / Increment the number of constraints considered per attempt
440456 // / to contract constraint graph edges.
441457 void incrementConstraintsPerContractionCounter ();
442458
443- // / The kind of change made to the graph.
444- enum class ChangeKind {
445- // / Added a type variable.
446- AddedTypeVariable,
447- // / Added a new constraint.
448- AddedConstraint,
449- // / Removed an existing constraint
450- RemovedConstraint,
451- // / Extended the equivalence class of a type variable.
452- ExtendedEquivalenceClass,
453- // / Added a fixed binding for a type variable.
454- BoundTypeVariable,
455- };
456-
457- // / A change made to the constraint graph.
458- // /
459- // / Each change can be undone (once, and in reverse order) by calling the
460- // / undo() method.
461- class Change {
462- public:
463- // / The kind of change.
464- ChangeKind Kind;
465-
466- union {
467- TypeVariableType *TypeVar;
468- Constraint *TheConstraint;
469-
470- struct {
471- // / The type variable whose equivalence class was extended.
472- TypeVariableType *TypeVar;
473-
474- // / The previous size of the equivalence class.
475- unsigned PrevSize;
476- } EquivClass;
477-
478- struct {
479- // / The type variable being bound to a fixed type.
480- TypeVariableType *TypeVar;
481-
482- // / The fixed type to which the type variable was bound.
483- TypeBase *FixedType;
484- } Binding;
485- };
486-
487- Change () : Kind(ChangeKind::AddedTypeVariable), TypeVar(nullptr ) { }
488-
489- // / Create a change that added a type variable.
490- static Change addedTypeVariable (TypeVariableType *typeVar);
491-
492- // / Create a change that added a constraint.
493- static Change addedConstraint (Constraint *constraint);
494-
495- // / Create a change that removed a constraint.
496- static Change removedConstraint (Constraint *constraint);
497-
498- // / Create a change that extended an equivalence class.
499- static Change extendedEquivalenceClass (TypeVariableType *typeVar,
500- unsigned prevSize);
501-
502- // / Create a change that bound a type variable to a fixed type.
503- static Change boundTypeVariable (TypeVariableType *typeVar, Type fixed);
504-
505- // / Undo this change, reverting the constraint graph to the state it
506- // / had prior to this change.
507- // /
508- // / Changes must be undone in stack order.
509- void undo (ConstraintGraph &cg);
510- };
511-
512- // / The currently active scope, or null if we aren't tracking changes made
513- // / to the constraint graph.
514- ConstraintGraphScope *ActiveScope = nullptr ;
515-
516- // / The set of changes made to this constraint graph.
517- // /
518- // / As the constraint graph is extended and mutated, additional changes are
519- // / introduced into this vector. Each scope
520- llvm::SmallVector<Change, 4 > Changes;
521-
522- friend class ConstraintGraphScope ;
459+ friend class SolverTrail ;
523460};
524461
525462} // end namespace constraints
0 commit comments