17
17
#ifndef SWIFT_SEMA_CSTRAIL_H
18
18
#define SWIFT_SEMA_CSTRAIL_H
19
19
20
+ #include " swift/AST/AnyFunctionRef.h"
21
+ #include " swift/AST/Type.h"
22
+ #include " swift/AST/Types.h"
20
23
#include < vector>
21
24
22
25
namespace llvm {
@@ -31,53 +34,18 @@ class TypeVariableType;
31
34
namespace constraints {
32
35
33
36
class Constraint ;
37
+ struct SyntacticElementTargetKey ;
34
38
35
39
class SolverTrail {
36
40
public:
37
41
38
42
// / The kind of change made to the graph.
39
43
enum class ChangeKind : unsigned {
40
- // / Added a new vertex to the constraint graph.
41
- AddedTypeVariable,
42
- // / Added a new constraint to the constraint graph.
43
- AddedConstraint,
44
- // / Removed an existing constraint from the constraint graph.
45
- RemovedConstraint,
46
- // / Extended the equivalence class of a type variable in the constraint graph.
47
- ExtendedEquivalenceClass,
48
- // / Added a new edge in the constraint graph.
49
- RelatedTypeVariables,
50
- // / Inferred potential bindings from a constraint.
51
- InferredBindings,
52
- // / Retracted potential bindings from a constraint.
53
- RetractedBindings,
54
- // / Set the fixed type or parent and flags for a type variable.
55
- UpdatedTypeVariable,
56
- // / Recorded a conversion restriction kind.
57
- AddedConversionRestriction,
58
- // / Recorded a fix.
59
- AddedFix,
60
- // / Recorded a fixed requirement.
61
- AddedFixedRequirement,
62
- // / Recorded a disjunction choice.
63
- RecordedDisjunctionChoice,
64
- // / Recorded an applied disjunction.
65
- RecordedAppliedDisjunction,
66
- // / Recorded an argument matching choice.
67
- RecordedMatchCallArgumentResult,
68
- // / Recorded a list of opened types at a locator.
69
- RecordedOpenedTypes,
70
- // / Recorded the opening of an existential type at a locator.
71
- RecordedOpenedExistentialType,
72
- // / Recorded the opening of a pack existential type.
73
- RecordedOpenedPackExpansionType,
74
- // / Recorded the creation of a generic environment for a pack expansion expression.
75
- RecordedPackExpansionEnvironment,
76
- // / Recorded the mapping from a pack element expression to its parent
77
- // / pack expansion expression.
78
- RecordedPackEnvironment,
79
- // / Record a defaulted constraint at a locator.
80
- RecordedDefaultedConstraint,
44
+ #define CHANGE (Name ) Name,
45
+ #define LAST_CHANGE (Name ) Last = Name
46
+ #include " CSTrail.def"
47
+ #undef CHANGE
48
+ #undef LAST_CHANGE
81
49
};
82
50
83
51
// / A change made to the constraint system.
@@ -135,91 +103,131 @@ class SolverTrail {
135
103
Type DstType;
136
104
} Restriction;
137
105
138
- ConstraintFix *Fix;
139
106
140
107
struct {
141
108
GenericTypeParamType *GP;
142
109
Type ReqTy;
143
110
} FixedRequirement;
144
111
145
- ConstraintLocator *Locator;
146
- PackExpansionType *ExpansionTy;
147
- PackElementExpr *ElementExpr;
112
+ struct {
113
+ ASTNode Node;
114
+ Type OldType;
115
+ } Node;
116
+
117
+ struct {
118
+ const KeyPathExpr *Expr;
119
+ Type OldType;
120
+ } KeyPath;
121
+
122
+ ConstraintFix *TheFix;
123
+ ConstraintLocator *TheLocator;
124
+ PackExpansionType *TheExpansion;
125
+ PackElementExpr *TheElement;
126
+ Expr *TheExpr;
127
+ Stmt *TheStmt;
128
+ StmtConditionElement *TheCondElt;
129
+ Pattern *ThePattern;
130
+ PatternBindingDecl *ThePatternBinding;
131
+ VarDecl *TheVar;
132
+ AnyFunctionRef TheRef;
133
+ ClosureExpr *TheClosure;
134
+ DeclContext *TheDeclContext;
135
+ CaseLabelItem *TheItem;
136
+ CatchNode TheCatchNode;
137
+ ParamDecl *TheParam;
148
138
};
149
139
150
140
Change () : Kind(ChangeKind::AddedTypeVariable), TypeVar(nullptr ) { }
151
141
142
+ #define LOCATOR_CHANGE (Name, _ ) static Change Name (ConstraintLocator *locator);
143
+ #define EXPR_CHANGE (Name ) static Change Name (Expr *expr);
144
+ #define CLOSURE_CHANGE (Name ) static Change Name (ClosureExpr *closure);
145
+ #include " swift/Sema/CSTrail.def"
146
+
152
147
// / Create a change that added a type variable.
153
- static Change addedTypeVariable (TypeVariableType *typeVar);
148
+ static Change AddedTypeVariable (TypeVariableType *typeVar);
154
149
155
150
// / Create a change that added a constraint.
156
- static Change addedConstraint (TypeVariableType *typeVar, Constraint *constraint);
151
+ static Change AddedConstraint (TypeVariableType *typeVar, Constraint *constraint);
157
152
158
153
// / Create a change that removed a constraint.
159
- static Change removedConstraint (TypeVariableType *typeVar, Constraint *constraint);
154
+ static Change RemovedConstraint (TypeVariableType *typeVar, Constraint *constraint);
160
155
161
156
// / Create a change that extended an equivalence class.
162
- static Change extendedEquivalenceClass (TypeVariableType *typeVar,
157
+ static Change ExtendedEquivalenceClass (TypeVariableType *typeVar,
163
158
unsigned prevSize);
164
159
165
160
// / Create a change that updated the references/referenced by sets of
166
161
// / a type variable pair.
167
- static Change relatedTypeVariables (TypeVariableType *typeVar,
162
+ static Change RelatedTypeVariables (TypeVariableType *typeVar,
168
163
TypeVariableType *otherTypeVar);
169
164
170
165
// / Create a change that inferred bindings from a constraint.
171
- static Change inferredBindings (TypeVariableType *typeVar,
166
+ static Change InferredBindings (TypeVariableType *typeVar,
172
167
Constraint *constraint);
173
168
174
169
// / Create a change that retracted bindings from a constraint.
175
- static Change retractedBindings (TypeVariableType *typeVar,
170
+ static Change RetractedBindings (TypeVariableType *typeVar,
176
171
Constraint *constraint);
177
172
178
173
// / Create a change that updated a type variable.
179
- static Change updatedTypeVariable (
174
+ static Change UpdatedTypeVariable (
180
175
TypeVariableType *typeVar,
181
176
llvm::PointerUnion<TypeVariableType *, TypeBase *> parentOrFixed,
182
177
unsigned options);
183
178
184
179
// / Create a change that recorded a restriction.
185
- static Change addedConversionRestriction (Type srcType, Type dstType);
180
+ static Change AddedConversionRestriction (Type srcType, Type dstType);
186
181
187
182
// / Create a change that recorded a fix.
188
- static Change addedFix (ConstraintFix *fix);
183
+ static Change AddedFix (ConstraintFix *fix);
189
184
190
185
// / Create a change that recorded a fixed requirement.
191
- static Change addedFixedRequirement (GenericTypeParamType *GP,
186
+ static Change AddedFixedRequirement (GenericTypeParamType *GP,
192
187
unsigned reqKind,
193
188
Type requirementTy);
194
189
195
- // / Create a change that recorded a disjunction choice.
196
- static Change recordedDisjunctionChoice (ConstraintLocator *locator,
197
- unsigned index);
190
+ // / Create a change that recorded the opening of a pack expansion type.
191
+ static Change RecordedOpenedPackExpansionType (PackExpansionType *expansion);
198
192
199
- // / Create a change that recorded an applied disjunction.
200
- static Change recordedAppliedDisjunction (ConstraintLocator *locator);
193
+ // / Create a change that recorded a mapping from a pack element expression
194
+ // / to its parent expansion expression.
195
+ static Change RecordedPackEnvironment (PackElementExpr *packElement);
201
196
202
- // / Create a change that recorded an applied disjunction .
203
- static Change recordedMatchCallArgumentResult (ConstraintLocator *locator );
197
+ // / Create a change that recorded an assignment of a type to an AST node .
198
+ static Change RecordedNodeType (ASTNode node, Type oldType );
204
199
205
- // / Create a change that recorded a list of opened types.
206
- static Change recordedOpenedTypes (ConstraintLocator *locator);
200
+ // / Create a change that recorded an assignment of a type to an AST node.
201
+ static Change RecordedKeyPathComponentType (const KeyPathExpr *expr,
202
+ unsigned component,
203
+ Type oldType);
207
204
208
- // / Create a change that recorded the opening of an existential type .
209
- static Change recordedOpenedExistentialType (ConstraintLocator *locator );
205
+ // / Create a change that disabled a constraint .
206
+ static Change DisabledConstraint (Constraint *constraint );
210
207
211
- // / Create a change that recorded the opening of a pack expansion type .
212
- static Change recordedOpenedPackExpansionType (PackExpansionType *expansion );
208
+ // / Create a change that favored a constraint .
209
+ static Change FavoredConstraint (Constraint *constraint );
213
210
214
- // / Create a change that recorded the opening of a pack expansion type .
215
- static Change recordedPackExpansionEnvironment (ConstraintLocator *locator );
211
+ // / Create a change that recorded a result builder transform .
212
+ static Change RecordedResultBuilderTransform (AnyFunctionRef fn );
216
213
217
- // / Create a change that recorded a mapping from a pack element expression
218
- // / to its parent expansion expression.
219
- static Change recordedPackEnvironment (PackElementExpr *packElement);
214
+ // / Create a change that recorded the contextual type of an AST node.
215
+ static Change RecordedContextualInfo (ASTNode node);
216
+
217
+ // / Create a change that recorded a SyntacticElementTarget.
218
+ static Change RecordedTarget (SyntacticElementTargetKey key);
219
+
220
+ // / Create a change that recorded a SyntacticElementTarget.
221
+ static Change RecordedCaseLabelItemInfo (CaseLabelItem *item);
220
222
221
- // / Create a change that recorded a defaulted constraint at a locator.
222
- static Change recordedDefaultedConstraint (ConstraintLocator *locator);
223
+ // / Create a change that recorded a potential throw site.
224
+ static Change RecordedPotentialThrowSite (CatchNode catchNode);
225
+
226
+ // / Create a change that recorded an isolated parameter.
227
+ static Change RecordedIsolatedParam (ParamDecl *param);
228
+
229
+ // / Create a change that recorded a key path expression.
230
+ static Change RecordedKeyPath (KeyPathExpr *expr);
223
231
224
232
// / Undo this change, reverting the constraint graph to the state it
225
233
// / had prior to this change.
@@ -229,9 +237,12 @@ class SolverTrail {
229
237
230
238
void dump (llvm::raw_ostream &out, ConstraintSystem &cs,
231
239
unsigned indent = 0 ) const ;
240
+
241
+ private:
242
+ SyntacticElementTargetKey getSyntacticElementTargetKey () const ;
232
243
};
233
244
234
- SolverTrail (ConstraintSystem &cs) : CS(cs) {}
245
+ SolverTrail (ConstraintSystem &cs);
235
246
236
247
~SolverTrail ();
237
248
@@ -258,6 +269,8 @@ class SolverTrail {
258
269
// / The list of changes made to this constraint system.
259
270
std::vector<Change> Changes;
260
271
272
+ uint64_t Profile[unsigned (ChangeKind::Last) + 1 ];
273
+
261
274
bool UndoActive = false ;
262
275
unsigned Total = 0 ;
263
276
unsigned Max = 0 ;
0 commit comments