diff options
| author | bors <bors@rust-lang.org> | 2013-07-21 22:34:36 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-21 22:34:36 -0700 |
| commit | 74f4badcab30c91b018f308d2c44641abed7d732 (patch) | |
| tree | 81dd71ea871e583375edf2dc423b17f3653b2e08 /src/libstd | |
| parent | 3d6c0bc05640b9cc62db9fe287903cb709056dcb (diff) | |
| parent | f51e2ad435d7c0b4cb1bdebc5b6db29b65249125 (diff) | |
| download | rust-74f4badcab30c91b018f308d2c44641abed7d732.tar.gz rust-74f4badcab30c91b018f308d2c44641abed7d732.zip | |
auto merge of #7955 : thestinger/rust/snapshot, r=huonw
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 1 | ||||
| -rw-r--r-- | src/libstd/cleanup.rs | 15 | ||||
| -rw-r--r-- | src/libstd/condition.rs | 61 | ||||
| -rw-r--r-- | src/libstd/gc.rs | 15 | ||||
| -rw-r--r-- | src/libstd/kinds.rs | 20 | ||||
| -rw-r--r-- | src/libstd/local_data.rs | 47 | ||||
| -rw-r--r-- | src/libstd/os.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rand.rs | 3 | ||||
| -rw-r--r-- | src/libstd/reflect.rs | 13 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 29 | ||||
| -rw-r--r-- | src/libstd/rt/global_heap.rs | 22 | ||||
| -rw-r--r-- | src/libstd/str.rs | 13 | ||||
| -rw-r--r-- | src/libstd/task/local_data_priv_stage0.rs | 229 | ||||
| -rw-r--r-- | src/libstd/task/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 5 | ||||
| -rw-r--r-- | src/libstd/unstable/intrinsics.rs | 9 | ||||
| -rw-r--r-- | src/libstd/util.rs | 13 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 117 |
18 files changed, 12 insertions, 607 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 695ed0749dd..5a0c781fe9a 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -21,7 +21,6 @@ A dynamic, mutable location. Similar to a mutable option type, but friendlier. */ -#[mutable] // XXX remove after snap #[no_freeze] #[deriving(Clone, DeepClone, Eq)] #[allow(missing_doc)] diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index bb011a8cd32..2ea10b09c8e 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -73,19 +73,6 @@ fn debug_mem() -> bool { false } -#[inline] -#[cfg(not(stage0))] -unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { - // This function should be inlined when stage0 is gone - ((*tydesc).drop_glue)(data); -} - -#[inline] -#[cfg(stage0)] -unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { - ((*tydesc).drop_glue)(0 as **TyDesc, data); -} - /// Destroys all managed memory (i.e. @ boxes) held by the current task. pub unsafe fn annihilate() { use rt::local_heap::local_free; @@ -128,7 +115,7 @@ pub unsafe fn annihilate() { if !uniq { let tydesc: *TyDesc = transmute((*box).header.type_desc); let data = transmute(&(*box).data); - call_drop_glue(tydesc, data); + ((*tydesc).drop_glue)(data); } } diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 10075137017..1f7f96d93c3 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -23,18 +23,11 @@ pub struct Handler<T, U> { prev: Option<@Handler<T, U>>, } -#[cfg(stage0)] -pub struct Condition<'self, T, U> { - name: &'static str, - key: local_data::Key<'self, @Handler<T, U>> -} -#[cfg(not(stage0))] pub struct Condition<T, U> { name: &'static str, key: local_data::Key<@Handler<T, U>> } -#[cfg(not(stage0))] impl<T, U> Condition<T, U> { pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> { unsafe { @@ -73,56 +66,7 @@ impl<T, U> Condition<T, U> { } } } -#[cfg(stage0)] -impl<'self, T, U> Condition<'self, T, U> { - pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> { - unsafe { - let p : *RustClosure = ::cast::transmute(&h); - let prev = local_data::get(::cast::unsafe_copy(&self.key), - |k| k.map(|&x| *x)); - let h = @Handler { handle: *p, prev: prev }; - Trap { cond: self, handler: h } - } - } - - pub fn raise(&self, t: T) -> U { - let msg = fmt!("Unhandled condition: %s: %?", self.name, t); - self.raise_default(t, || fail!(msg.clone())) - } - - pub fn raise_default(&self, t: T, default: &fn() -> U) -> U { - unsafe { - match local_data::pop(::cast::unsafe_copy(&self.key)) { - None => { - debug!("Condition.raise: found no handler"); - default() - } - Some(handler) => { - debug!("Condition.raise: found handler"); - match handler.prev { - None => {} - Some(hp) => { - local_data::set(::cast::unsafe_copy(&self.key), - hp) - } - } - let handle : &fn(T) -> U = - ::cast::transmute(handler.handle); - let u = handle(t); - local_data::set(::cast::unsafe_copy(&self.key), handler); - u - } - } - } - } -} -#[cfg(stage0)] -struct Trap<'self, T, U> { - cond: &'self Condition<'self, T, U>, - handler: @Handler<T, U> -} -#[cfg(not(stage0))] struct Trap<'self, T, U> { cond: &'self Condition<T, U>, handler: @Handler<T, U> @@ -137,11 +81,6 @@ impl<'self, T, U> Trap<'self, T, U> { } } -#[cfg(stage0)] -struct Guard<'self, T, U> { - cond: &'self Condition<'self, T, U> -} -#[cfg(not(stage0))] struct Guard<'self, T, U> { cond: &'self Condition<T, U> } diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 62be923d770..911fb5625e5 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -317,19 +317,6 @@ fn expect_sentinel() -> bool { true } #[cfg(nogc)] fn expect_sentinel() -> bool { false } -#[inline] -#[cfg(not(stage0))] -unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { - // This function should be inlined when stage0 is gone - ((*tydesc).drop_glue)(data); -} - -#[inline] -#[cfg(stage0)] -unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { - ((*tydesc).drop_glue)(0 as **TyDesc, data); -} - // Entry point for GC-based cleanup. Walks stack looking for exchange // heap and stack allocations requiring drop, and runs all // destructors. @@ -373,7 +360,7 @@ pub fn cleanup_stack_for_failure() { // FIXME #4420: Destroy this box // FIXME #4330: Destroy this box } else { - call_drop_glue(tydesc, *root as *i8); + ((*tydesc).drop_glue)(*root as *i8); } } } diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index f13eeece2f4..6b45ddddf7e 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -29,31 +29,11 @@ The 2 kinds are #[allow(missing_doc)]; -#[cfg(stage0)] -#[lang="copy"] -pub trait Copy { - // Empty. -} - -#[cfg(stage0)] -#[lang="owned"] -pub trait Send { - // empty. -} - -#[cfg(not(stage0))] #[lang="send"] pub trait Send { // empty. } -#[cfg(stage0)] -#[lang="const"] -pub trait Freeze { - // empty. -} - -#[cfg(not(stage0))] #[lang="freeze"] pub trait Freeze { // empty. diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 2c1a3bb29a0..537289c8dd6 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -56,10 +56,7 @@ use task::local_data_priv::*; * sections to ensure that each value of the `Key` type points to a unique * location. */ -#[cfg(not(stage0))] pub type Key<T> = &'static KeyValue<T>; -#[cfg(stage0)] -pub type Key<'self,T> = &'self fn(v: T); pub enum KeyValue<T> { Key } @@ -67,73 +64,37 @@ pub enum KeyValue<T> { Key } * Remove a task-local data value from the table, returning the * reference that was originally created to insert it. */ -#[cfg(stage0)] -pub fn pop<T: 'static>(key: Key<@T>) -> Option<@T> { - unsafe { local_pop(Handle::new(), key) } -} -/** - * Remove a task-local data value from the table, returning the - * reference that was originally created to insert it. - */ -#[cfg(not(stage0))] pub fn pop<T: 'static>(key: Key<T>) -> Option<T> { unsafe { local_pop(Handle::new(), key) } } + /** * Retrieve a task-local data value. It will also be kept alive in the * table until explicitly removed. */ -#[cfg(stage0)] -pub fn get<T: 'static, U>(key: Key<@T>, f: &fn(Option<&@T>) -> U) -> U { - unsafe { local_get(Handle::new(), key, f) } -} -/** - * Retrieve a task-local data value. It will also be kept alive in the - * table until explicitly removed. - */ -#[cfg(not(stage0))] pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U { unsafe { local_get(Handle::new(), key, f) } } + /** * Retrieve a mutable borrowed pointer to a task-local data value. */ -#[cfg(not(stage0))] pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U { unsafe { local_get_mut(Handle::new(), key, f) } } + /** * Store a value in task-local data. If this key already has a value, * that value is overwritten (and its destructor is run). */ -#[cfg(stage0)] -pub fn set<T: 'static>(key: Key<@T>, data: @T) { - unsafe { local_set(Handle::new(), key, data) } -} -/** - * Store a value in task-local data. If this key already has a value, - * that value is overwritten (and its destructor is run). - */ -#[cfg(not(stage0))] pub fn set<T: 'static>(key: Key<T>, data: T) { unsafe { local_set(Handle::new(), key, data) } } + /** * Modify a task-local data value. If the function returns 'None', the * data is removed (and its reference dropped). */ -#[cfg(stage0)] -pub fn modify<T: 'static>(key: Key<@T>, f: &fn(Option<@T>) -> Option<@T>) { - match f(pop(key)) { - Some(next) => { set(key, next); } - None => {} - } -} -/** - * Modify a task-local data value. If the function returns 'None', the - * data is removed (and its reference dropped). - */ -#[cfg(not(stage0))] pub fn modify<T: 'static>(key: Key<T>, f: &fn(Option<T>) -> Option<T>) { unsafe { match f(pop(::cast::unsafe_copy(&key))) { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3b37fb077d6..bbfa15d69bd 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1237,9 +1237,6 @@ struct OverriddenArgs { val: ~[~str] } -#[cfg(stage0)] -fn overridden_arg_key(_v: @OverriddenArgs) {} -#[cfg(not(stage0))] static overridden_arg_key: local_data::Key<@OverriddenArgs> = &local_data::Key; /// Returns the arguments which this program was started with (normally passed diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 5be73bbfc68..9af2d8be297 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -852,9 +852,6 @@ pub fn seed() -> ~[u8] { } // used to make space in TLS for a random number generator -#[cfg(stage0)] -fn tls_rng_state(_v: @@mut IsaacRng) {} -#[cfg(not(stage0))] static tls_rng_state: local_data::Key<@@mut IsaacRng> = &local_data::Key; /** diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index 63d2492bd33..d49d54ae68f 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -16,9 +16,6 @@ Runtime type reflection #[allow(missing_doc)]; -#[cfg(stage0)] -use intrinsic::{Opaque, TyDesc, TyVisitor}; -#[cfg(not(stage0))] use unstable::intrinsics::{Opaque, TyDesc, TyVisitor}; use libc::c_void; use sys; @@ -197,14 +194,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { true } - #[cfg(stage0)] - fn visit_str(&self) -> bool { - self.align_to::<~str>(); - if ! self.inner.visit_str() { return false; } - self.bump_past::<~str>(); - true - } - fn visit_estr_box(&self) -> bool { self.align_to::<@str>(); if ! self.inner.visit_estr_box() { return false; } @@ -249,7 +238,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { true } - #[cfg(not(stage0))] fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool { self.align_to::<~u8>(); if ! self.inner.visit_uniq_managed(mtbl, inner) { return false; } @@ -298,7 +286,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { true } - #[cfg(not(stage0))] fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool { self.align_to::<~[@u8]>(); if ! self.inner.visit_evec_uniq_managed(mtbl, inner) { return false; } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 0aeff2b0b77..07fd82e1616 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -31,9 +31,6 @@ use to_str::ToStr; use vec::raw::{VecRepr, SliceRepr}; use vec; use vec::{OwnedVector, UnboxedVecRepr}; -#[cfg(stage0)] -use intrinsic::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; -#[cfg(not(stage0))] use unstable::intrinsics::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; #[cfg(test)] use io; @@ -267,10 +264,6 @@ impl TyVisitor for ReprVisitor { } } - // Type no longer exists, vestigial function. - #[cfg(stage0)] - fn visit_str(&self) -> bool { fail!(); } - fn visit_estr_box(&self) -> bool { do self.get::<@str> |s| { self.writer.write_char('@'); @@ -309,7 +302,6 @@ impl TyVisitor for ReprVisitor { } } - #[cfg(not(stage0))] fn visit_uniq_managed(&self, _mtbl: uint, inner: *TyDesc) -> bool { self.writer.write_char('~'); do self.get::<&managed::raw::BoxRepr> |b| { @@ -351,15 +343,6 @@ impl TyVisitor for ReprVisitor { } } - #[cfg(stage0)] - fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&VecRepr> |b| { - self.writer.write_char('~'); - self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner); - } - } - - #[cfg(not(stage0))] fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool { do self.get::<&UnboxedVecRepr> |b| { self.writer.write_char('~'); @@ -367,7 +350,6 @@ impl TyVisitor for ReprVisitor { } } - #[cfg(not(stage0))] fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool { do self.get::<&VecRepr> |b| { self.writer.write_char('~'); @@ -563,7 +545,6 @@ impl TyVisitor for ReprVisitor { fn visit_self(&self) -> bool { true } fn visit_type(&self) -> bool { true } - #[cfg(not(stage0))] fn visit_opaque_box(&self) -> bool { self.writer.write_char('@'); do self.get::<&managed::raw::BoxRepr> |b| { @@ -571,16 +552,6 @@ impl TyVisitor for ReprVisitor { self.visit_ptr_inner(p, b.header.type_desc); } } - #[cfg(stage0)] - fn visit_opaque_box(&self) -> bool { - self.writer.write_char('@'); - do self.get::<&managed::raw::BoxRepr> |b| { - let p = ptr::to_unsafe_ptr(&b.data) as *c_void; - unsafe { - self.visit_ptr_inner(p, transmute(b.header.type_desc)); - } - } - } // Type no longer exists, vestigial function. fn visit_constr(&self, _inner: *TyDesc) -> bool { fail!(); } diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index d0b268ace54..580390c1953 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -56,28 +56,8 @@ pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void { p } -// FIXME #4942: Make these signatures agree with exchange_alloc's signatures -#[cfg(stage0, not(test))] -#[lang="exchange_malloc"] -#[inline] -pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { - let td = td as *TyDesc; - let size = size as uint; - - assert!(td.is_not_null()); - - let total_size = get_box_size(size, (*td).align); - let p = malloc_raw(total_size as uint); - - let box: *mut BoxRepr = p as *mut BoxRepr; - (*box).header.ref_count = -1; - (*box).header.type_desc = td; - - box as *c_char -} - /// The allocator for unique pointers without contained managed pointers. -#[cfg(not(stage0), not(test))] +#[cfg(not(test))] #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uintptr_t) -> *c_char { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 97fc56d007d..125df156ed0 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1006,19 +1006,6 @@ pub mod raw { /// Sets the length of the string and adds the null terminator #[inline] - #[cfg(stage0)] - pub unsafe fn set_len(v: &mut ~str, new_len: uint) { - let v: **mut vec::raw::VecRepr = cast::transmute(v); - let repr: *mut vec::raw::VecRepr = *v; - (*repr).unboxed.fill = new_len + 1u; - let null = ptr::mut_offset(cast::transmute(&((*repr).unboxed.data)), - new_len); - *null = 0u8; - } - - /// Sets the length of the string and adds the null terminator - #[inline] - #[cfg(not(stage0))] pub unsafe fn set_len(v: &mut ~str, new_len: uint) { let v: **mut vec::UnboxedVecRepr = cast::transmute(v); let repr: *mut vec::UnboxedVecRepr = *v; diff --git a/src/libstd/task/local_data_priv_stage0.rs b/src/libstd/task/local_data_priv_stage0.rs deleted file mode 100644 index fe80ec06c69..00000000000 --- a/src/libstd/task/local_data_priv_stage0.rs +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[allow(missing_doc)]; - -use cast; -use cmp::Eq; -use libc; -use local_data; -use prelude::*; -use sys; -use task::rt; - -use super::rt::rust_task; -use rt::task::{Task, LocalStorage}; - -pub enum Handle { - OldHandle(*rust_task), - NewHandle(*mut LocalStorage) -} - -impl Handle { - pub fn new() -> Handle { - use rt::{context, OldTaskContext}; - use rt::local::Local; - unsafe { - match context() { - OldTaskContext => { - OldHandle(rt::rust_get_task()) - } - _ => { - let task = Local::unsafe_borrow::<Task>(); - NewHandle(&mut (*task).storage) - } - } - } - } -} - -pub trait LocalData { } -impl<T: 'static> LocalData for @T { } - -impl Eq for @LocalData { - fn eq(&self, other: &@LocalData) -> bool { - unsafe { - let ptr_a: &(uint, uint) = cast::transmute(self); - let ptr_b: &(uint, uint) = cast::transmute(other); - return ptr_a == ptr_b; - } - } - fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) } -} - -// If TLS is used heavily in future, this could be made more efficient with a -// proper map. -type TaskLocalElement = (*libc::c_void, *libc::c_void, @LocalData); -// Has to be a pointer at outermost layer; the foreign call returns void *. -type TaskLocalMap = ~[Option<TaskLocalElement>]; - -fn cleanup_task_local_map(map_ptr: *libc::c_void) { - unsafe { - assert!(!map_ptr.is_null()); - // Get and keep the single reference that was created at the - // beginning. - let _map: TaskLocalMap = cast::transmute(map_ptr); - // All local_data will be destroyed along with the map. - } -} - -// Gets the map from the runtime. Lazily initialises if not done so already. -unsafe fn get_local_map(handle: Handle) -> &mut TaskLocalMap { - match handle { - OldHandle(task) => get_task_local_map(task), - NewHandle(local_storage) => get_newsched_local_map(local_storage) - } -} - -unsafe fn get_task_local_map(task: *rust_task) -> &mut TaskLocalMap { - - extern fn cleanup_task_local_map_extern_cb(map_ptr: *libc::c_void) { - cleanup_task_local_map(map_ptr); - } - - // Relies on the runtime initialising the pointer to null. - // Note: the map is an owned pointer and is "owned" by TLS. It is moved - // into the tls slot for this task, and then mutable loans are taken from - // this slot to modify the map. - let map_ptr = rt::rust_get_task_local_data(task); - if (*map_ptr).is_null() { - // First time TLS is used, create a new map and set up the necessary - // TLS information for its safe destruction - let map: TaskLocalMap = ~[]; - *map_ptr = cast::transmute(map); - rt::rust_task_local_data_atexit(task, cleanup_task_local_map_extern_cb); - } - return cast::transmute(map_ptr); -} - -unsafe fn get_newsched_local_map(local: *mut LocalStorage) -> &mut TaskLocalMap { - // This is based on the same idea as the oldsched code above. - match &mut *local { - // If the at_exit function is already set, then we just need to take a - // loan out on the TLS map stored inside - &LocalStorage(ref mut map_ptr, Some(_)) => { - assert!(map_ptr.is_not_null()); - return cast::transmute(map_ptr); - } - // If this is the first time we've accessed TLS, perform similar - // actions to the oldsched way of doing things. - &LocalStorage(ref mut map_ptr, ref mut at_exit) => { - assert!(map_ptr.is_null()); - assert!(at_exit.is_none()); - let map: TaskLocalMap = ~[]; - *map_ptr = cast::transmute(map); - *at_exit = Some(cleanup_task_local_map); - return cast::transmute(map_ptr); - } - } -} - -unsafe fn key_to_key_value<T: 'static>(key: local_data::Key<@T>) -> *libc::c_void { - let pair: sys::Closure = cast::transmute(key); - return pair.code as *libc::c_void; -} - -// If returning Some(..), returns with @T with the map's reference. Careful! -unsafe fn local_data_lookup<T: 'static>( - map: &mut TaskLocalMap, key: local_data::Key<@T>) - -> Option<(uint, *libc::c_void)> { - - let key_value = key_to_key_value(key); - for map.iter().enumerate().advance |(i, entry)| { - match *entry { - Some((k, data, _)) if k == key_value => { return Some((i, data)); } - _ => {} - } - } - return None; -} - -unsafe fn local_get_helper<T: 'static>( - handle: Handle, key: local_data::Key<@T>, - do_pop: bool) -> Option<@T> { - - let map = get_local_map(handle); - // Interpreturn our findings from the map - do local_data_lookup(map, key).map |result| { - // A reference count magically appears on 'data' out of thin air. It - // was referenced in the local_data box, though, not here, so before - // overwriting the local_data_box we need to give an extra reference. - // We must also give an extra reference when not removing. - let (index, data_ptr) = *result; - let data: @T = cast::transmute(data_ptr); - cast::bump_box_refcount(data); - if do_pop { - map[index] = None; - } - data - } -} - - -pub unsafe fn local_pop<T: 'static>( - handle: Handle, - key: local_data::Key<@T>) -> Option<@T> { - - local_get_helper(handle, key, true) -} - -pub unsafe fn local_get<T: 'static, U>( - handle: Handle, - key: local_data::Key<@T>, - f: &fn(Option<&@T>) -> U) -> U { - - match local_get_helper(handle, key, false) { - Some(ref x) => f(Some(x)), - None => f(None) - } -} - -pub unsafe fn local_set<T: 'static>( - handle: Handle, key: local_data::Key<@T>, data: @T) { - - let map = get_local_map(handle); - // Store key+data as *voids. Data is invisibly referenced once; key isn't. - let keyval = key_to_key_value(key); - // We keep the data in two forms: one as an unsafe pointer, so we can get - // it back by casting; another in an existential box, so the reference we - // own on it can be dropped when the box is destroyed. The unsafe pointer - // does not have a reference associated with it, so it may become invalid - // when the box is destroyed. - let data_ptr = *cast::transmute::<&@T, &*libc::c_void>(&data); - let data_box = @data as @LocalData; - // Construct new entry to store in the map. - let new_entry = Some((keyval, data_ptr, data_box)); - // Find a place to put it. - match local_data_lookup(map, key) { - Some((index, _old_data_ptr)) => { - // Key already had a value set, _old_data_ptr, whose reference - // will get dropped when the local_data box is overwritten. - map[index] = new_entry; - } - None => { - // Find an empty slot. If not, grow the vector. - match map.iter().position(|x| x.is_none()) { - Some(empty_index) => { map[empty_index] = new_entry; } - None => { map.push(new_entry); } - } - } - } -} - -pub unsafe fn local_modify<T: 'static>( - handle: Handle, key: local_data::Key<@T>, - modify_fn: &fn(Option<@T>) -> Option<@T>) { - - // Could be more efficient by doing the lookup work, but this is easy. - let newdata = modify_fn(local_pop(handle, key)); - if newdata.is_some() { - local_set(handle, key, newdata.unwrap()); - } -} diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index f2563b37347..1ce8641085b 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -54,10 +54,6 @@ use util; #[cfg(test)] use ptr; #[cfg(test)] use task; -#[cfg(stage0)] -#[path="local_data_priv_stage0.rs"] -mod local_data_priv; -#[cfg(not(stage0))] mod local_data_priv; pub mod rt; pub mod spawn; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 2150c0c5ac2..a17bb2b1632 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -487,14 +487,9 @@ fn kill_taskgroup(state: TaskGroupInner, me: &TaskHandle, is_main: bool) { // FIXME (#2912): Work around core-vs-coretest function duplication. Can't use // a proper closure because the #[test]s won't understand. Have to fake it. -#[cfg(not(stage0))] fn taskgroup_key() -> local_data::Key<@@mut Taskgroup> { unsafe { cast::transmute(-2) } } -#[cfg(stage0)] -fn taskgroup_key() -> local_data::Key<@@mut Taskgroup> { - unsafe { cast::transmute((-2, 0)) } -} // Transitionary. struct RuntimeGlue; diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 275a8c94c69..76958fa333f 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -36,12 +36,8 @@ A quick refresher on memory ordering: #[cfg(test)] pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor}; -#[cfg(not(stage0))] pub type GlueFn = extern "Rust" fn(*i8); -#[cfg(stage0)] -pub type GlueFn = extern "Rust" fn(**TyDesc, *i8); - // NB: this has to be kept in sync with the Rust ABI. #[lang="ty_desc"] #[cfg(not(test))] @@ -284,10 +280,7 @@ extern "rust-intrinsic" { pub fn pref_align_of<T>() -> uint; /// Get a static pointer to a type descriptor. - #[cfg(not(stage0))] pub fn get_tydesc<T>() -> *TyDesc; - #[cfg(stage0)] - pub fn get_tydesc<T>() -> *(); /// Create a value initialized to zero. /// @@ -310,10 +303,8 @@ extern "rust-intrinsic" { pub fn needs_drop<T>() -> bool; /// Returns `true` if a type is managed (will be allocated on the local heap) - #[cfg(not(stage0))] pub fn contains_managed<T>() -> bool; - #[cfg(not(stage0))] pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor); pub fn frame_address(f: &once fn(*u8)); diff --git a/src/libstd/util.rs b/src/libstd/util.rs index 8e7efeb532a..5ae45b74dd8 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -175,18 +175,16 @@ mod tests { // verify that `#[unsafe_no_drop_flag]` works as intended on a zero-size struct - // NOTE: uncomment after snapshot, will not parse yet - //static mut did_run: bool = false; + static mut did_run: bool = false; struct Foo { five: int } impl Drop for Foo { fn drop(&self) { assert_eq!(self.five, 5); - // NOTE: uncomment after snapshot, will not parse yet - //unsafe { - //did_run = true; - //} + unsafe { + did_run = true; + } } } @@ -194,7 +192,6 @@ mod tests { let _a = (NonCopyable, Foo { five: 5 }, NonCopyable); } - // NOTE: uncomment after snapshot, will not parse yet - //unsafe { assert_eq!(did_run, true); } + unsafe { assert_eq!(did_run, true); } } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 877ee65b4d6..6c9d3c15b9e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -25,16 +25,12 @@ use option::{None, Option, Some}; use ptr::to_unsafe_ptr; use ptr; use ptr::RawPtr; -#[cfg(not(stage0))] use rt::global_heap::malloc_raw; use rt::global_heap::realloc_raw; use sys; use sys::size_of; use uint; use unstable::intrinsics; -#[cfg(stage0)] -use intrinsic::{get_tydesc}; -#[cfg(not(stage0))] use unstable::intrinsics::{get_tydesc, contains_managed}; use vec; use util; @@ -91,15 +87,6 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] { } /// Creates a new vector with a capacity of `capacity` -#[cfg(stage0)] -pub fn with_capacity<T>(capacity: uint) -> ~[T] { - let mut vec = ~[]; - vec.reserve(capacity); - vec -} - -/// Creates a new vector with a capacity of `capacity` -#[cfg(not(stage0))] pub fn with_capacity<T>(capacity: uint) -> ~[T] { unsafe { if contains_managed::<T>() { @@ -1136,40 +1123,6 @@ impl<T> OwnedVector<T> for ~[T] { * * * n - The number of elements to reserve space for */ - #[cfg(stage0)] - fn reserve(&mut self, n: uint) { - // Only make the (slow) call into the runtime if we have to - use managed; - if self.capacity() < n { - unsafe { - let ptr: *mut *mut raw::VecRepr = cast::transmute(self); - let td = get_tydesc::<T>(); - if ((**ptr).box_header.ref_count == - managed::raw::RC_MANAGED_UNIQUE) { - // XXX transmute shouldn't be necessary - let td = cast::transmute(td); - ::at_vec::raw::reserve_raw(td, ptr, n); - } else { - let alloc = n * sys::nonzero_size_of::<T>(); - *ptr = realloc_raw(*ptr as *mut c_void, alloc + size_of::<raw::VecRepr>()) - as *mut raw::VecRepr; - (**ptr).unboxed.alloc = alloc; - } - } - } - } - - /** - * Reserves capacity for exactly `n` elements in the given vector. - * - * If the capacity for `self` is already equal to or greater than the requested - * capacity, then no action is taken. - * - * # Arguments - * - * * n - The number of elements to reserve space for - */ - #[cfg(not(stage0))] fn reserve(&mut self, n: uint) { // Only make the (slow) call into the runtime if we have to if self.capacity() < n { @@ -1213,17 +1166,6 @@ impl<T> OwnedVector<T> for ~[T] { /// Returns the number of elements the vector can hold without reallocating. #[inline] - #[cfg(stage0)] - fn capacity(&self) -> uint { - unsafe { - let repr: **raw::VecRepr = transmute(self); - (**repr).unboxed.alloc / sys::nonzero_size_of::<T>() - } - } - - /// Returns the number of elements the vector can hold without reallocating. - #[inline] - #[cfg(not(stage0))] fn capacity(&self) -> uint { unsafe { if contains_managed::<T>() { @@ -1238,23 +1180,6 @@ impl<T> OwnedVector<T> for ~[T] { /// Append an element to a vector #[inline] - #[cfg(stage0)] - fn push(&mut self, t: T) { - unsafe { - let repr: **raw::VecRepr = transmute(&mut *self); - let fill = (**repr).unboxed.fill; - if (**repr).unboxed.alloc <= fill { - let new_len = self.len() + 1; - self.reserve_at_least(new_len); - } - - self.push_fast(t); - } - } - - /// Append an element to a vector - #[inline] - #[cfg(not(stage0))] fn push(&mut self, t: T) { unsafe { if contains_managed::<T>() { @@ -1281,19 +1206,6 @@ impl<T> OwnedVector<T> for ~[T] { // This doesn't bother to make sure we have space. #[inline] // really pretty please - #[cfg(stage0)] - unsafe fn push_fast(&mut self, t: T) { - let repr: **mut raw::VecRepr = transmute(self); - let fill = (**repr).unboxed.fill; - (**repr).unboxed.fill += sys::nonzero_size_of::<T>(); - let p = to_unsafe_ptr(&((**repr).unboxed.data)); - let p = ptr::offset(p, fill) as *mut T; - intrinsics::move_val_init(&mut(*p), t); - } - - // This doesn't bother to make sure we have space. - #[inline] // really pretty please - #[cfg(not(stage0))] unsafe fn push_fast(&mut self, t: T) { if contains_managed::<T>() { let repr: **mut raw::VecRepr = transmute(self); @@ -1901,7 +1813,6 @@ pub mod raw { use sys; use unstable::intrinsics; use vec::{UnboxedVecRepr, with_capacity, ImmutableVector, MutableVector}; - #[cfg(not(stage0))] use unstable::intrinsics::contains_managed; /// The internal representation of a (boxed) vector @@ -1927,21 +1838,6 @@ pub mod raw { * the vector is actually the specified size. */ #[inline] - #[cfg(stage0)] - pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) { - let repr: **mut VecRepr = transmute(v); - (**repr).unboxed.fill = new_len * sys::nonzero_size_of::<T>(); - } - - /** - * Sets the length of a vector - * - * This will explicitly set the size of the vector, without actually - * modifing its buffers, so it is up to the caller to ensure that - * the vector is actually the specified size. - */ - #[inline] - #[cfg(not(stage0))] pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) { if contains_managed::<T>() { let repr: **mut VecRepr = transmute(v); @@ -2286,19 +2182,6 @@ impl<T> Iterator<T> for VecConsumeRevIterator<T> { } } -#[cfg(stage0)] -impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] { - pub fn from_iterator(iterator: &mut T) -> ~[A] { - let mut xs = ~[]; - for iterator.advance |x| { - xs.push(x); - } - xs - } -} - - -#[cfg(not(stage0))] impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] { pub fn from_iterator(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); |
