Skip to content

Commit 52c3462

Browse files
committed
Use the newer snapshot_vec, which has a simplified delegate
interface since in practice no delegates had any state.
1 parent 966e53d commit 52c3462

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ pub mod util {
142142
pub mod common;
143143
pub mod ppaux;
144144
pub mod nodemap;
145-
pub mod snapshot_vec;
146145
pub mod lev_distance;
147146
}
148147

src/librustc/middle/infer/type_variable.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::cmp::min;
1717
use std::marker::PhantomData;
1818
use std::mem;
1919
use std::u32;
20-
use util::snapshot_vec as sv;
20+
use rustc_data_structures::snapshot_vec as sv;
2121

2222
pub struct TypeVariableTable<'tcx> {
2323
values: sv::SnapshotVec<Delegate<'tcx>>,
@@ -65,7 +65,7 @@ impl RelationDir {
6565

6666
impl<'tcx> TypeVariableTable<'tcx> {
6767
pub fn new() -> TypeVariableTable<'tcx> {
68-
TypeVariableTable { values: sv::SnapshotVec::new(Delegate(PhantomData)) }
68+
TypeVariableTable { values: sv::SnapshotVec::new() }
6969
}
7070

7171
fn relations<'a>(&'a mut self, a: ty::TyVid) -> &'a mut Vec<Relation> {
@@ -201,9 +201,7 @@ impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
201201
type Value = TypeVariableData<'tcx>;
202202
type Undo = UndoEntry;
203203

204-
fn reverse(&mut self,
205-
values: &mut Vec<TypeVariableData<'tcx>>,
206-
action: UndoEntry) {
204+
fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: UndoEntry) {
207205
match action {
208206
SpecifyVar(vid, relations) => {
209207
values[vid.index as usize].value = Bounded(relations);

src/librustc/middle/infer/unify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use middle::ty::{self, Ty};
1717
use std::fmt::Debug;
1818
use std::marker::PhantomData;
1919
use syntax::ast;
20-
use util::snapshot_vec as sv;
20+
use rustc_data_structures::snapshot_vec as sv;
2121

2222
/// This trait is implemented by any type that can serve as a type
2323
/// variable. We call such variables *unification keys*. For example,
@@ -95,7 +95,7 @@ pub struct Delegate<K>(PhantomData<K>);
9595
impl<K:UnifyKey> UnificationTable<K> {
9696
pub fn new() -> UnificationTable<K> {
9797
UnificationTable {
98-
values: sv::SnapshotVec::new(Delegate(PhantomData)),
98+
values: sv::SnapshotVec::new(),
9999
}
100100
}
101101

@@ -213,7 +213,7 @@ impl<K:UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
213213
type Value = VarValue<K>;
214214
type Undo = ();
215215

216-
fn reverse(&mut self, _: &mut Vec<VarValue<K>>, _: ()) {
216+
fn reverse(_: &mut Vec<VarValue<K>>, _: ()) {
217217
panic!("Nothing to reverse");
218218
}
219219
}

src/librustc_data_structures/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@
3131

3232
#[macro_use] extern crate log;
3333
extern crate serialize as rustc_serialize; // used by deriving
34+
35+
pub mod snapshot_vec;

src/librustc/util/snapshot_vec.rs renamed to src/librustc_data_structures/snapshot_vec.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use self::UndoLog::*;
2222

2323
use std::mem;
24+
use std::ops;
2425

2526
pub enum UndoLog<D:SnapshotVecDelegate> {
2627
/// Indicates where a snapshot started.
@@ -42,7 +43,6 @@ pub enum UndoLog<D:SnapshotVecDelegate> {
4243
pub struct SnapshotVec<D:SnapshotVecDelegate> {
4344
values: Vec<D::Value>,
4445
undo_log: Vec<UndoLog<D>>,
45-
delegate: D
4646
}
4747

4848
// Snapshots are tokens that should be created/consumed linearly.
@@ -55,15 +55,14 @@ pub trait SnapshotVecDelegate {
5555
type Value;
5656
type Undo;
5757

58-
fn reverse(&mut self, values: &mut Vec<Self::Value>, action: Self::Undo);
58+
fn reverse(values: &mut Vec<Self::Value>, action: Self::Undo);
5959
}
6060

6161
impl<D:SnapshotVecDelegate> SnapshotVec<D> {
62-
pub fn new(delegate: D) -> SnapshotVec<D> {
62+
pub fn new() -> SnapshotVec<D> {
6363
SnapshotVec {
6464
values: Vec::new(),
6565
undo_log: Vec::new(),
66-
delegate: delegate
6766
}
6867
}
6968

@@ -77,6 +76,10 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
7776
}
7877
}
7978

79+
pub fn len(&self) -> usize {
80+
self.values.len()
81+
}
82+
8083
pub fn push(&mut self, elem: D::Value) -> usize {
8184
let len = self.values.len();
8285
self.values.push(elem);
@@ -159,7 +162,7 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
159162
}
160163

161164
Other(u) => {
162-
self.delegate.reverse(&mut self.values, u);
165+
D::reverse(&mut self.values, u);
163166
}
164167
}
165168
}
@@ -184,3 +187,21 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
184187
}
185188
}
186189
}
190+
191+
impl<D:SnapshotVecDelegate> ops::Deref for SnapshotVec<D> {
192+
type Target = [D::Value];
193+
fn deref(&self) -> &[D::Value] { &*self.values }
194+
}
195+
196+
impl<D:SnapshotVecDelegate> ops::DerefMut for SnapshotVec<D> {
197+
fn deref_mut(&mut self) -> &mut [D::Value] { &mut *self.values }
198+
}
199+
200+
impl<D:SnapshotVecDelegate> ops::Index<usize> for SnapshotVec<D> {
201+
type Output = D::Value;
202+
fn index(&self, index: usize) -> &D::Value { self.get(index) }
203+
}
204+
205+
impl<D:SnapshotVecDelegate> ops::IndexMut<usize> for SnapshotVec<D> {
206+
fn index_mut(&mut self, index: usize) -> &mut D::Value { self.get_mut(index) }
207+
}

0 commit comments

Comments
 (0)