Skip to content

Commit 0f08a69

Browse files
author
Markus Westerlind
committed
Clear the modified set once no snapshots exist
1 parent cd86ce1 commit 0f08a69

File tree

3 files changed

+15
-137
lines changed

3 files changed

+15
-137
lines changed

compiler/rustc_data_structures/src/logged_unification_table.rs

Lines changed: 3 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::{marker::PhantomData, ops::Range};
2-
31
use rustc_index::vec::Idx;
42

53
use crate::modified_set as ms;
64
use crate::snapshot_vec as sv;
75
use crate::unify as ut;
86
use crate::unify_log as ul;
97

10-
use ena::undo_log::{Rollback, Snapshots, UndoLogs};
8+
use ena::undo_log::{Rollback, UndoLogs};
119

1210
pub enum UndoLog<K: ut::UnifyKey, I = K> {
1311
Relation(sv::UndoLog<ut::Delegate<K>>),
@@ -33,44 +31,6 @@ impl<K: ut::UnifyKey, I> From<ms::Undo<I>> for UndoLog<K, I> {
3331
}
3432
}
3533

36-
struct Logs<K: ut::UnifyKey, I> {
37-
logs: Vec<UndoLog<K, I>>,
38-
num_open_snapshots: usize,
39-
}
40-
41-
impl<K: ut::UnifyKey, I> Default for Logs<K, I> {
42-
fn default() -> Self {
43-
Self { logs: Default::default(), num_open_snapshots: Default::default() }
44-
}
45-
}
46-
47-
impl<T, K: ut::UnifyKey, I> UndoLogs<T> for Logs<K, I>
48-
where
49-
UndoLog<K, I>: From<T>,
50-
{
51-
fn num_open_snapshots(&self) -> usize {
52-
self.num_open_snapshots
53-
}
54-
fn push(&mut self, undo: T) {
55-
if self.in_snapshot() {
56-
self.logs.push(undo.into())
57-
}
58-
}
59-
fn clear(&mut self) {
60-
self.logs.clear();
61-
self.num_open_snapshots = 0;
62-
}
63-
fn extend<J>(&mut self, undos: J)
64-
where
65-
Self: Sized,
66-
J: IntoIterator<Item = T>,
67-
{
68-
if self.in_snapshot() {
69-
self.logs.extend(undos.into_iter().map(UndoLog::from))
70-
}
71-
}
72-
}
73-
7434
impl<K: ut::UnifyKey, I: Idx> Rollback<UndoLog<K, I>> for LoggedUnificationTableStorage<K, I> {
7535
fn reverse(&mut self, undo: UndoLog<K, I>) {
7636
match undo {
@@ -81,64 +41,6 @@ impl<K: ut::UnifyKey, I: Idx> Rollback<UndoLog<K, I>> for LoggedUnificationTable
8141
}
8242
}
8343

84-
impl<K: ut::UnifyKey, I: Idx> Snapshots<UndoLog<K, I>> for Logs<K, I> {
85-
type Snapshot = Snapshot<K, I>;
86-
fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[UndoLog<K, I>] {
87-
&self.logs[snapshot.undo_len..]
88-
}
89-
90-
fn start_snapshot(&mut self) -> Self::Snapshot {
91-
unreachable!()
92-
}
93-
94-
fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
95-
where
96-
R: Rollback<UndoLog<K, I>>,
97-
{
98-
debug!("rollback_to({})", snapshot.undo_len);
99-
self.assert_open_snapshot(&snapshot);
100-
101-
if self.logs.len() > snapshot.undo_len {
102-
let mut values = values();
103-
while self.logs.len() > snapshot.undo_len {
104-
values.reverse(self.logs.pop().unwrap());
105-
}
106-
}
107-
108-
if self.num_open_snapshots == 1 {
109-
// The root snapshot. It's safe to clear the undo log because
110-
// there's no snapshot further out that we might need to roll back
111-
// to.
112-
assert!(snapshot.undo_len == 0);
113-
self.logs.clear();
114-
}
115-
116-
self.num_open_snapshots -= 1;
117-
}
118-
119-
fn commit(&mut self, snapshot: Self::Snapshot) {
120-
debug!("commit({})", snapshot.undo_len);
121-
122-
if self.num_open_snapshots == 1 {
123-
// The root snapshot. It's safe to clear the undo log because
124-
// there's no snapshot further out that we might need to roll back
125-
// to.
126-
assert!(snapshot.undo_len == 0);
127-
self.logs.clear();
128-
}
129-
130-
self.num_open_snapshots -= 1;
131-
}
132-
}
133-
134-
impl<K: ut::UnifyKey, I: Idx> Logs<K, I> {
135-
fn assert_open_snapshot(&self, snapshot: &Snapshot<K, I>) {
136-
// Failures here may indicate a failure to follow a stack discipline.
137-
assert!(self.logs.len() >= snapshot.undo_len);
138-
assert!(self.num_open_snapshots > 0);
139-
}
140-
}
141-
14244
pub struct LoggedUnificationTableStorage<K: ut::UnifyKey, I: Idx = K> {
14345
relations: ut::UnificationTableStorage<K>,
14446
unify_log: ul::UnifyLog<I>,
@@ -268,39 +170,10 @@ where
268170
self.relations().new_key(value)
269171
}
270172

271-
pub fn vars_since_snapshot(&mut self, s: &Snapshot<K, I>) -> Range<K> {
272-
K::from(I::new(s.value_count))..K::from(I::new(self.relations().len()))
173+
pub fn clear_modified_set(&mut self) {
174+
self.storage.modified_set.clear();
273175
}
274176

275-
/* FIXME
276-
pub fn snapshot(&mut self) -> Snapshot<K, I> {
277-
self.undo_log.num_open_snapshots += 1;
278-
Snapshot {
279-
undo_len: self.undo_log.logs.len(),
280-
value_count: self.relations().len(),
281-
_marker: PhantomData,
282-
}
283-
}
284-
285-
pub fn rollback_to(&mut self, snapshot: Snapshot<K, I>) {
286-
let UnificationTableStorage { relations, unify_log, modified_set, .. } = self.storage;
287-
288-
self.undo_log.rollback_to(|| RollbackView { relations, unify_log, modified_set }, snapshot);
289-
290-
if self.undo_log.num_open_snapshots == 0 {
291-
self.storage.modified_set.clear();
292-
}
293-
}
294-
295-
pub fn commit(&mut self, snapshot: Snapshot<K, I>) {
296-
self.undo_log.commit(snapshot);
297-
298-
if self.undo_log.num_open_snapshots() == 0 {
299-
self.storage.modified_set.clear();
300-
}
301-
}
302-
*/
303-
304177
pub fn register(&mut self) -> ms::Offset<I> {
305178
self.storage.modified_set.register()
306179
}
@@ -329,9 +202,3 @@ where
329202
})
330203
}
331204
}
332-
333-
pub struct Snapshot<K: ut::UnifyKey, I: Idx = K> {
334-
undo_len: usize,
335-
value_count: usize,
336-
_marker: PhantomData<(K, I)>,
337-
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_data_structures::logged_unification_table as lut;
1515
use rustc_data_structures::modified_set as ms;
1616
use rustc_data_structures::sync::Lrc;
17-
use rustc_data_structures::undo_log::Rollback;
17+
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
1818
use rustc_data_structures::unify as ut;
1919
use rustc_errors::DiagnosticBuilder;
2020
use rustc_hir as hir;
@@ -763,6 +763,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
763763
let mut inner = self.inner.borrow_mut();
764764
inner.rollback_to(undo_snapshot);
765765
inner.unwrap_region_constraints().rollback_to(region_constraints_snapshot);
766+
767+
if UndoLogs::<UndoLog<'_>>::num_open_snapshots(&inner.undo_log) == 0 {
768+
inner.type_variables().clear_modified_set();
769+
inner.int_unification_table().clear_modified_set();
770+
inner.float_unification_table().clear_modified_set();
771+
inner.const_unification_table().clear_modified_set();
772+
}
766773
}
767774

768775
fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
433433
.collect()
434434
}
435435

436+
pub fn clear_modified_set(&mut self) {
437+
self.eq_relations().clear_modified_set();
438+
}
439+
436440
pub fn drain_modified_set(
437441
&mut self,
438442
offset: &ms::Offset<ty::TyVid>,

0 commit comments

Comments
 (0)