@@ -98,7 +98,7 @@ SolverTrail::Change::updatedTypeVariable(
98
98
return result;
99
99
}
100
100
101
- void SolverTrail::Change::undo (ConstraintSystem &cs) {
101
+ void SolverTrail::Change::undo (ConstraintSystem &cs) const {
102
102
auto &cg = cs.getConstraintGraph ();
103
103
104
104
switch (Kind) {
@@ -131,6 +131,68 @@ void SolverTrail::Change::undo(ConstraintSystem &cs) {
131
131
}
132
132
}
133
133
134
+ void SolverTrail::Change::dump (llvm::raw_ostream &out,
135
+ ConstraintSystem &cs,
136
+ unsigned indent) const {
137
+ PrintOptions PO;
138
+ PO.PrintTypesForDebugging = true ;
139
+
140
+ out.indent (indent);
141
+
142
+ switch (Kind) {
143
+ case ChangeKind::AddedTypeVariable:
144
+ out << " (added type variable " ;
145
+ TypeVar->print (out, PO);
146
+ out << " )\n " ;
147
+ break ;
148
+
149
+ case ChangeKind::AddedConstraint:
150
+ out << " (added constraint " ;
151
+ TheConstraint->print (out, &cs.getASTContext ().SourceMgr , indent + 2 );
152
+ out << " )\n " ;
153
+ break ;
154
+
155
+ case ChangeKind::RemovedConstraint:
156
+ out << " (removed constraint " ;
157
+ TheConstraint->print (out, &cs.getASTContext ().SourceMgr , indent + 2 );
158
+ out << " )\n " ;
159
+ break ;
160
+
161
+ case ChangeKind::ExtendedEquivalenceClass: {
162
+ out << " (equivalence " ;
163
+ EquivClass.TypeVar ->print (out, PO);
164
+ out << " " << EquivClass.PrevSize << " )\n " ;
165
+ break ;
166
+ }
167
+
168
+ case ChangeKind::BoundTypeVariable:
169
+ out << " (bound type variable " ;
170
+ Binding.TypeVar ->print (out, PO);
171
+ out << " to fixed type " ;
172
+ Binding.FixedType ->print (out, PO);
173
+ out << " )\n " ;
174
+ break ;
175
+
176
+ case ChangeKind::UpdatedTypeVariable:
177
+ out << " (updated type variable " ;
178
+ Update.TypeVar ->print (out, PO);
179
+
180
+ auto parentOrFixed = Update.TypeVar ->getImpl ().ParentOrFixed ;
181
+ if (auto *parent = parentOrFixed.dyn_cast <TypeVariableType *>()) {
182
+ out << " to parent " ;
183
+ parent->print (out, PO);
184
+ }
185
+ else {
186
+ out << " to fixed type " ;
187
+ parentOrFixed.get <TypeBase *>()->print (out, PO);
188
+ }
189
+ out << " with options 0x" ;
190
+ out.write_hex (Update.Options );
191
+ out << " )\n " ;
192
+ break ;
193
+ }
194
+ }
195
+
134
196
void SolverTrail::recordChange (Change change) {
135
197
if (UndoActive)
136
198
return ;
@@ -166,121 +228,13 @@ void SolverTrail::undo(unsigned toIndex) {
166
228
167
229
void SolverTrail::dumpActiveScopeChanges (llvm::raw_ostream &out,
168
230
unsigned fromIndex,
169
- unsigned indent) {
170
- if (Changes.empty ())
171
- return ;
172
-
173
- // Collect Changes for printing.
174
- std::map<TypeVariableType *, TypeBase *> tvWithboundTypes;
175
- std::vector<TypeVariableType *> addedTypeVars;
176
- std::vector<TypeVariableType *> equivTypeVars;
177
- std::set<Constraint *> addedConstraints;
178
- std::set<Constraint *> removedConstraints;
179
- for (unsigned int i = fromIndex; i < Changes.size (); i++) {
180
- auto change = Changes[i];
181
- switch (change.Kind ) {
182
- case ChangeKind::BoundTypeVariable:
183
- tvWithboundTypes.insert (std::pair<TypeVariableType *, TypeBase *>(
184
- change.Binding .TypeVar , change.Binding .FixedType ));
185
- break ;
186
- case ChangeKind::AddedTypeVariable:
187
- addedTypeVars.push_back (change.TypeVar );
188
- break ;
189
- case ChangeKind::ExtendedEquivalenceClass:
190
- equivTypeVars.push_back (change.EquivClass .TypeVar );
191
- break ;
192
- case ChangeKind::AddedConstraint:
193
- addedConstraints.insert (change.TheConstraint );
194
- break ;
195
- case ChangeKind::RemovedConstraint:
196
- removedConstraints.insert (change.TheConstraint );
197
- break ;
198
- case ChangeKind::UpdatedTypeVariable:
199
- // Don't consider changes that don't affect the graph.
200
- break ;
201
- }
202
- }
231
+ unsigned indent) const {
232
+ out.indent (indent);
233
+ out << " (changes:\n " ;
203
234
204
- // If there are any constraints that were both added and removed in this set
205
- // of Changes, remove them from both.
206
- std::set<Constraint *> intersects;
207
- set_intersection (addedConstraints.begin (), addedConstraints.end (),
208
- removedConstraints.begin (), removedConstraints.end (),
209
- std::inserter (intersects, intersects.begin ()));
210
- llvm::set_subtract (addedConstraints, intersects);
211
- llvm::set_subtract (removedConstraints, intersects);
235
+ for (unsigned i = fromIndex; i < Changes.size (); ++i)
236
+ Changes[i].dump (out, CS, indent + 2 );
212
237
213
- // Print out Changes.
214
- PrintOptions PO;
215
- PO.PrintTypesForDebugging = true ;
216
- out.indent (indent);
217
- out << " (Changes:\n " ;
218
- if (!tvWithboundTypes.empty ()) {
219
- out.indent (indent + 2 );
220
- out << " (Newly Bound: \n " ;
221
- for (const auto &tvWithType : tvWithboundTypes) {
222
- out.indent (indent + 4 );
223
- out << " > $T" << tvWithType.first ->getImpl ().getID () << " := " ;
224
- tvWithType.second ->print (out, PO);
225
- out << ' \n ' ;
226
- }
227
- out.indent (indent + 2 );
228
- out << " )\n " ;
229
- }
230
- if (!addedTypeVars.empty ()) {
231
- out.indent (indent + 2 );
232
- auto heading = (addedTypeVars.size () > 1 ) ? " (New Type Variables: \n "
233
- : " (New Type Variable: \n " ;
234
- out << heading;
235
- for (const auto &typeVar : addedTypeVars) {
236
- out.indent (indent + 4 );
237
- out << " > $T" << typeVar->getImpl ().getID ();
238
- out << ' \n ' ;
239
- }
240
- out.indent (indent + 2 );
241
- out << " )\n " ;
242
- }
243
- if (!equivTypeVars.empty ()) {
244
- out.indent (indent + 2 );
245
- auto heading = (equivTypeVars.size () > 1 ) ? " (New Equivalences: \n "
246
- : " (New Equivalence: \n " ;
247
- out << heading;
248
- for (const auto &typeVar : equivTypeVars) {
249
- out.indent (indent + 4 );
250
- out << " > $T" << typeVar->getImpl ().getID ();
251
- out << ' \n ' ;
252
- }
253
- out.indent (indent + 2 );
254
- out << " )\n " ;
255
- }
256
- if (!addedConstraints.empty ()) {
257
- out.indent (indent + 2 );
258
- auto heading = (addedConstraints.size () > 1 ) ? " (Added Constraints: \n "
259
- : " (Added Constraint: \n " ;
260
- out << heading;
261
- for (const auto &constraint : addedConstraints) {
262
- out.indent (indent + 4 );
263
- out << " > " ;
264
- constraint->print (out, &CS.getASTContext ().SourceMgr , indent + 6 );
265
- out << ' \n ' ;
266
- }
267
- out.indent (indent + 2 );
268
- out << " )\n " ;
269
- }
270
- if (!removedConstraints.empty ()) {
271
- out.indent (indent + 2 );
272
- auto heading = (removedConstraints.size () > 1 ) ? " (Removed Constraints: \n "
273
- : " (Removed Constraint: \n " ;
274
- out << heading;
275
- for (const auto &constraint : removedConstraints) {
276
- out.indent (indent + 4 );
277
- out << " > " ;
278
- constraint->print (out, &CS.getASTContext ().SourceMgr , indent + 6 );
279
- out << ' \n ' ;
280
- }
281
- out.indent (indent + 2 );
282
- out << " )\n " ;
283
- }
284
238
out.indent (indent);
285
239
out << " )\n " ;
286
240
}
0 commit comments