21
21
#include " swift/Basic/LLVM.h"
22
22
#include " swift/AST/Identifier.h"
23
23
#include " swift/AST/Type.h"
24
+ #include " swift/Sema/CSBindings.h"
24
25
#include " llvm/ADT/ArrayRef.h"
25
26
#include " llvm/ADT/DenseSet.h"
26
27
#include " llvm/ADT/DenseMap.h"
@@ -47,7 +48,8 @@ class ConstraintSystem;
47
48
// / A single node in the constraint graph, which represents a type variable.
48
49
class ConstraintGraphNode {
49
50
public:
50
- explicit ConstraintGraphNode (TypeVariableType *typeVar) : TypeVar(typeVar) { }
51
+ explicit ConstraintGraphNode (ConstraintGraph &CG, TypeVariableType *typeVar)
52
+ : CG(CG), TypeVar(typeVar) {}
51
53
52
54
ConstraintGraphNode (const ConstraintGraphNode&) = delete ;
53
55
ConstraintGraphNode &operator =(const ConstraintGraphNode&) = delete ;
@@ -75,6 +77,8 @@ class ConstraintGraphNode {
75
77
// / as this type variable.
76
78
ArrayRef<TypeVariableType *> getEquivalenceClass () const ;
77
79
80
+ inference::PotentialBindings &getCurrentBindings ();
81
+
78
82
private:
79
83
// / Determines whether the type variable associated with this node
80
84
// / is a representative of an equivalence class.
@@ -98,6 +102,9 @@ class ConstraintGraphNode {
98
102
// / Add the given type variables to this node's equivalence class.
99
103
void addToEquivalenceClass (ArrayRef<TypeVariableType *> typeVars);
100
104
105
+ // / Remove N last members from equivalence class of the current type variable.
106
+ void truncateEquivalenceClass (unsigned prevSize);
107
+
101
108
// / Add a type variable related to this type variable through fixed
102
109
// / binding.
103
110
void addReferencedVar (TypeVariableType *typeVar);
@@ -112,9 +119,46 @@ class ConstraintGraphNode {
112
119
// / Remove a type variable which used to reference this type variable.
113
120
void removeReferencedBy (TypeVariableType *typeVar);
114
121
122
+ // / Binding Inference {
123
+
124
+ // / Infer bindings from the given constraint and notify referenced variables
125
+ // / about its arrival (if requested). This happens every time a new constraint
126
+ // / gets added to a constraint graph node.
127
+ void introduceToInference (Constraint *constraint, bool notifyReferencedVars);
128
+
129
+ // / Forget about the given constraint. This happens every time a constraint
130
+ // / gets removed for a constraint graph.
131
+ void retractFromInference (Constraint *constraint, bool notifyReferencedVars);
132
+
133
+ // / Re-evaluate the given constraint. This happens when there are changes
134
+ // / in associated type variables e.g. bound/unbound to/from a fixed type,
135
+ // / equivalence class changes.
136
+ void reintroduceToInference (Constraint *constraint, bool notifyReferencedVars);
137
+
138
+ // / Drop all previously collected bindings and re-infer based on the
139
+ // / current set constraints associated with this equivalence class.
140
+ void resetBindingSet ();
141
+
142
+ // / Notify all of the type variables that have this one (or any member of
143
+ // / its equivalence class) referenced in their fixed type.
144
+ // /
145
+ // / This is a traversal up the reference change which triggers constraint
146
+ // / re-introduction to affected type variables.
147
+ // /
148
+ // / This is useful in situations when type variable gets bound and unbound,
149
+ // / or equivalence class changes.
150
+ void notifyReferencingVars () const ;
151
+ // / }
152
+
153
+ // / The constraint graph this node belongs to.
154
+ ConstraintGraph &CG;
155
+
115
156
// / The type variable this node represents.
116
157
TypeVariableType *TypeVar;
117
158
159
+ // / The set of bindings associated with this type variable.
160
+ llvm::Optional<inference::PotentialBindings> Bindings;
161
+
118
162
// / The vector of constraints that mention this type variable, in a stable
119
163
// / order for iteration.
120
164
SmallVector<Constraint *, 2 > Constraints;
0 commit comments