@@ -42,7 +42,6 @@ namespace constraints {
42
42
43
43
class Constraint ;
44
44
class ConstraintGraph ;
45
- class ConstraintGraphScope ;
46
45
class ConstraintSystem ;
47
46
class TypeVariableBinding ;
48
47
@@ -58,6 +57,13 @@ class ConstraintGraphNode {
58
57
// / Retrieve the type variable this node represents.
59
58
TypeVariableType *getTypeVariable () const { return TypeVar; }
60
59
60
+ void reset ();
61
+
62
+ void initTypeVariable (TypeVariableType *typeVar) {
63
+ ASSERT (!TypeVar);
64
+ TypeVar = typeVar;
65
+ }
66
+
61
67
// / Retrieve the set of constraints that mention this type variable.
62
68
// /
63
69
// / These are the hyperedges of the graph, connecting this node to
@@ -148,9 +154,7 @@ class ConstraintGraphNode {
148
154
void introduceToInference (Type fixedType);
149
155
150
156
// / Opposite of \c introduceToInference(Type)
151
- void
152
- retractFromInference (Type fixedType,
153
- SmallPtrSetImpl<TypeVariableType *> &referencedVars);
157
+ void retractFromInference (Type fixedType);
154
158
155
159
// / Drop all previously collected bindings and re-infer based on the
156
160
// / current set constraints associated with this equivalence class.
@@ -216,6 +220,7 @@ class ConstraintGraphNode {
216
220
friend class ConstraintGraph ;
217
221
friend class ConstraintSystem ;
218
222
friend class TypeVariableBinding ;
223
+ friend class SolverTrail ;
219
224
};
220
225
221
226
// / A graph that describes the relationships among the various type variables
@@ -266,6 +271,9 @@ class ConstraintGraph {
266
271
// / Bind the given type variable to the given fixed type.
267
272
void bindTypeVariable (TypeVariableType *typeVar, Type fixedType);
268
273
274
+ // / Introduce the type variable's fixed type to inference.
275
+ void introduceToInference (TypeVariableType *typeVar, Type fixedType);
276
+
269
277
// / Describes which constraints \c gatherConstraints should gather.
270
278
enum class GatheringKind {
271
279
// / Gather constraints associated with all of the variables within the
@@ -387,7 +395,6 @@ class ConstraintGraph {
387
395
// / Print the graph.
388
396
void print (ArrayRef<TypeVariableType *> typeVars, llvm::raw_ostream &out);
389
397
void dump (llvm::raw_ostream &out);
390
- void dumpActiveScopeChanges (llvm::raw_ostream &out, unsigned indent = 0 );
391
398
392
399
// FIXME: Potentially side-effectful.
393
400
SWIFT_DEBUG_HELPER (void dump ());
@@ -423,6 +430,12 @@ class ConstraintGraph {
423
430
// / caution.
424
431
void unbindTypeVariable (TypeVariableType *typeVar, Type fixedType);
425
432
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
+
426
439
// / Perform edge contraction on the constraint graph, merging equivalence
427
440
// / classes until a fixed point is reached.
428
441
bool contractEdges ();
@@ -436,90 +449,14 @@ class ConstraintGraph {
436
449
// / Constraints that are "orphaned" because they contain no type variables.
437
450
SmallVector<Constraint *, 4 > OrphanedConstraints;
438
451
452
+ // / Unused nodes.
453
+ SmallVector<ConstraintGraphNode *> FreeList;
454
+
439
455
// / Increment the number of constraints considered per attempt
440
456
// / to contract constraint graph edges.
441
457
void incrementConstraintsPerContractionCounter ();
442
458
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 ;
523
460
};
524
461
525
462
} // end namespace constraints
0 commit comments