Skip to content

Commit da19783

Browse files
committed
Introduce in_snapshot and assert_open_snapshot methods.
This makes the two snapshot implementations more consistent with each other and with crate `ena`.
1 parent c430f98 commit da19783

File tree

2 files changed

+14
-7
lines changed
  • src
    • librustc/infer/region_constraints
    • librustc_data_structures/snapshot_map

2 files changed

+14
-7
lines changed

src/librustc/infer/region_constraints/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,14 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
429429
}
430430
}
431431

432-
pub fn commit(&mut self, snapshot: RegionSnapshot) {
433-
debug!("RegionConstraintCollector: commit({})", snapshot.length);
432+
fn assert_open_snapshot(&self, snapshot: &RegionSnapshot) {
434433
assert!(self.undo_log.len() > snapshot.length);
435434
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
435+
}
436+
437+
pub fn commit(&mut self, snapshot: RegionSnapshot) {
438+
debug!("RegionConstraintCollector: commit({})", snapshot.length);
439+
self.assert_open_snapshot(&snapshot);
436440

437441
if snapshot.length == 0 {
438442
self.undo_log.clear();
@@ -444,8 +448,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
444448

445449
pub fn rollback_to(&mut self, snapshot: RegionSnapshot) {
446450
debug!("RegionConstraintCollector: rollback_to({:?})", snapshot);
447-
assert!(self.undo_log.len() > snapshot.length);
448-
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
451+
self.assert_open_snapshot(&snapshot);
449452
while self.undo_log.len() > snapshot.length + 1 {
450453
let undo_entry = self.undo_log.pop().unwrap();
451454
self.rollback_undo_entry(undo_entry);

src/librustc_data_structures/snapshot_map/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ impl<K, V> SnapshotMap<K, V>
5555
self.undo_log.clear();
5656
}
5757

58+
fn in_snapshot(&self) -> bool {
59+
!self.undo_log.is_empty()
60+
}
61+
5862
pub fn insert(&mut self, key: K, value: V) -> bool {
5963
match self.map.insert(key.clone(), value) {
6064
None => {
61-
if !self.undo_log.is_empty() {
65+
if self.in_snapshot() {
6266
self.undo_log.push(UndoLog::Inserted(key));
6367
}
6468
true
6569
}
6670
Some(old_value) => {
67-
if !self.undo_log.is_empty() {
71+
if self.in_snapshot() {
6872
self.undo_log.push(UndoLog::Overwrite(key, old_value));
6973
}
7074
false
@@ -75,7 +79,7 @@ impl<K, V> SnapshotMap<K, V>
7579
pub fn remove(&mut self, key: K) -> bool {
7680
match self.map.remove(&key) {
7781
Some(old_value) => {
78-
if !self.undo_log.is_empty() {
82+
if self.in_snapshot() {
7983
self.undo_log.push(UndoLog::Overwrite(key, old_value));
8084
}
8185
true

0 commit comments

Comments
 (0)