Skip to content

Commit

Permalink
Register snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed May 4, 2013
1 parent b872900 commit 8081e8d
Show file tree
Hide file tree
Showing 47 changed files with 138 additions and 5,842 deletions.
46 changes: 0 additions & 46 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

//! Unsafe casting functions

#[cfg(not(stage0))]
use sys;
#[cfg(not(stage0))]
use unstable;

pub mod rusti {
Expand All @@ -21,35 +19,11 @@ pub mod rusti {
pub extern "rust-intrinsic" {
fn forget<T>(+x: T);

#[cfg(stage0)]
fn reinterpret_cast<T, U>(&&e: T) -> U;

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn transmute<T,U>(e: T) -> U;
}
}

/// Casts the value at `src` to U. The two types must have the same length.
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
rusti::reinterpret_cast(*src)
}

/// Unsafely copies and casts the value at `src` to U, even if the value is
/// noncopyable. The two types must have the same length.
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
rusti::reinterpret_cast(*src)
}

#[inline(always)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = unstable::intrinsics::init();
{
Expand Down Expand Up @@ -90,17 +64,6 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
* assert!(transmute("L") == ~[76u8, 0u8]);
*/
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn transmute<L, G>(thing: L) -> G {
let newthing: G = reinterpret_cast(&thing);
forget(thing);
newthing
}

#[inline(always)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub unsafe fn transmute<L, G>(thing: L) -> G {
rusti::transmute(thing)
}
Expand Down Expand Up @@ -161,15 +124,6 @@ mod tests {
use cast::{bump_box_refcount, transmute};

#[test]
#[cfg(stage0)]
fn test_reinterpret_cast() {
assert!(1u == unsafe { ::cast::reinterpret_cast(&1) });
}

#[test]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn test_transmute_copy() {
assert!(1u == unsafe { ::cast::transmute_copy(&1) });
}
Expand Down
36 changes: 0 additions & 36 deletions src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,6 @@ pub trait Mutable: Container {
fn clear(&mut self);
}

#[cfg(stage0)]
pub trait Map<K, V>: Mutable {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool;

// Visits all keys and values
fn each(&self, f: &fn(&K, &V) -> bool);

/// Visit all keys
fn each_key(&self, f: &fn(&K) -> bool);

/// Visit all values
fn each_value(&self, f: &fn(&V) -> bool);

/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);

/// Return a reference to the value corresponding to the key
fn find(&self, key: &K) -> Option<&'self V>;

/// Return a mutable reference to the value corresponding to the key
fn find_mut(&mut self, key: &K) -> Option<&'self mut V>;

/// Insert a key-value pair into the map. An existing value for a
/// key is replaced by the new value. Return true if the key did
/// not already exist in the map.
fn insert(&mut self, key: K, value: V) -> bool;

/// Remove a key-value pair from the map. Return true if the key
/// was present in the map, otherwise false.
fn remove(&mut self, key: &K) -> bool;
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub trait Map<K, V>: Mutable {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool;
Expand Down
3 changes: 0 additions & 3 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ they contained the following prologue:

pub use kinds::{Const, Copy, Owned, Durable};
pub use ops::{Drop};
#[cfg(stage0)]
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
#[cfg(not(stage0))]
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Shl, Shr, Index};
Expand Down
168 changes: 0 additions & 168 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,6 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
}
}

#[cfg(stage0)]
#[inline(always)]
fn value_for_bucket(&self, idx: uint) -> &'self V {
match self.buckets[idx] {
Some(ref bkt) => &bkt.value,
None => fail!(~"HashMap::find: internal logic error"),
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[inline(always)]
fn value_for_bucket<'a>(&'a self, idx: uint) -> &'a V {
match self.buckets[idx] {
Expand All @@ -204,18 +192,6 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
}
}

#[cfg(stage0)]
#[inline(always)]
fn mut_value_for_bucket(&mut self, idx: uint) -> &'self mut V {
match self.buckets[idx] {
Some(ref mut bkt) => &mut bkt.value,
None => unreachable()
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[inline(always)]
fn mut_value_for_bucket<'a>(&'a mut self, idx: uint) -> &'a mut V {
match self.buckets[idx] {
Expand Down Expand Up @@ -329,21 +305,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
}

/// Visit all key-value pairs
#[cfg(stage0)]
fn each(&self, blk: &fn(&'self K, &'self V) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
for self.buckets[i].each |bucket| {
if !blk(&bucket.key, &bucket.value) {
return;
}
}
}
}

