fixup mutability of vec::each, make iter_bytes pure

also, change DVec() to work with imm vectors rather than mut ones
This commit is contained in:
Niko Matsakis 2012-09-12 10:38:17 -07:00
parent 8fbe4b5841
commit 5d540de769
34 changed files with 357 additions and 186 deletions

View File

@ -50,7 +50,7 @@ export unwrap;
* type could only produce 47 million pushes/second.
*/
type DVec_<A> = {
mut data: ~[mut A]
mut data: ~[A]
};
enum DVec<A> {
@ -59,21 +59,21 @@ enum DVec<A> {
/// Creates a new, empty dvec
fn DVec<A>() -> DVec<A> {
DVec_({mut data: ~[mut]})
DVec_({mut data: ~[]})
}
/// Creates a new dvec with a single element
fn from_elem<A>(+e: A) -> DVec<A> {
DVec_({mut data: ~[mut move e]})
DVec_({mut data: ~[move e]})
}
/// Creates a new dvec with the contents of a vector
fn from_vec<A>(+v: ~[mut A]) -> DVec<A> {
fn from_vec<A>(+v: ~[A]) -> DVec<A> {
DVec_({mut data: move v})
}
/// Consumes the vector and returns its contents
fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
fn unwrap<A>(+d: DVec<A>) -> ~[A] {
let DVec_({data: v}) <- d;
move v
}
@ -89,7 +89,7 @@ priv impl<A> DVec<A> {
}
#[inline(always)]
fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
fn check_out<B>(f: fn(-~[A]) -> B) -> B {
unsafe {
let mut data = unsafe::reinterpret_cast(&null::<()>());
data <-> self.data;
@ -100,9 +100,9 @@ priv impl<A> DVec<A> {
}
#[inline(always)]
fn give_back(-data: ~[mut A]) {
fn give_back(+data: ~[A]) {
unsafe {
self.data <- data;
self.data = move data;
}
}
}
@ -122,10 +122,22 @@ impl<A> DVec<A> {
* and return a new vector to replace it with.
*/
#[inline(always)]
fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
fn swap(f: fn(-~[A]) -> ~[A]) {
self.check_out(|v| self.give_back(f(move v)))
}
/**
* Swaps out the current vector and hands it off to a user-provided
* function `f`. The function should transform it however is desired
* and return a new vector to replace it with.
*/
#[inline(always)]
fn swap_mut(f: fn(-~[mut A]) -> ~[mut A]) {
do self.swap |v| {
vec::from_mut(f(vec::to_mut(move v)))
}
}
/// Returns the number of elements currently in the dvec
pure fn len() -> uint {
unchecked {
@ -138,7 +150,7 @@ impl<A> DVec<A> {
}
/// Overwrite the current contents
fn set(+w: ~[mut A]) {
fn set(+w: ~[A]) {
self.check_not_borrowed();
self.data <- w;
}
@ -161,7 +173,7 @@ impl<A> DVec<A> {
let data_ptr: *() = unsafe::reinterpret_cast(&data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
log(error, ~"a");
self.data <- ~[mut move t];
self.data <- ~[move t];
vec::push_all_move(self.data, move data);
log(error, ~"b");
}
@ -176,9 +188,9 @@ impl<A> DVec<A> {
/// Remove and return the first element
fn shift() -> A {
do self.check_out |v| {
let mut v = vec::from_mut(move v);
let mut v = move v;
let result = vec::shift(v);
self.give_back(vec::to_mut(move v));
self.give_back(move v);
move result
}
}
@ -186,6 +198,7 @@ impl<A> DVec<A> {
/// Reverse the elements in the list, in place
fn reverse() {
do self.check_out |v| {
let mut v = move v;
vec::reverse(v);
self.give_back(move v);
}
@ -203,6 +216,7 @@ impl<A> DVec<A> {
/// Gives access to the vector as a slice with mutable contents
fn borrow_mut<R>(op: fn(x: &[mut A]) -> R) -> R {
do self.check_out |v| {
let mut v = move v;
let result = op(v);
self.give_back(move v);
move result
@ -268,7 +282,7 @@ impl<A: Copy> DVec<A> {
pure fn get() -> ~[A] {
unchecked {
do self.check_out |v| {
let w = vec::from_mut(copy v);
let w = copy v;
self.give_back(move v);
move w
}
@ -295,9 +309,9 @@ impl<A: Copy> DVec<A> {
*/
fn grow_set_elt(idx: uint, initval: A, val: A) {
do self.swap |v| {
let mut v <- v;
let mut v = vec::to_mut(move v);
vec::grow_set(v, idx, initval, val);
move v
move vec::from_mut(v)
}
}

View File

@ -130,7 +130,7 @@ pure fn hash_keyed_5<A: IterBytes,
}
}
pure fn hash_bytes_keyed(val: &[const u8], k0: u64, k1: u64) -> u64 {
pure fn hash_bytes_keyed(val: &[u8], k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_str_keyed(val: &str, k0: u64, k1: u64) -> u64 {
@ -152,7 +152,7 @@ pure fn hash_uint_keyed(val: uint, k0: u64, k1: u64) -> u64 {
val.hash_keyed(k0, k1)
}
pure fn hash_bytes(val: &[const u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
pure fn hash_bytes(val: &[u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
pure fn hash_str(val: &str) -> u64 { hash_str_keyed(val, 0, 0) }
pure fn hash_u64(val: u64) -> u64 { hash_u64_keyed(val, 0, 0) }
pure fn hash_u32(val: u32) -> u64 { hash_u32_keyed(val, 0, 0) }

View File

@ -214,7 +214,7 @@ fn convert_whence(whence: SeekStyle) -> i32 {
impl *libc::FILE: Reader {
fn read(buf: &[mut u8], len: uint) -> uint {
do vec::as_buf(buf) |buf_p, buf_len| {
do vec::as_mut_buf(buf) |buf_p, buf_len| {
assert buf_len <= len;
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,

View File

@ -2,6 +2,7 @@
export addr_of;
export to_unsafe_ptr;
export to_const_unsafe_ptr;
export to_mut_unsafe_ptr;
export mut_addr_of;
export offset;
@ -26,11 +27,16 @@ use libc::{c_void, size_t};
#[abi = "cdecl"]
extern mod libc_ {
#[rust_stack]
fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
fn memcpy(dest: *mut c_void, src: *const c_void,
n: libc::size_t) -> *c_void;
#[rust_stack]
fn memmove(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
fn memmove(dest: *mut c_void, src: *const c_void,
n: libc::size_t) -> *c_void;
#[rust_stack]
fn memset(dest: *c_void, c: libc::c_int, len: libc::size_t) -> *c_void;
fn memset(dest: *mut c_void, c: libc::c_int,
len: libc::size_t) -> *c_void;
}
#[abi = "rust-intrinsic"]
@ -105,9 +111,9 @@ pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
* and destination may not overlap.
*/
#[inline(always)]
unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
let n = count * sys::size_of::<T>();
libc_::memcpy(dst as *c_void, src as *c_void, n as size_t);
libc_::memcpy(dst as *mut c_void, src as *c_void, n as size_t);
}
/**
@ -117,15 +123,15 @@ unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
* and destination may overlap.
*/
#[inline(always)]
unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
let n = count * sys::size_of::<T>();
libc_::memmove(dst as *c_void, src as *c_void, n as size_t);
libc_::memmove(dst as *mut c_void, src as *c_void, n as size_t);
}
#[inline(always)]
unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
let n = count * sys::size_of::<T>();
libc_::memset(dst as *c_void, c as libc::c_int, n as size_t);
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
}
@ -135,8 +141,18 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
reinterpret_cast.
*/
#[inline(always)]
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
unsafe::reinterpret_cast(&thing)
fn to_unsafe_ptr<T>(thing: &T) -> *T {
unsafe { unsafe::reinterpret_cast(&thing) }
}
/**
Transform a const region pointer - &const T - to a const unsafe pointer -
*const T. This is safe, but is implemented with an unsafe block due to
reinterpret_cast.
*/
#[inline(always)]
fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
unsafe { unsafe::reinterpret_cast(&thing) }
}
/**
@ -145,8 +161,8 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
reinterpret_cast.
*/
#[inline(always)]
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T unsafe {
unsafe::reinterpret_cast(&thing)
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
unsafe { unsafe::reinterpret_cast(&thing) }
}
/**
@ -246,16 +262,16 @@ fn test() {
assert (p.fst == 50);
assert (p.snd == 60);
let v0 = ~[32000u16, 32001u16, 32002u16];
let v1 = ~[0u16, 0u16, 0u16];
let mut v0 = ~[32000u16, 32001u16, 32002u16];
let mut v1 = ~[0u16, 0u16, 0u16];
ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 1u),
ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 1u),
ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u);
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16);
ptr::memcpy(vec::unsafe::to_ptr(v1),
ptr::memcpy(vec::unsafe::to_mut_ptr(v1),
ptr::offset(vec::unsafe::to_ptr(v0), 2u), 1u);
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16);
ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 2u),
ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 2u),
vec::unsafe::to_ptr(v0), 1u);
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16);
}

View File

@ -250,6 +250,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) {
do as_buf(lhs) |lbuf, _llen| {
do as_buf(rhs) |rbuf, _rlen| {
let dst = ptr::offset(lbuf, llen);
let dst = ::unsafe::transmute_mut_unsafe(dst);
ptr::memcpy(dst, rbuf, rlen);
}
}
@ -266,6 +267,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
do as_buf(lhs) |lbuf, _llen| {
do as_buf(rhs) |rbuf, _rlen| {
let dst = ptr::offset(lbuf, llen);
let dst = ::unsafe::transmute_mut_unsafe(dst);
ptr::memcpy(dst, rbuf, rlen);
}
}
@ -1990,7 +1992,10 @@ mod unsafe {
unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
let mut v: ~[mut u8] = ~[mut];
vec::reserve(v, len + 1u);
vec::as_buf(v, |b, _len| ptr::memcpy(b, buf as *u8, len));
vec::as_buf(v, |vbuf, _len| {
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
ptr::memcpy(vbuf, buf as *u8, len)
});
vec::unsafe::set_len(v, len);
vec::push(v, 0u8);
@ -2045,6 +2050,7 @@ mod unsafe {
vec::reserve(v, end - begin + 1u);
unsafe {
do vec::as_buf(v) |vbuf, _vlen| {
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
let src = ptr::offset(sbuf, begin);
ptr::memcpy(vbuf, src, end - begin);
}

View File

@ -7,12 +7,12 @@ use io::Writer;
type Cb = fn(buf: &[const u8]) -> bool;
trait IterBytes {
fn iter_bytes(lsb0: bool, f: Cb);
pure fn iter_bytes(lsb0: bool, f: Cb);
}
impl u8: IterBytes {
#[inline(always)]
fn iter_bytes(_lsb0: bool, f: Cb) {
pure fn iter_bytes(_lsb0: bool, f: Cb) {
f([
self
]);
@ -21,7 +21,7 @@ impl u8: IterBytes {
impl u16: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
if lsb0 {
f([
self as u8,
@ -38,7 +38,7 @@ impl u16: IterBytes {
impl u32: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
if lsb0 {
f([
self as u8,
@ -59,7 +59,7 @@ impl u32: IterBytes {
impl u64: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
if lsb0 {
f([
self as u8,
@ -88,36 +88,43 @@ impl u64: IterBytes {
impl i8: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
impl i16: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u16).iter_bytes(lsb0, f)
}
}
impl i32: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u32).iter_bytes(lsb0, f)
}
}
impl i64: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u64).iter_bytes(lsb0, f)
}
}
impl char: IterBytes {
#[inline(always)]
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u32).iter_bytes(lsb0, f)
}
}
#[cfg(target_word_size = "32")]
impl uint: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u32).iter_bytes(lsb0, f)
}
}
@ -125,21 +132,21 @@ impl uint: IterBytes {
#[cfg(target_word_size = "64")]
impl uint: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as u64).iter_bytes(lsb0, f)
}
}
impl int: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as uint).iter_bytes(lsb0, f)
}
}
impl<A: IterBytes> &[const A]: IterBytes {
impl<A: IterBytes> &[A]: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
for self.each |elt| {
do elt.iter_bytes(lsb0) |bytes| {
f(bytes)
@ -149,26 +156,26 @@ impl<A: IterBytes> &[const A]: IterBytes {
}
// Move this to vec, probably.
fn borrow<A>(a: &x/[const A]) -> &x/[const A] {
pure fn borrow<A>(a: &x/[A]) -> &x/[A] {
a
}
impl<A: IterBytes> ~[const A]: IterBytes {
impl<A: IterBytes> ~[A]: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
borrow(self).iter_bytes(lsb0, f)
}
}
impl<A: IterBytes> @[const A]: IterBytes {
impl<A: IterBytes> @[A]: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
borrow(self).iter_bytes(lsb0, f)
}
}
fn iter_bytes_2<A: IterBytes, B: IterBytes>(a: &A, b: &B,
pure fn iter_bytes_2<A: IterBytes, B: IterBytes>(a: &A, b: &B,
lsb0: bool, z: Cb) {
let mut flag = true;
a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
@ -176,7 +183,7 @@ fn iter_bytes_2<A: IterBytes, B: IterBytes>(a: &A, b: &B,
b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
fn iter_bytes_3<A: IterBytes,
pure fn iter_bytes_3<A: IterBytes,
B: IterBytes,
C: IterBytes>(a: &A, b: &B, c: &C,
lsb0: bool, z: Cb) {
@ -188,7 +195,7 @@ fn iter_bytes_3<A: IterBytes,
c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
fn iter_bytes_4<A: IterBytes,
pure fn iter_bytes_4<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes>(a: &A, b: &B, c: &C,
@ -204,7 +211,7 @@ fn iter_bytes_4<A: IterBytes,
d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
fn iter_bytes_5<A: IterBytes,
pure fn iter_bytes_5<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@ -223,7 +230,7 @@ fn iter_bytes_5<A: IterBytes,
e.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
fn iter_bytes_6<A: IterBytes,
pure fn iter_bytes_6<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@ -245,7 +252,7 @@ fn iter_bytes_6<A: IterBytes,
f.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
fn iter_bytes_7<A: IterBytes,
pure fn iter_bytes_7<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@ -273,7 +280,7 @@ fn iter_bytes_7<A: IterBytes,
impl &str: IterBytes {
#[inline(always)]
fn iter_bytes(_lsb0: bool, f: Cb) {
pure fn iter_bytes(_lsb0: bool, f: Cb) {
do str::byte_slice(self) |bytes| {
f(bytes);
}
@ -282,7 +289,7 @@ impl &str: IterBytes {
impl ~str: IterBytes {
#[inline(always)]
fn iter_bytes(_lsb0: bool, f: Cb) {
pure fn iter_bytes(_lsb0: bool, f: Cb) {
do str::byte_slice(self) |bytes| {
f(bytes);
}
@ -291,7 +298,7 @@ impl ~str: IterBytes {
impl @str: IterBytes {
#[inline(always)]
fn iter_bytes(_lsb0: bool, f: Cb) {
pure fn iter_bytes(_lsb0: bool, f: Cb) {
do str::byte_slice(self) |bytes| {
f(bytes);
}
@ -300,7 +307,7 @@ impl @str: IterBytes {
impl<A: IterBytes> Option<A>: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
match self {
Some(a) => iter_bytes_2(&0u8, &a, lsb0, f),
None => 1u8.iter_bytes(lsb0, f)
@ -310,30 +317,30 @@ impl<A: IterBytes> Option<A>: IterBytes {
impl<A: IterBytes> &A: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(*self).iter_bytes(lsb0, f);
}
}
impl<A: IterBytes> @A: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(*self).iter_bytes(lsb0, f);
}
}
impl<A: IterBytes> ~A: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(*self).iter_bytes(lsb0, f);
}
}
// NB: raw-pointer IterBytes does _not_ dereference
// to the target; it just gives you the pointer-bytes.
impl<A> *A: IterBytes {
impl<A> *const A: IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: Cb) {
pure fn iter_bytes(lsb0: bool, f: Cb) {
(self as uint).iter_bytes(lsb0, f);
}
}

View File

@ -2,6 +2,7 @@
export reinterpret_cast, forget, bump_box_refcount, transmute;
export transmute_mut, transmute_immut, transmute_region, transmute_mut_region;
export transmute_mut_unsafe, transmute_immut_unsafe;
export SharedMutableState, shared_mutable_state, clone_shared_mutable_state;
export get_shared_mutable_state, get_shared_immutable_state;
@ -68,6 +69,12 @@ unsafe fn transmute_immut<T>(+ptr: &a/mut T) -> &a/T { transmute(move ptr) }
/// Coerce a borrowed pointer to have an arbitrary associated region.
unsafe fn transmute_region<T>(+ptr: &a/T) -> &b/T { transmute(move ptr) }
/// Coerce an immutable reference to be mutable.
unsafe fn transmute_mut_unsafe<T>(+ptr: *const T) -> *mut T { transmute(ptr) }
/// Coerce an immutable reference to be mutable.
unsafe fn transmute_immut_unsafe<T>(+ptr: *const T) -> *T { transmute(ptr) }
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
unsafe fn transmute_mut_region<T>(+ptr: &a/mut T) -> &b/mut T {
transmute(move ptr)
@ -78,6 +85,11 @@ unsafe fn copy_lifetime<S,T>(_ptr: &a/S, ptr: &T) -> &a/T {
transmute_region(ptr)
}
/// Transforms lifetime of the second pointer to match the first.
unsafe fn copy_lifetime_to_unsafe<S,T>(_ptr: &a/S, +ptr: *T) -> &a/T {
transmute(ptr)
}
/****************************************************************************
* Shared state & exclusive ARC

View File

@ -77,7 +77,7 @@ export swap;
export reverse;
export reversed;
export iter, iter_between, each, eachi, reach, reachi;
export each_mut, each_const;
export each_ref, each_mut_ref, each_const_ref;
export iter2;
export iteri;
export riter;
@ -336,7 +336,8 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
do as_buf(v) |p, _len| {
unsafe {
::unsafe::reinterpret_cast(
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
&(ptr::offset(p, start),
(end - start) * sys::size_of::<T>()))
}
}
}
@ -345,10 +346,11 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
assert (start <= end);
assert (end <= len(v));
do as_buf(v) |p, _len| {
do as_mut_buf(v) |p, _len| {
unsafe {
::unsafe::reinterpret_cast(
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
&(ptr::mut_offset(p, start),
(end - start) * sys::size_of::<T>()))
}
}
}
@ -357,10 +359,11 @@ pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
assert (start <= end);
assert (end <= len(v));
do as_buf(v) |p, _len| {
do as_const_buf(v) |p, _len| {
unsafe {
::unsafe::reinterpret_cast(
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
&(ptr::const_offset(p, start),
(end - start) * sys::size_of::<T>()))
}
}
}
@ -1141,7 +1144,7 @@ fn swap<T>(v: &[mut T], a: uint, b: uint) {
}
/// Reverse the order of elements in a vector, in place
fn reverse<T>(v: ~[mut T]) {
fn reverse<T>(v: &[mut T]) {
let mut i: uint = 0u;
let ln = len::<T>(v);
while i < ln / 2u { v[i] <-> v[ln - i - 1u]; i += 1u; }
@ -1203,7 +1206,12 @@ pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) {
* Return true to continue, false to break.
*/
#[inline(always)]
pure fn each<T>(v: &[const T], f: fn(T) -> bool) {
pure fn each<T>(v: &[T], f: fn(T) -> bool) {
// ^^^^
// NB---this CANNOT be &[const T]! The reason
// is that you are passing it to `f()` using
// an immutable.
do vec::as_buf(v) |p, n| {
let mut n = n;
let mut p = p;
@ -1217,21 +1225,52 @@ pure fn each<T>(v: &[const T], f: fn(T) -> bool) {
}
}
/**
* Iterates over a vector, with option to break
*
* Return true to continue, false to break.
*/
#[inline(always)]
pure fn each_ref<T>(v: &r/[T], f: fn(v: &r/T) -> bool) {
// this is not the most efficient impl, as it repeats the bound checks,
// but it's good enough
let mut i = 0;
let n = v.len();
while i < n {
if !f(&v[i]) {
return;
}
i += 1;
}
}
/// Like `each()`, but for the case where you have
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
pure fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
do vec::as_mut_buf(v) |p, n| {
let mut n = n;
let mut p = p;
while n > 0u {
unsafe {
if !f(&mut *p) { break; }
p = ptr::mut_offset(p, 1u);
}
n -= 1u;
fn each_mut_ref<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
if !f(&mut v[i]) {
return;
}
i += 1;
}
}
/// Like `each()`, but for the case where you have
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
if !f(&const v[i]) {
return;
}
i += 1;
}
}
@ -1241,7 +1280,7 @@ pure fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pure fn eachi<T>(v: &[const T], f: fn(uint, T) -> bool) {
pure fn eachi<T>(v: &[T], f: fn(uint, T) -> bool) {
do vec::as_buf(v) |p, n| {
let mut i = 0u;
let mut p = p;
@ -1392,10 +1431,18 @@ pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
* foreign interop.
*/
#[inline(always)]
pure fn as_buf<T,U>(s: &[const T],
pure fn as_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */
f: fn(*T, uint) -> U) -> U {
// NB---People keep changing the type of s to `&[const T]`. This is
// unsound. The reason is that we are going to create immutable pointers
// into `s` and pass them to `f()`, but in fact they are potentially
// pointing at *mutable memory*. Use `as_const_buf` or `as_mut_buf`
// instead!
unsafe {
let v : *(*T,uint) = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
let v : *(*T,uint) =
::unsafe::reinterpret_cast(&ptr::addr_of(s));
let (buf,len) = *v;
f(buf, len / sys::size_of::<T>())
}
@ -1405,11 +1452,12 @@ pure fn as_buf<T,U>(s: &[const T],
#[inline(always)]
pure fn as_const_buf<T,U>(s: &[const T],
f: fn(*const T, uint) -> U) -> U {
do as_buf(s) |p, len| {
unsafe {
let pp : *const T = ::unsafe::reinterpret_cast(&p);
f(pp, len)
}
unsafe {
let v : *(*const T,uint) =
::unsafe::reinterpret_cast(&ptr::addr_of(s));
let (buf,len) = *v;
f(buf, len / sys::size_of::<T>())
}
}
@ -1417,11 +1465,12 @@ pure fn as_const_buf<T,U>(s: &[const T],
#[inline(always)]
pure fn as_mut_buf<T,U>(s: &[mut T],
f: fn(*mut T, uint) -> U) -> U {
do as_buf(s) |p, len| {
unsafe {
let pp : *mut T = ::unsafe::reinterpret_cast(&p);
f(pp, len)
}
unsafe {
let v : *(*mut T,uint) =
::unsafe::reinterpret_cast(&ptr::addr_of(s));
let (buf,len) = *v;
f(buf, len / sys::size_of::<T>())
}
}
@ -1765,7 +1814,7 @@ mod unsafe {
let mut dst = ~[];
reserve(dst, elts);
set_len(dst, elts);
as_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
as_mut_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
move dst
}
@ -1792,18 +1841,24 @@ mod unsafe {
* would also make any pointers to it invalid.
*/
#[inline(always)]
unsafe fn to_ptr<T>(v: ~[const T]) -> *T {
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
}
#[inline(always)]
unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T {
unsafe fn to_ptr<T>(v: &[T]) -> *T {
let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v));
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
}
/** see `to_ptr()` */
#[inline(always)]
unsafe fn to_const_ptr<T>(v: &[const T]) -> *const T {
let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v));
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
}
/** see `to_ptr()` */
#[inline(always)]
unsafe fn to_mut_ptr<T>(v: &[mut T]) -> *mut T {
let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v));
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
}
/**
* Form a slice from a pointer and length (as a number of units,
@ -1822,7 +1877,7 @@ mod unsafe {
*/
#[inline(always)]
unsafe fn get<T: Copy>(v: &[const T], i: uint) -> T {
as_buf(v, |p, _len| *ptr::offset(p, i))
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
}
/**
@ -1846,8 +1901,8 @@ mod unsafe {
* may overlap.
*/
unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
do as_buf(dst) |p_dst, _len_dst| {
do as_buf(src) |p_src, _len_src| {
do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memcpy(p_dst, p_src, count)
}
}
@ -1860,8 +1915,8 @@ mod unsafe {
* may overlap.
*/
unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
do as_buf(dst) |p_dst, _len_dst| {
do as_buf(src) |p_src, _len_src| {
do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memmove(p_dst, p_src, count)
}
}
@ -1952,12 +2007,12 @@ mod u8 {
// This cannot be used with iter-trait.rs because of the region pointer
// required in the slice.
impl<A> &[const A]: iter::BaseIter<A> {
impl<A> &[A]: iter::BaseIter<A> {
pure fn each(blk: fn(A) -> bool) { each(self, blk) }
pure fn size_hint() -> Option<uint> { Some(len(self)) }
}
impl<A> &[const A]: iter::ExtendedIter<A> {
impl<A> &[A]: iter::ExtendedIter<A> {
pure fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }

View File

@ -89,7 +89,7 @@ fn round_up_to(base: uint, align: uint) -> uint {
// in it.
unsafe fn destroy_chunk(chunk: Chunk) {
let mut idx = 0;
let buf = vec::unsafe::to_ptr_slice(chunk.data);
let buf = vec::unsafe::to_ptr(chunk.data);
let fill = chunk.fill;
while idx < fill {
@ -156,7 +156,7 @@ impl &Arena {
// start, n_bytes, align, head.fill);
unsafe {
ptr::offset(vec::unsafe::to_ptr_slice(head.data), start)
ptr::offset(vec::unsafe::to_ptr(head.data), start)
}
}
@ -200,7 +200,7 @@ impl &Arena {
// start, n_bytes, align, head.fill);
unsafe {
let buf = vec::unsafe::to_ptr_slice(head.data);
let buf = vec::unsafe::to_ptr(head.data);
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
}
}

View File

@ -57,7 +57,7 @@ fn create<T: Copy>() -> Deque<T> {
self.lo = self.elts.len() - 1u;
} else { self.lo -= 1u; }
if self.lo == self.hi {
self.elts.swap(|v| grow(self.nelts, oldlo, move v));
self.elts.swap_mut(|v| grow(self.nelts, oldlo, move v));
self.lo = self.elts.len() - 1u;
self.hi = self.nelts;
}
@ -66,7 +66,7 @@ fn create<T: Copy>() -> Deque<T> {
}
fn add_back(t: T) {
if self.lo == self.hi && self.nelts != 0u {
self.elts.swap(|v| grow(self.nelts, self.lo, move v));
self.elts.swap_mut(|v| grow(self.nelts, self.lo, move v));
self.lo = 0u;
self.hi = self.nelts;
}
@ -108,8 +108,7 @@ fn create<T: Copy>() -> Deque<T> {
mut hi: 0u,
elts:
dvec::from_vec(
vec::to_mut(
vec::from_elem(initial_capacity, None)))
vec::from_elem(initial_capacity, None))
};
(move repr) as Deque::<T>
}

View File

@ -646,12 +646,12 @@ pure fn lt(value0: Json, value1: Json) -> bool {
let (d0_flat, d1_flat) = {
let d0_flat = dvec::DVec();
for d0.each |k, v| { d0_flat.push((k, v)); }
let d0_flat = dvec::unwrap(move d0_flat);
let mut d0_flat = dvec::unwrap(move d0_flat);
d0_flat.qsort();
let mut d1_flat = dvec::DVec();
for d1.each |k, v| { d1_flat.push((k, v)); }
let d1_flat = dvec::unwrap(move d1_flat);
let mut d1_flat = dvec::unwrap(move d1_flat);
d1_flat.qsort();
(move d0_flat, move d1_flat)

View File

@ -736,8 +736,8 @@ impl Url: Eq {
}
impl Url: IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
self.to_str().iter_bytes(lsb0, f)
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
unchecked { self.to_str() }.iter_bytes(lsb0, f)
}
}
@ -1077,11 +1077,11 @@ mod tests {
assert encode_form_urlencoded(m) == ~"";
let m = str_hash();
m.insert(~"foo", @dvec::from_vec(~[mut @~"bar", @~"123"]));
m.insert(~"foo", @dvec::from_vec(~[@~"bar", @~"123"]));
assert encode_form_urlencoded(m) == ~"foo=bar&foo=123";
let m = str_hash();
m.insert(~"foo bar", @dvec::from_vec(~[mut @~"abc", @~"12 = 34"]));
m.insert(~"foo bar", @dvec::from_vec(~[@~"abc", @~"12 = 34"]));
assert encode_form_urlencoded(m) == ~"foo+bar=abc&foo+bar=12+%3D+34";
}

62
src/libstd/set.rs Normal file
View File

@ -0,0 +1,62 @@
import dvec::dvec;
import map::{hashfn, eqfn, hashmap};
struct set<K: copy> {
mut implementation: option<set_implementation<K>>
}
struct list_set<K> {
hasher: hashfn<K>;
eqer: eqfn<K>;
elements: ~[K];
}
enum set_implementation<K: copy> {
impl_with_list(list_set<K>),
impl_with_map(hashmap<K, ()>)
}
const threshold: uint = 25; // completely arbitrary.
impl<K> &list_set {
pure fn contains(element: &K) {
for self.elements.each |existing_element| {
if self.eqer(element, existing_element) {
return true;
}
}
return false;
}
pure fn convert_to_map() -> hashmap<K, ()> {
...
}
}
impl<K: copy> set<K> {
fn add(+element: K) -> bool {
let mut set_impl = option::swap_unwrap(&mut self.implementation);
let contained_before = match set_impl {
impl_with_list(ref mut list_set) => {
if list_set.elements.len() >= threshold {
// convert to a map
self.implementation = some(list_set.convert_to_map());
return self.add(move element);
}
if list_set.contains(&element) {
false
} else {
vec::push(list_set.elements, element);
true
}
}
impl_with_map(ref map) => {
let contained_before = map.insert(element, ());
}
}
self.implementation = some(move set_impl);
return true;
}
}

View File

@ -161,7 +161,7 @@ fn sha1() -> Sha1 {
fn mk_result(st: &Sha1State) -> ~[u8] {
if !(*st).computed { pad_msg(st); (*st).computed = true; }
let mut rs: ~[u8] = ~[];
for vec::each_mut((*st).h) |ptr_hpart| {
for vec::each_mut_ref((*st).h) |ptr_hpart| {
let hpart = *ptr_hpart;
let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;

View File

@ -92,7 +92,7 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
old.is_some()
}
fn clear() {
self.v.set(~[mut]);
self.v.set(~[]);
}
fn contains_key(+key: uint) -> bool {
contains_key(self, key)

View File

@ -311,7 +311,7 @@ enum binding_mode {
}
impl binding_mode : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
bind_by_value => 0u8.iter_bytes(lsb0, f),
@ -385,7 +385,7 @@ enum pat_ {
enum mutability { m_mutbl, m_imm, m_const, }
impl mutability : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -524,7 +524,7 @@ enum inferable<T> {
}
impl<T: to_bytes::IterBytes> inferable<T> : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
expl(ref t) =>
to_bytes::iter_bytes_2(&0u8, t, lsb0, f),
@ -560,7 +560,7 @@ impl<T:cmp::Eq> inferable<T> : cmp::Eq {
enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy }
impl rmode : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -922,7 +922,7 @@ enum trait_method {
enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, }
impl int_ty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -951,7 +951,7 @@ impl int_ty: cmp::Eq {
enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, }
impl uint_ty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -978,7 +978,7 @@ impl uint_ty: cmp::Eq {
enum float_ty { ty_f, ty_f32, ty_f64, }
impl float_ty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -1082,7 +1082,7 @@ impl ty : cmp::Eq {
}
impl ty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f);
}
}
@ -1106,7 +1106,7 @@ enum purity {
}
impl purity : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -1126,7 +1126,7 @@ enum ret_style {
}
impl ret_style : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -1423,7 +1423,7 @@ enum item_ {
enum class_mutability { class_mutable, class_immutable }
impl class_mutability : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}

View File

@ -254,7 +254,7 @@ pure fn is_call_expr(e: @expr) -> bool {
// This makes def_id hashable
impl def_id : core::to_bytes::IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: core::to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: core::to_bytes::Cb) {
core::to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f);
}
}

View File

@ -127,7 +127,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
pure fn by_lo(a: &gather_item, b: &gather_item) -> bool {
a.lo < b.lo
}
vec::to_mut(std::sort::merge_sort(by_lo, v))
std::sort::merge_sort(by_lo, v)
};
return cx;
}

View File

@ -35,7 +35,7 @@ impl ObsoleteSyntax : cmp::Eq {
impl ObsoleteSyntax: to_bytes::IterBytes {
#[inline(always)]
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as uint).iter_bytes(lsb0, f);
}
}

View File

@ -3556,8 +3556,8 @@ impl parser {
}
{attrs_remaining: attrs,
view_items: vec::from_mut(dvec::unwrap(move view_items)),
items: vec::from_mut(dvec::unwrap(move items))}
view_items: dvec::unwrap(move view_items),
items: dvec::unwrap(move items)}
}
// Parses a source module as a crate

View File

@ -951,7 +951,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
let ids = val_dsr.read_to_vec(|| {
xcx.tr_id(val_dsr.read_int())
});
let dvec = @dvec::from_vec(vec::to_mut(ids));
let dvec = @dvec::from_vec(move ids);
dcx.maps.last_use_map.insert(id, dvec);
} else if tag == (c::tag_table_method_map as uint) {
dcx.maps.method_map.insert(

View File

@ -415,7 +415,7 @@ impl root_map_key : cmp::Eq {
}
impl root_map_key : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.id, &self.derefs, lsb0, f);
}
}

View File

@ -408,7 +408,7 @@ impl gather_loan_ctxt {
}
None => {
self.req_maps.req_loan_map.insert(
scope_id, @dvec::from_vec(~[mut loans]));
scope_id, @dvec::from_vec(~[loans]));
}
}
}

View File

@ -285,7 +285,7 @@ fn get_options(ccx: @crate_ctxt, m: match_, col: uint) -> ~[opt] {
}
}
}
return vec::from_mut(dvec::unwrap(move found));
return dvec::unwrap(move found);
}
fn extract_variant_args(bcx: block, pat_id: ast::node_id,

View File

@ -446,7 +446,7 @@ fn InBoundsGEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) ->
unsafe {
count_insn(cx, "inboundsgep");
return llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
vec::unsafe::to_ptr_slice(Indices),
vec::unsafe::to_ptr(Indices),
Indices.len() as c_uint,
noname());
}

View File

@ -1133,7 +1133,7 @@ impl mono_id_: cmp::Eq {
}
impl mono_param_id : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
mono_precise(t, mids) =>
to_bytes::iter_bytes_3(&0u8, &ty::type_id(t), &mids, lsb0, f),
@ -1147,7 +1147,7 @@ impl mono_param_id : to_bytes::IterBytes {
}
impl mono_id_ : core::to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.def, &self.params, lsb0, f);
}
}

View File

@ -43,7 +43,7 @@ impl nominal_id_ : core::cmp::Eq {
}
impl nominal_id_ : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.did, &self.parent_id, lsb0, f);
for self.tps.each |t| {
ty::type_id(t).iter_bytes(lsb0, f);

View File

@ -118,7 +118,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
fn type_needs(cx: ctx, use_: uint, ty: ty::t) {
// Optimization -- don't descend type if all params already have this use
for vec::each_mut(cx.uses) |u| {
for vec::each_mut_ref(cx.uses) |u| {
if *u & use_ != use_ {
type_needs_inner(cx, use_, ty, @Nil);
return;

View File

@ -247,7 +247,7 @@ impl creader_cache_key : cmp::Eq {
}
impl creader_cache_key : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_3(&self.cnum, &self.pos, &self.len, lsb0, f);
}
}
@ -262,7 +262,7 @@ impl intern_key: cmp::Eq {
}
impl intern_key : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.sty, &self.o_def_id, lsb0, f);
}
}
@ -404,7 +404,7 @@ enum closure_kind {
}
impl closure_kind : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(self as u8).iter_bytes(lsb0, f)
}
}
@ -422,7 +422,7 @@ enum fn_proto {
}
impl fn_proto : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
proto_bare =>
0u8.iter_bytes(lsb0, f),
@ -500,7 +500,7 @@ impl param_ty: cmp::Eq {
}
impl param_ty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.idx, &self.def_id, lsb0, f)
}
}
@ -674,7 +674,7 @@ enum InferTy {
}
impl InferTy : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
TyVar(ref tv) => to_bytes::iter_bytes_2(&0u8, tv, lsb0, f),
IntVar(ref iv) => to_bytes::iter_bytes_2(&1u8, iv, lsb0, f)
@ -683,7 +683,7 @@ impl InferTy : to_bytes::IterBytes {
}
impl param_bound : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
bound_copy => 0u8.iter_bytes(lsb0, f),
bound_owned => 1u8.iter_bytes(lsb0, f),
@ -747,25 +747,25 @@ impl purity: purity_to_str {
}
impl RegionVid : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(*self).iter_bytes(lsb0, f)
}
}
impl TyVid : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(*self).iter_bytes(lsb0, f)
}
}
impl IntVid : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(*self).iter_bytes(lsb0, f)
}
}
impl FnVid : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
(*self).iter_bytes(lsb0, f)
}
}
@ -2432,7 +2432,7 @@ fn index_sty(cx: ctxt, sty: &sty) -> Option<mt> {
}
impl bound_region : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
ty::br_self => 0u8.iter_bytes(lsb0, f),
@ -2449,7 +2449,7 @@ impl bound_region : to_bytes::IterBytes {
}
impl region : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
re_bound(ref br) =>
to_bytes::iter_bytes_2(&0u8, br, lsb0, f),
@ -2469,7 +2469,7 @@ impl region : to_bytes::IterBytes {
}
impl vstore : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
vstore_fixed(ref u) =>
to_bytes::iter_bytes_2(&0u8, u, lsb0, f),
@ -2484,7 +2484,7 @@ impl vstore : to_bytes::IterBytes {
}
impl substs : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_3(&self.self_r,
&self.self_ty,
&self.tps, lsb0, f)
@ -2492,28 +2492,28 @@ impl substs : to_bytes::IterBytes {
}
impl mt : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.ty,
&self.mutbl, lsb0, f)
}
}
impl field : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.ident,
&self.mt, lsb0, f)
}
}
impl arg : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.mode,
&self.ty, lsb0, f)
}
}
impl sty : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
ty_nil => 0u8.iter_bytes(lsb0, f),
ty_bool => 1u8.iter_bytes(lsb0, f),

