about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-04-07 06:11:49 -0400
committerNiko Matsakis <niko@alum.mit.edu>2015-04-17 10:12:55 -0400
commit52c34625866f6e23fd0de484282f326da6a100e3 (patch)
tree9fb362e4f1e4f0c0118344bcfa8a78664d1c0990
parent966e53d8b6272a324c6be3460ae6bf52e47202fe (diff)
downloadrust-52c34625866f6e23fd0de484282f326da6a100e3.tar.gz
rust-52c34625866f6e23fd0de484282f326da6a100e3.zip
Use the newer snapshot_vec, which has a simplified delegate
interface since in practice no delegates had any state.
-rw-r--r--src/librustc/lib.rs1
-rw-r--r--src/librustc/middle/infer/type_variable.rs8
-rw-r--r--src/librustc/middle/infer/unify.rs6
-rw-r--r--src/librustc_data_structures/lib.rs2
-rw-r--r--src/librustc_data_structures/snapshot_vec.rs (renamed from src/librustc/util/snapshot_vec.rs)31
5 files changed, 34 insertions, 14 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index 4f7bb3d528a..6837483a422 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -142,7 +142,6 @@ pub mod util {
     pub mod common;
     pub mod ppaux;
     pub mod nodemap;
-    pub mod snapshot_vec;
     pub mod lev_distance;
 }
 
diff --git a/src/librustc/middle/infer/type_variable.rs b/src/librustc/middle/infer/type_variable.rs
index 03612a6c1ae..b3e3e016d85 100644
--- a/src/librustc/middle/infer/type_variable.rs
+++ b/src/librustc/middle/infer/type_variable.rs
@@ -17,7 +17,7 @@ use std::cmp::min;
 use std::marker::PhantomData;
 use std::mem;
 use std::u32;
-use util::snapshot_vec as sv;
+use rustc_data_structures::snapshot_vec as sv;
 
 pub struct TypeVariableTable<'tcx> {
     values: sv::SnapshotVec<Delegate<'tcx>>,
@@ -65,7 +65,7 @@ impl RelationDir {
 
 impl<'tcx> TypeVariableTable<'tcx> {
     pub fn new() -> TypeVariableTable<'tcx> {
-        TypeVariableTable { values: sv::SnapshotVec::new(Delegate(PhantomData)) }
+        TypeVariableTable { values: sv::SnapshotVec::new() }
     }
 
     fn relations<'a>(&'a mut self, a: ty::TyVid) -> &'a mut Vec<Relation> {
@@ -201,9 +201,7 @@ impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
     type Value = TypeVariableData<'tcx>;
     type Undo = UndoEntry;
 
-    fn reverse(&mut self,
-               values: &mut Vec<TypeVariableData<'tcx>>,
-               action: UndoEntry) {
+    fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: UndoEntry) {
         match action {
             SpecifyVar(vid, relations) => {
                 values[vid.index as usize].value = Bounded(relations);
diff --git a/src/librustc/middle/infer/unify.rs b/src/librustc/middle/infer/unify.rs
index 4bbced1d75c..5aec4227136 100644
--- a/src/librustc/middle/infer/unify.rs
+++ b/src/librustc/middle/infer/unify.rs
@@ -17,7 +17,7 @@ use middle::ty::{self, Ty};
 use std::fmt::Debug;
 use std::marker::PhantomData;
 use syntax::ast;
-use util::snapshot_vec as sv;
+use rustc_data_structures::snapshot_vec as sv;
 
 /// This trait is implemented by any type that can serve as a type
 /// variable. We call such variables *unification keys*. For example,
@@ -95,7 +95,7 @@ pub struct Delegate<K>(PhantomData<K>);
 impl<K:UnifyKey> UnificationTable<K> {
     pub fn new() -> UnificationTable<K> {
         UnificationTable {
-            values: sv::SnapshotVec::new(Delegate(PhantomData)),
+            values: sv::SnapshotVec::new(),
         }
     }
 
@@ -213,7 +213,7 @@ impl<K:UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
     type Value = VarValue<K>;
     type Undo = ();
 
-    fn reverse(&mut self, _: &mut Vec<VarValue<K>>, _: ()) {
+    fn reverse(_: &mut Vec<VarValue<K>>, _: ()) {
         panic!("Nothing to reverse");
     }
 }
diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs
index abac991e5ce..5f2f430df50 100644
--- a/src/librustc_data_structures/lib.rs
+++ b/src/librustc_data_structures/lib.rs
@@ -31,3 +31,5 @@
 
 #[macro_use] extern crate log;
 extern crate serialize as rustc_serialize; // used by deriving
+
+pub mod snapshot_vec;
diff --git a/src/librustc/util/snapshot_vec.rs b/src/librustc_data_structures/snapshot_vec.rs
index d2e0b3aec2f..5ab740f3629 100644
--- a/src/librustc/util/snapshot_vec.rs
+++ b/src/librustc_data_structures/snapshot_vec.rs
@@ -21,6 +21,7 @@
 use self::UndoLog::*;
 
 use std::mem;
+use std::ops;
 
 pub enum UndoLog<D:SnapshotVecDelegate> {
     /// Indicates where a snapshot started.
@@ -42,7 +43,6 @@ pub enum UndoLog<D:SnapshotVecDelegate> {
 pub struct SnapshotVec<D:SnapshotVecDelegate> {
     values: Vec<D::Value>,
     undo_log: Vec<UndoLog<D>>,
-    delegate: D
 }
 
 // Snapshots are tokens that should be created/consumed linearly.
@@ -55,15 +55,14 @@ pub trait SnapshotVecDelegate {
     type Value;
     type Undo;
 
-    fn reverse(&mut self, values: &mut Vec<Self::Value>, action: Self::Undo);
+    fn reverse(values: &mut Vec<Self::Value>, action: Self::Undo);
 }
 
 impl<D:SnapshotVecDelegate> SnapshotVec<D> {
-    pub fn new(delegate: D) -> SnapshotVec<D> {
+    pub fn new() -> SnapshotVec<D> {
         SnapshotVec {
             values: Vec::new(),
             undo_log: Vec::new(),
-            delegate: delegate
         }
     }
 
@@ -77,6 +76,10 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
         }
     }
 
+    pub fn len(&self) -> usize {
+        self.values.len()
+    }
+
     pub fn push(&mut self, elem: D::Value) -> usize {
         let len = self.values.len();
         self.values.push(elem);
@@ -159,7 +162,7 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
                 }
 
                 Other(u) => {
-                    self.delegate.reverse(&mut self.values, u);
+                    D::reverse(&mut self.values, u);
                 }
             }
         }
@@ -184,3 +187,21 @@ impl<D:SnapshotVecDelegate> SnapshotVec<D> {
         }
     }
 }
+
+impl<D:SnapshotVecDelegate> ops::Deref for SnapshotVec<D> {
+    type Target = [D::Value];
+    fn deref(&self) -> &[D::Value] { &*self.values }
+}
+
+impl<D:SnapshotVecDelegate> ops::DerefMut for SnapshotVec<D> {
+    fn deref_mut(&mut self) -> &mut [D::Value] { &mut *self.values }
+}
+
+impl<D:SnapshotVecDelegate> ops::Index<usize> for SnapshotVec<D> {
+    type Output = D::Value;
+    fn index(&self, index: usize) -> &D::Value { self.get(index) }
+}
+
+impl<D:SnapshotVecDelegate> ops::IndexMut<usize> for SnapshotVec<D> {
+    fn index_mut(&mut self, index: usize) -> &mut D::Value { self.get_mut(index) }
+}