/// Visit all key-value pairs
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn each<'a>(&'a self, blk: &fn(&'a K, &'a V) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
for self.buckets[i].each |bucket| {
Expand All @@ -360,15 +321,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
}

/// Visit all values
#[cfg(stage0)]
fn each_value(&self, blk: &fn(v: &V) -> bool) {
self.each(|_, v| blk(v))
}

/// Visit all values
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) {
self.each(|_, v| blk(v))
}
Expand All @@ -386,18 +338,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
}

/// Return a reference to the value corresponding to the key
#[cfg(stage0)]
fn find(&self, k: &K) -> Option<&'self V> {
match self.bucket_for_key(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
}
}

/// Return a reference to the value corresponding to the key
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
match self.bucket_for_key(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
Expand All @@ -406,21 +346,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
}

/// Return a mutable reference to the value corresponding to the key
#[cfg(stage0)]
fn find_mut(&mut self, k: &K) -> Option<&'self mut V> {
let idx = match self.bucket_for_key(k) {
FoundEntry(idx) => idx,
TableFull | FoundHole(_) => return None
};
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
Some(::cast::transmute_mut_region(self.mut_value_for_bucket(idx)))
}
}

/// Return a mutable reference to the value corresponding to the key
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> {
let idx = match self.bucket_for_key(k) {
FoundEntry(idx) => idx,
Expand Down Expand Up @@ -503,40 +428,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

/// Return the value corresponding to the key in the map, or insert
/// and return the value if it doesn't exist.
#[cfg(stage0)]
fn find_or_insert(&mut self, k: K, v: V) -> &'self V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
// simply going to update a key in place. My sense
// though is that it's worse to have to search through
// buckets to find the right spot twice than to just
// resize in this corner case.
self.expand();
}

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
value: v});
self.size += 1;
idx
},
};

unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
::cast::transmute_region(self.value_for_bucket(idx))
}
}

/// Return the value corresponding to the key in the map, or insert
/// and return the value if it doesn't exist.
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
Expand Down Expand Up @@ -567,41 +458,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

/// Return the value corresponding to the key in the map, or create,
/// insert, and return a new value if it doesn't exist.
#[cfg(stage0)]
fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
// simply going to update a key in place. My sense
// though is that it's worse to have to search through
// buckets to find the right spot twice than to just
// resize in this corner case.
self.expand();
}

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
let v = f(&k);
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
value: v});
self.size += 1;
idx
},
};

unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
::cast::transmute_region(self.value_for_bucket(idx))
}
}

/// Return the value corresponding to the key in the map, or create,
/// insert, and return a new value if it doesn't exist.
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
Expand Down Expand Up @@ -647,17 +503,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
}
}

#[cfg(stage0)]
fn get(&self, k: &K) -> &'self V {
match self.find(k) {
Some(v) => v,
None => fail!(fmt!("No entry found for key: %?", k)),
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn get<'a>(&'a self, k: &K) -> &'a V {
match self.find(k) {
Some(v) => v,
Expand All @@ -676,19 +521,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

/// Return the value corresponding to the key in the map, using
/// equivalence
#[cfg(stage0)]
fn find_equiv<Q:Hash + Equiv<K>>(&self, k: &Q) -> Option<&'self V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
}
}

/// Return the value corresponding to the key in the map, using
/// equivalence
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
Expand Down
7 changes: 1 addition & 6 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,7 @@ impl Div<f32,f32> for f32 {
fn div(&self, other: &f32) -> f32 { *self / *other }
}

#[cfg(stage0,notest)]
impl Modulo<f32,f32> for f32 {
#[inline(always)]
fn modulo(&self, other: &f32) -> f32 { *self % *other }
}
#[cfg(not(stage0),notest)]
#[cfg(notest)]
impl Rem<f32,f32> for f32 {
#[inline(always)]
fn rem(&self, other: &f32) -> f32 { *self % *other }
Expand Down
6 changes: 1 addition & 5 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,7 @@ impl Mul<f64,f64> for f64 {
impl Div<f64,f64> for f64 {
fn div(&self, other: &f64) -> f64 { *self / *other }
}
#[cfg(stage0,notest)]
impl Modulo<f64,f64> for f64 {
fn modulo(&self, other: &f64) -> f64 { *self % *other }
}
#[cfg(not(stage0),notest)]
#[cfg(notest)]
impl Rem<f64,f64> for f64 {
#[inline(always)]
fn rem(&self, other: &f64) -> f64 { *self % *other }
Expand Down
Loading

0 comments on commit 8081e8d

Please sign in to comment.