View File

@ -350,7 +350,7 @@ impl Constraint: cmp::Eq {
}
impl Constraint : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
match self {
ConstrainVarSubVar(ref v0, ref v1) =>
to_bytes::iter_bytes_3(&0u8, v0, v1, lsb0, f),
@ -377,7 +377,7 @@ impl TwoRegions: cmp::Eq {
}
impl TwoRegions : to_bytes::IterBytes {
fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.a, &self.b, lsb0, f)
}
}

View File

@ -12,7 +12,7 @@ fn collect_raw(num: uint) -> ~[uint] {
return result;
}
fn collect_dvec(num: uint) -> ~[mut uint] {
fn collect_dvec(num: uint) -> ~[uint] {
let result = DVec();
for uint::range(0u, num) |i| {
result.push(i);
@ -43,7 +43,7 @@ fn main(args: ~[~str]) {
let raw = mid - start;
let dvec = end - mid;
let maxf = max as float;
let rawf = raw as float;
let dvecf = dvec as float;

View File

@ -5,11 +5,11 @@ type parser = {
};
trait parse {
fn parse() -> ~[mut int];
fn parse() -> ~[int];
}
impl parser: parse {
fn parse() -> ~[mut int] {
fn parse() -> ~[int] {
dvec::unwrap(move self.tokens) //~ ERROR illegal move from self
}
}

View File

@ -5,7 +5,7 @@ fn main() {
d.push(3);
d.push(4);
assert d.get() == ~[3, 4];
d.set(~[mut 5]);
d.set(~[5]);
d.push(6);
d.push(7);
d.push(8);
@ -23,6 +23,6 @@ fn main() {
assert e == exp[i];
}
let v = vec::from_mut(dvec::unwrap(move d));
let v = dvec::unwrap(move d);
assert v == exp;
}

View File

@ -9,7 +9,7 @@ use std::map::*;
use std::map::str_hash;
fn main() {
let v = ~[mut @~"hi"];
let v = ~[@~"hi"];
let m: req::header_map = str_hash();
m.insert(~"METHOD", @dvec::from_vec(v));
request::<int>(m);