1717#ifndef SWIFT_SEMA_CSTRAIL_H
1818#define SWIFT_SEMA_CSTRAIL_H
1919
20+ #include " swift/AST/AnyFunctionRef.h"
21+ #include " swift/AST/Type.h"
22+ #include " swift/AST/Types.h"
2023#include < vector>
2124
2225namespace llvm {
@@ -31,53 +34,18 @@ class TypeVariableType;
3134namespace constraints {
3235
3336class Constraint ;
37+ struct SyntacticElementTargetKey ;
3438
3539class SolverTrail {
3640public:
3741
3842 // / The kind of change made to the graph.
3943 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
8149 };
8250
8351 // / A change made to the constraint system.
@@ -135,91 +103,131 @@ class SolverTrail {
135103 Type DstType;
136104 } Restriction;
137105
138- ConstraintFix *Fix;
139106
140107 struct {
141108 GenericTypeParamType *GP;
142109 Type ReqTy;
143110 } FixedRequirement;
144111
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;
148138 };
149139
150140 Change () : Kind(ChangeKind::AddedTypeVariable), TypeVar(nullptr ) { }
151141
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+
152147 // / Create a change that added a type variable.
153- static Change addedTypeVariable (TypeVariableType *typeVar);
148+ static Change AddedTypeVariable (TypeVariableType *typeVar);
154149
155150 // / Create a change that added a constraint.
156- static Change addedConstraint (TypeVariableType *typeVar, Constraint *constraint);
151+ static Change AddedConstraint (TypeVariableType *typeVar, Constraint *constraint);
157152
158153 // / Create a change that removed a constraint.
159- static Change removedConstraint (TypeVariableType *typeVar, Constraint *constraint);
154+ static Change RemovedConstraint (TypeVariableType *typeVar, Constraint *constraint);
160155
161156 // / Create a change that extended an equivalence class.
162- static Change extendedEquivalenceClass (TypeVariableType *typeVar,
157+ static Change ExtendedEquivalenceClass (TypeVariableType *typeVar,
163158 unsigned prevSize);
164159
165160 // / Create a change that updated the references/referenced by sets of
166161 // / a type variable pair.
167- static Change relatedTypeVariables (TypeVariableType *typeVar,
162+ static Change RelatedTypeVariables (TypeVariableType *typeVar,
168163 TypeVariableType *otherTypeVar);
169164
170165 // / Create a change that inferred bindings from a constraint.
171- static Change inferredBindings (TypeVariableType *typeVar,
166+ static Change InferredBindings (TypeVariableType *typeVar,
172167 Constraint *constraint);
173168
174169 // / Create a change that retracted bindings from a constraint.
175- static Change retractedBindings (TypeVariableType *typeVar,
170+ static Change RetractedBindings (TypeVariableType *typeVar,
176171 Constraint *constraint);
177172
178173 // / Create a change that updated a type variable.
179- static Change updatedTypeVariable (
174+ static Change UpdatedTypeVariable (
180175 TypeVariableType *typeVar,
181176 llvm::PointerUnion<TypeVariableType *, TypeBase *> parentOrFixed,
182177 unsigned options);
183178
184179 // / Create a change that recorded a restriction.
185- static Change addedConversionRestriction (Type srcType, Type dstType);
180+ static Change AddedConversionRestriction (Type srcType, Type dstType);
186181
187182 // / Create a change that recorded a fix.
188- static Change addedFix (ConstraintFix *fix);
183+ static Change AddedFix (ConstraintFix *fix);
189184
190185 // / Create a change that recorded a fixed requirement.
191- static Change addedFixedRequirement (GenericTypeParamType *GP,
186+ static Change AddedFixedRequirement (GenericTypeParamType *GP,
192187 unsigned reqKind,
193188 Type requirementTy);
194189
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);
198192
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);
201196
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 );
204199
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);
207204
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 );
210207
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 );
213210
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 );
216213
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);
220222
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);
223231
224232 // / Undo this change, reverting the constraint graph to the state it
225233 // / had prior to this change.
@@ -229,9 +237,12 @@ class SolverTrail {
229237
230238 void dump (llvm::raw_ostream &out, ConstraintSystem &cs,
231239 unsigned indent = 0 ) const ;
240+
241+ private:
242+ SyntacticElementTargetKey getSyntacticElementTargetKey () const ;
232243 };
233244
234- SolverTrail (ConstraintSystem &cs) : CS(cs) {}
245+ SolverTrail (ConstraintSystem &cs);
235246
236247 ~SolverTrail ();
237248
@@ -258,6 +269,8 @@ class SolverTrail {
258269 // / The list of changes made to this constraint system.
259270 std::vector<Change> Changes;
260271
272+ uint64_t Profile[unsigned (ChangeKind::Last) + 1 ];
273+
261274 bool UndoActive = false ;
262275 unsigned Total = 0 ;
263276 unsigned Max = 0 ;
0 commit comments