Skip to content

Commit 4548880

Browse files
committed
Sema: Add LLVM_DEBUGs to CSTrail.cpp
1 parent e70d0bc commit 4548880

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/swift/Sema/CSTrail.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class SolverTrail {
159159
std::vector<Change> Changes;
160160

161161
bool UndoActive = false;
162+
unsigned Total = 0;
163+
unsigned Max = 0;
162164
};
163165

164166
} // namespace constraints

lib/Sema/CSTrail.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,14 @@ void SolverTrail::Change::dump(llvm::raw_ostream &out,
216216
}
217217

218218
void SolverTrail::recordChange(Change change) {
219+
LLVM_DEBUG(llvm::dbgs() << "+ "; change.dump(llvm::dbgs(), CS, 0););
219220
ASSERT(!UndoActive);
221+
220222
Changes.push_back(change);
223+
224+
++Total;
225+
if (Changes.size() > Max)
226+
Max = Changes.size();
221227
}
222228

223229
void SolverTrail::undo(unsigned toIndex) {
@@ -226,20 +232,28 @@ void SolverTrail::undo(unsigned toIndex) {
226232
if (CS.inInvalidState())
227233
return;
228234

235+
LLVM_DEBUG(llvm::dbgs() << "decisions " << Changes.size()
236+
<< " max " << Max
237+
<< " total " << Total << "\n");
229238
ASSERT(Changes.size() >= toIndex && "Trail corrupted");
230239
ASSERT(!UndoActive);
231240
UndoActive = true;
232241

242+
// FIXME: Undo all changes in the correct order!
233243
for (unsigned i = Changes.size(); i > toIndex; i--) {
234244
auto change = Changes[i - 1];
235-
if (change.Kind == ChangeKind::UpdatedTypeVariable)
245+
if (change.Kind == ChangeKind::UpdatedTypeVariable) {
246+
LLVM_DEBUG(llvm::dbgs() << "- "; change.dump(llvm::dbgs(), CS, 0));
236247
change.undo(CS);
248+
}
237249
}
238250

239251
for (unsigned i = Changes.size(); i > toIndex; i--) {
240252
auto change = Changes[i - 1];
241-
if (change.Kind != ChangeKind::UpdatedTypeVariable)
253+
if (change.Kind != ChangeKind::UpdatedTypeVariable) {
254+
LLVM_DEBUG(llvm::dbgs() << "- "; change.dump(llvm::dbgs(), CS, 0));
242255
change.undo(CS);
256+
}
243257
}
244258

245259
Changes.resize(toIndex);

0 commit comments

Comments
 (0)