mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Use the newer snapshot_vec, which has a simplified delegate
interface since in practice no delegates had any state.
This commit is contained in:
parent
966e53d8b6
commit
52c3462586
@ -142,7 +142,6 @@ pub mod util {
|
||||
pub mod common;
|
||||
pub mod ppaux;
|
||||
pub mod nodemap;
|
||||
pub mod snapshot_vec;
|
||||
pub mod lev_distance;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -31,3 +31,5 @@
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
|
||||
pub mod snapshot_vec;
|
||||
|
@ -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) }
|
||||
}
|
Loading…
Reference in New Issue
Block a user