Finally removing all uses of by-mut-ref

The code for the mode itself is still there.
This commit is contained in:
Tim Chevalier 2012-10-05 17:19:50 -07:00
parent 688a920045
commit 05999290e2
5 changed files with 6 additions and 209 deletions

View File

@ -21,10 +21,6 @@ extern mod rustrt {
#[abi = "rust-intrinsic"]
extern mod rusti {
#[legacy_exports];
#[cfg(stage0)]
fn move_val_init<T>(&dst: T, -src: T);
#[cfg(stage1)]
#[cfg(stage2)]
fn move_val_init<T>(dst: &mut T, -src: T);
}
@ -181,20 +177,6 @@ pub mod raw {
}
}
// This doesn't bother to make sure we have space.
#[cfg(stage0)]
#[inline(always)] // really pretty please
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T;
rusti::move_val_init(*p, move initval);
}
// This doesn't bother to make sure we have space.
#[cfg(stage1)]
#[cfg(stage2)]
#[inline(always)] // really pretty please
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);

View File

@ -18,10 +18,6 @@ extern mod rustrt {
#[abi = "rust-intrinsic"]
extern mod rusti {
#[cfg(stage0)]
fn move_val_init<T>(&dst: T, -src: T);
#[cfg(stage1)]
#[cfg(stage2)]
fn move_val_init<T>(dst: &mut T, -src: T);
}
@ -103,23 +99,6 @@ pub pure fn len<T>(v: &[const T]) -> uint {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
#[cfg(stage0)]
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
do as_mut_buf(v) |p, _len| {
let mut i: uint = 0u;
while i < n_elts {
rusti::move_val_init(*ptr::mut_offset(p, i), op(i));
i += 1u;
}
}
raw::set_len(&mut v, n_elts);
return move v;
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
@ -503,19 +482,6 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
}
}
#[cfg(stage0)]
// This doesn't bother to make sure we have space.
#[inline(always)] // really pretty please
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
let repr: **raw::VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T;
rusti::move_val_init(*p, move initval);
}
#[cfg(stage1)]
#[cfg(stage2)]
// This doesn't bother to make sure we have space.
#[inline(always)] // really pretty please
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
@ -1793,18 +1759,6 @@ pub mod raw {
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
}
#[cfg(stage0)]
#[inline(always)]
pub unsafe fn init_elem<T>(v: &[mut T], i: uint, val: T) {
let mut box = Some(move val);
do as_mut_buf(v) |p, _len| {
let mut box2 = None;
box2 <-> box;
rusti::move_val_init(*ptr::mut_offset(p, i),
option::unwrap(move box2));
}
}
#[cfg(stage1)]
/**
* Unchecked vector index assignment. Does not drop the
* old value and hence is only suitable when the vector

View File

@ -31,10 +31,6 @@ use libc::size_t;
#[abi = "rust-intrinsic"]
extern mod rusti {
#[cfg(stage0)]
fn move_val_init<T>(&dst: T, -src: T);
#[cfg(stage1)]
#[cfg(stage2)]
fn move_val_init<T>(dst: &mut T, -src: T);
fn needs_drop<T>() -> bool;
}
@ -132,117 +128,6 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
(reinterpret_cast(&(p & !1)), p & 1 == 1)
}
// tjc: Can get rid of the duplication post-snapshot
#[cfg(stage0)]
// The duplication between the POD and non-POD functions is annoying.
impl &Arena {
// Functions for the POD part of the arena
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.pod_head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
self.chunks = @Cons(copy self.pod_head, self.chunks);
self.pod_head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
return self.alloc_pod_inner(n_bytes, align);
}
#[inline(always)]
fn alloc_pod_inner(n_bytes: uint, align: uint) -> *u8 {
let head = &mut self.pod_head;
let start = round_up_to(head.fill, align);
let end = start + n_bytes;
if end > at_vec::capacity(head.data) {
return self.alloc_pod_grow(n_bytes, align);
}
head.fill = end;
//debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill);
unsafe {
ptr::offset(vec::raw::to_ptr(head.data), start)
}
}
#[inline(always)]
fn alloc_pod<T>(op: fn() -> T) -> &self/T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
let ptr: *mut T = reinterpret_cast(&ptr);
rusti::move_val_init(*ptr, op());
return reinterpret_cast(&ptr);
}
}
// Functions for the non-POD part of the arena
fn alloc_nonpod_grow(n_bytes: uint, align: uint) -> (*u8, *u8) {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
self.chunks = @Cons(copy self.head, self.chunks);
self.head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
return self.alloc_nonpod_inner(n_bytes, align);
}
#[inline(always)]
fn alloc_nonpod_inner(n_bytes: uint, align: uint) -> (*u8, *u8) {
let head = &mut self.head;
let tydesc_start = head.fill;
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
let start = round_up_to(after_tydesc, align);
let end = start + n_bytes;
if end > at_vec::capacity(head.data) {
return self.alloc_nonpod_grow(n_bytes, align);
}
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
//debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill);
unsafe {
let buf = vec::raw::to_ptr(head.data);
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
}
}
#[inline(always)]
fn alloc_nonpod<T>(op: fn() -> T) -> &self/T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let (ty_ptr, ptr) =
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
let ty_ptr: *mut uint = reinterpret_cast(&ty_ptr);
let ptr: *mut T = reinterpret_cast(&ptr);
// Write in our tydesc along with a bit indicating that it
// has *not* been initialized yet.
*ty_ptr = reinterpret_cast(&tydesc);
// Actually initialize it
rusti::move_val_init(*ptr, op());
// Now that we are done, update the tydesc to indicate that
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
return reinterpret_cast(&ptr);
}
}
// The external interface
#[inline(always)]
fn alloc<T>(op: fn() -> T) -> &self/T {
if !rusti::needs_drop::<T>() {
self.alloc_pod(op)
} else { self.alloc_nonpod(op) }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
impl &Arena {
// Functions for the POD part of the arena
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {

View File

@ -8,24 +8,16 @@ use result::{Result, Ok, Err};
#[abi = "cdecl"]
extern mod rustrt {
#[legacy_exports]
#[cfg(stage0)]
fn get_time(&sec: i64, &nsec: i32);
#[cfg(stage1)]
#[cfg(stage2)]
fn get_time(sec: &mut i64, nsec: &mut i32);
#[cfg(stage0)]
fn precise_time_ns(&ns: u64);
#[cfg(stage1)]
#[cfg(stage2)]
fn precise_time_ns(ns: &mut u64);
fn rust_tzset();
// FIXME: The i64 values can be passed by-val when #2064 is fixed.
fn rust_gmtime(&&sec: i64, &&nsec: i32, &&result: Tm);
fn rust_localtime(&&sec: i64, &&nsec: i32, &&result: Tm);
fn rust_timegm(&&tm: Tm, &sec: i64);
fn rust_mktime(&&tm: Tm, &sec: i64);
fn rust_timegm(&&tm: Tm, sec: &mut i64);
fn rust_mktime(&&tm: Tm, sec: &mut i64);
}
/// A record specifying a time value in seconds and nanoseconds.
@ -42,15 +34,6 @@ impl Timespec : Eq {
* Returns the current time as a `timespec` containing the seconds and
* nanoseconds since 1970-01-01T00:00:00Z.
*/
#[cfg(stage0)]
pub fn get_time() -> Timespec {
let mut sec = 0i64;
let mut nsec = 0i32;
rustrt::get_time(sec, nsec);
return {sec: sec, nsec: nsec};
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn get_time() -> Timespec {
let mut sec = 0i64;
let mut nsec = 0i32;
@ -63,14 +46,6 @@ pub fn get_time() -> Timespec {
* Returns the current value of a high-resolution performance counter
* in nanoseconds since an unspecified epoch.
*/
#[cfg(stage0)]
pub fn precise_time_ns() -> u64 {
let mut ns = 0u64;
rustrt::precise_time_ns(ns);
ns
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn precise_time_ns() -> u64 {
let mut ns = 0u64;
rustrt::precise_time_ns(&mut ns);
@ -790,9 +765,9 @@ impl Tm {
fn to_timespec() -> Timespec {
let mut sec = 0i64;
if self.tm_gmtoff == 0_i32 {
rustrt::rust_timegm(self, sec);
rustrt::rust_timegm(self, &mut sec);
} else {
rustrt::rust_mktime(self, sec);
rustrt::rust_mktime(self, &mut sec);
}
{ sec: sec, nsec: self.tm_nsec }
}

View File

@ -570,7 +570,8 @@ impl parser {
fn parse_arg_mode() -> mode {
if self.eat(token::BINOP(token::AND)) {
self.warn(~"Obsolete syntax has no effect");
self.span_fatal(copy self.last_span,
~"Obsolete syntax has no effect");
expl(by_mutbl_ref)
} else if self.eat(token::BINOP(token::MINUS)) {
expl(by_move)