Skip to content

Commit 974817d

Browse files
committed
when pop skol, also remove from proj cache
1 parent da5b646 commit 974817d

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

src/librustc/infer/higher_ranked/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -839,5 +839,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
839839
debug!("pop_skolemized({:?})", skol_map);
840840
let skol_regions: FnvHashSet<_> = skol_map.values().cloned().collect();
841841
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
842+
self.projection_cache.borrow_mut().partial_rollback(&snapshot.projection_cache_snapshot);
842843
}
843844
}

src/librustc/traits/project.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
167167
infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot);
168168

169169
let skol_obligation = obligation.with(skol_predicate);
170-
match project_and_unify_type(selcx, &skol_obligation) {
170+
let r = match project_and_unify_type(selcx, &skol_obligation) {
171171
Ok(result) => {
172172
let span = obligation.cause.span;
173173
match infcx.leak_check(false, span, &skol_map, snapshot) {
@@ -178,7 +178,9 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
178178
Err(e) => {
179179
Err(e)
180180
}
181-
}
181+
};
182+
183+
r
182184
})
183185
}
184186

@@ -1396,6 +1398,10 @@ impl<'tcx> ProjectionCache<'tcx> {
13961398
self.map.rollback_to(snapshot.snapshot);
13971399
}
13981400

1401+
pub fn partial_rollback(&mut self, snapshot: &ProjectionCacheSnapshot) {
1402+
self.map.partial_rollback(&snapshot.snapshot);
1403+
}
1404+
13991405
pub fn commit(&mut self, snapshot: ProjectionCacheSnapshot) {
14001406
self.map.commit(snapshot.snapshot);
14011407
}

src/librustc_data_structures/snapshot_map/mod.rs

+42-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use fnv::FnvHashMap;
1212
use std::hash::Hash;
1313
use std::ops;
14+
use std::mem;
1415

1516
#[cfg(test)]
1617
mod test;
@@ -31,6 +32,7 @@ enum UndoLog<K, V> {
3132
CommittedSnapshot,
3233
Inserted(K),
3334
Overwrite(K, V),
35+
Noop,
3436
}
3537

3638
impl<K, V> SnapshotMap<K, V>
@@ -100,24 +102,29 @@ impl<K, V> SnapshotMap<K, V>
100102
}
101103
}
102104

105+
pub fn partial_rollback(&mut self, snapshot: &Snapshot) {
106+
self.assert_open_snapshot(snapshot);
107+
for i in (snapshot.len + 1..self.undo_log.len()).rev() {
108+
let reverse = match self.undo_log[i] {
109+
UndoLog::OpenSnapshot => false,
110+
UndoLog::CommittedSnapshot => false,
111+
UndoLog::Noop => false,
112+
UndoLog::Inserted(..) => true,
113+
UndoLog::Overwrite(..) => true,
114+
};
115+
116+
if reverse {
117+
let entry = mem::replace(&mut self.undo_log[i], UndoLog::Noop);
118+
self.reverse(entry);
119+
}
120+
}
121+
}
122+
103123
pub fn rollback_to(&mut self, snapshot: Snapshot) {
104124
self.assert_open_snapshot(&snapshot);
105125
while self.undo_log.len() > snapshot.len + 1 {
106-
match self.undo_log.pop().unwrap() {
107-
UndoLog::OpenSnapshot => {
108-
panic!("cannot rollback an uncommitted snapshot");
109-
}
110-
111-
UndoLog::CommittedSnapshot => {}
112-
113-
UndoLog::Inserted(key) => {
114-
self.map.remove(&key);
115-
}
116-
117-
UndoLog::Overwrite(key, old_value) => {
118-
self.map.insert(key, old_value);
119-
}
120-
}
126+
let entry = self.undo_log.pop().unwrap();
127+
self.reverse(entry);
121128
}
122129

123130
let v = self.undo_log.pop().unwrap();
@@ -127,6 +134,26 @@ impl<K, V> SnapshotMap<K, V>
127134
});
128135
assert!(self.undo_log.len() == snapshot.len);
129136
}
137+
138+
fn reverse(&mut self, entry: UndoLog<K, V>) {
139+
match entry {
140+
UndoLog::OpenSnapshot => {
141+
panic!("cannot rollback an uncommitted snapshot");
142+
}
143+
144+
UndoLog::CommittedSnapshot => {}
145+
146+
UndoLog::Inserted(key) => {
147+
self.map.remove(&key);
148+
}
149+
150+
UndoLog::Overwrite(key, old_value) => {
151+
self.map.insert(key, old_value);
152+
}
153+
154+
UndoLog::Noop => {}
155+
}
156+
}
130157
}
131158

132159
impl<'k, K, V> ops::Index<&'k K> for SnapshotMap<K, V>

0 commit comments

Comments
 (0)