diff --git a/doc/rust.md b/doc/rust.md index 0173f61e7307d..136c7ee9da3f2 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -2187,7 +2187,7 @@ A loop expression denotes an infinite loop; see [Continue expressions](#continue-expressions) for continue expressions. ~~~~~~~~{.ebnf .gram} -loop_expr : "loop" [ ident ':' ] '{' block '}'; +loop_expr : [ lifetime ':' ] "loop" '{' block '}'; ~~~~~~~~ A `loop` expression may optionally have a _label_. @@ -2198,7 +2198,7 @@ See [Break expressions](#break-expressions). ### Break expressions ~~~~~~~~{.ebnf .gram} -break_expr : "break" [ ident ]; +break_expr : "break" [ lifetime ]; ~~~~~~~~ A `break` expression has an optional `label`. @@ -2211,7 +2211,7 @@ but must enclose it. ### Continue expressions ~~~~~~~~{.ebnf .gram} -continue_expr : "loop" [ ident ]; +continue_expr : "loop" [ lifetime ]; ~~~~~~~~ A continue expression, written `loop`, also has an optional `label`. @@ -2393,7 +2393,7 @@ variables in the arm's block, and control enters the block. An example of an `match` expression: -~~~~ +~~~~ {.xfail-test} # fn process_pair(a: int, b: int) { } # fn process_ten() { } diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 6ce1acf59472c..9f59f1d8fe48d 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -14,7 +14,6 @@ use cast::transmute; use kinds::Copy; use old_iter; use option::Option; -use ptr::addr_of; use sys; use uint; use vec; @@ -40,8 +39,7 @@ pub mod rustrt { #[inline(always)] pub fn capacity(v: @[T]) -> uint { unsafe { - let repr: **raw::VecRepr = - ::cast::transmute(addr_of(&v)); + let repr: **raw::VecRepr = transmute(&v); (**repr).unboxed.alloc / sys::size_of::() } } @@ -187,13 +185,12 @@ pub mod traits {} pub mod raw { use at_vec::{capacity, rustrt}; - use cast::transmute; + use cast::{transmute, transmute_copy}; use libc; - use unstable::intrinsics::{move_val_init}; - use ptr::addr_of; use ptr; use sys; use uint; + use unstable::intrinsics::{move_val_init}; use vec; pub type VecRepr = vec::raw::VecRepr; @@ -208,18 +205,17 @@ pub mod raw { */ #[inline(always)] pub unsafe fn set_len(v: @[T], new_len: uint) { - let repr: **mut VecRepr = ::cast::transmute(addr_of(&v)); + let repr: **mut VecRepr = transmute(&v); (**repr).unboxed.fill = new_len * sys::size_of::(); } #[inline(always)] pub unsafe fn push(v: &mut @[T], initval: T) { - let repr: **VecRepr = ::cast::reinterpret_cast(&v); + let repr: **VecRepr = transmute_copy(&v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, initval); - } - else { + } else { push_slow(v, initval); } } @@ -229,7 +225,7 @@ pub mod raw { let repr: **mut VecRepr = ::cast::transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); - let p = addr_of(&((**repr).unboxed.data)); + let p = &((**repr).unboxed.data); let p = ptr::offset(p, fill) as *mut T; move_val_init(&mut(*p), initval); } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 1d214f402f5ac..6fb737d37709f 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -10,21 +10,56 @@ //! Unsafe casting functions +use sys; +use unstable; + pub mod rusti { #[abi = "rust-intrinsic"] #[link_name = "rusti"] pub extern "rust-intrinsic" { fn forget(+x: T); + + #[cfg(stage0)] fn reinterpret_cast(&&e: T) -> U; + + #[cfg(stage1)] + #[cfg(stage2)] + #[cfg(stage3)] + fn transmute(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(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(src: &T) -> U { + rusti::reinterpret_cast(*src) +} + +#[inline(always)] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub unsafe fn transmute_copy(src: &T) -> U { + let mut dest: U = unstable::intrinsics::init(); + { + let dest_ptr: *mut u8 = rusti::transmute(&mut dest); + let src_ptr: *u8 = rusti::transmute(src); + unstable::intrinsics::memmove64(dest_ptr, + src_ptr, + sys::size_of::() as u64); + } + dest +} + /** * Move a thing into the void * @@ -53,12 +88,21 @@ pub unsafe fn bump_box_refcount(t: @T) { forget(t); } * assert!(transmute("L") == ~[76u8, 0u8]); */ #[inline(always)] +#[cfg(stage0)] pub unsafe fn transmute(thing: L) -> G { let newthing: G = reinterpret_cast(&thing); forget(thing); newthing } +#[inline(always)] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub unsafe fn transmute(thing: L) -> G { + rusti::transmute(thing) +} + /// Coerce an immutable reference to be mutable. #[inline(always)] pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) } @@ -112,11 +156,20 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T { #[cfg(test)] mod tests { - use cast::{bump_box_refcount, reinterpret_cast, transmute}; + use cast::{bump_box_refcount, transmute}; #[test] + #[cfg(stage0)] fn test_reinterpret_cast() { - assert!(1u == unsafe { reinterpret_cast(&1) }); + 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) }); } #[test] @@ -125,8 +178,8 @@ mod tests { let box = @~"box box box"; // refcount 1 bump_box_refcount(box); // refcount 2 let ptr: *int = transmute(box); // refcount 2 - let _box1: @~str = reinterpret_cast(&ptr); - let _box2: @~str = reinterpret_cast(&ptr); + let _box1: @~str = ::cast::transmute_copy(&ptr); + let _box2: @~str = ::cast::transmute_copy(&ptr); assert!(*_box1 == ~"box box box"); assert!(*_box2 == ~"box box box"); // Will destroy _box1 and _box2. Without the bump, this would diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 2656115dca258..50a3bba049bbb 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -327,6 +327,7 @@ impl ::clone::Clone for SharedChan { #[allow(non_camel_case_types)] pub mod oneshot { priv use core::kinds::Owned; + use ptr::to_unsafe_ptr; pub fn init() -> (client::Oneshot, server::Oneshot) { pub use core::pipes::HasBuffer; @@ -341,7 +342,7 @@ pub mod oneshot { do ::core::pipes::entangle_buffer(buffer) |buffer, data| { { data.Oneshot.set_buffer(buffer); - ::ptr::addr_of(&(data.Oneshot)) + to_unsafe_ptr(&data.Oneshot) } } } @@ -394,24 +395,55 @@ pub mod oneshot { } /// The send end of a oneshot pipe. -pub type ChanOne = oneshot::client::Oneshot; +pub struct ChanOne { + contents: oneshot::client::Oneshot +} + +impl ChanOne { + pub fn new(contents: oneshot::client::Oneshot) -> ChanOne { + ChanOne { + contents: contents + } + } +} + /// The receive end of a oneshot pipe. -pub type PortOne = oneshot::server::Oneshot; +pub struct PortOne { + contents: oneshot::server::Oneshot +} + +impl PortOne { + pub fn new(contents: oneshot::server::Oneshot) -> PortOne { + PortOne { + contents: contents + } + } +} /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair. pub fn oneshot() -> (PortOne, ChanOne) { let (chan, port) = oneshot::init(); - (port, chan) + (PortOne::new(port), ChanOne::new(chan)) } pub impl PortOne { fn recv(self) -> T { recv_one(self) } fn try_recv(self) -> Option { try_recv_one(self) } + fn unwrap(self) -> oneshot::server::Oneshot { + match self { + PortOne { contents: s } => s + } + } } pub impl ChanOne { fn send(self, data: T) { send_one(self, data) } fn try_send(self, data: T) -> bool { try_send_one(self, data) } + fn unwrap(self) -> oneshot::client::Oneshot { + match self { + ChanOne { contents: s } => s + } + } } /** @@ -419,33 +451,47 @@ pub impl ChanOne { * closed. */ pub fn recv_one(port: PortOne) -> T { - let oneshot::send(message) = recv(port); - message + match port { + PortOne { contents: port } => { + let oneshot::send(message) = recv(port); + message + } + } } /// Receive a message from a oneshot pipe unless the connection was closed. pub fn try_recv_one (port: PortOne) -> Option { - let message = try_recv(port); - - if message.is_none() { None } - else { - let oneshot::send(message) = message.unwrap(); - Some(message) + match port { + PortOne { contents: port } => { + let message = try_recv(port); + + if message.is_none() { + None + } else { + let oneshot::send(message) = message.unwrap(); + Some(message) + } + } } } /// Send a message on a oneshot pipe, failing if the connection was closed. pub fn send_one(chan: ChanOne, data: T) { - oneshot::client::send(chan, data); + match chan { + ChanOne { contents: chan } => oneshot::client::send(chan, data), + } } /** * Send a message on a oneshot pipe, or return false if the connection was * closed. */ -pub fn try_send_one(chan: ChanOne, data: T) - -> bool { - oneshot::client::try_send(chan, data).is_some() +pub fn try_send_one(chan: ChanOne, data: T) -> bool { + match chan { + ChanOne { contents: chan } => { + oneshot::client::try_send(chan, data).is_some() + } + } } @@ -519,11 +565,11 @@ mod test { #[test] fn test_oneshot() { - let (c, p) = oneshot::init(); + let (p, c) = oneshot(); - oneshot::client::send(c, ()); + c.send(()); - recv_one(p) + p.recv() } #[test] diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index 5c4181c10cf3b..c3518cc8b6ee2 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -53,7 +53,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] { let res = rustrt::tdefl_compress_mem_to_heap(b as *c_void, len as size_t, - ptr::addr_of(&outsz), + &outsz, lz_norm); assert!(res as int != 0); let out = vec::raw::from_buf_raw(res as *u8, @@ -71,7 +71,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] { let res = rustrt::tinfl_decompress_mem_to_heap(b as *c_void, len as size_t, - ptr::addr_of(&outsz), + &outsz, 0); assert!(res as int != 0); let out = vec::raw::from_buf_raw(res as *u8, diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index a6bae3c76631c..0d0a98359d14c 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -338,7 +338,7 @@ pub fn cleanup_stack_for_failure() { // own stack roots on the stack anyway. let sentinel_box = ~0; let sentinel: **Word = if expect_sentinel() { - cast::transmute(ptr::addr_of(&sentinel_box)) + cast::transmute(&sentinel_box) } else { ptr::null() }; diff --git a/src/libcore/managed.rs b/src/libcore/managed.rs index 2bd3959acf4de..debca1ead82f8 100644 --- a/src/libcore/managed.rs +++ b/src/libcore/managed.rs @@ -10,7 +10,7 @@ //! Operations on managed box types -use ptr; +use ptr::to_unsafe_ptr; #[cfg(notest)] use cmp::{Eq, Ord}; @@ -38,13 +38,15 @@ pub mod raw { #[inline(always)] pub fn ptr_eq(a: @T, b: @T) -> bool { //! Determine if two shared boxes point to the same object - ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) + let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b); + a_ptr == b_ptr } #[inline(always)] pub fn mut_ptr_eq(a: @mut T, b: @mut T) -> bool { //! Determine if two mutable shared boxes point to the same object - ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) + let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b); + a_ptr == b_ptr } #[cfg(notest)] diff --git a/src/libcore/option.rs b/src/libcore/option.rs index d3519854a0a36..17192b4257b16 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -49,7 +49,6 @@ use num::Zero; use old_iter::{BaseIter, MutableIter, ExtendedIter}; use old_iter; -#[cfg(test)] use ptr; #[cfg(test)] use str; /// The option type @@ -481,12 +480,14 @@ pub impl Option { #[test] fn test_unwrap_ptr() { - let x = ~0; - let addr_x = ptr::addr_of(&(*x)); - let opt = Some(x); - let y = opt.unwrap(); - let addr_y = ptr::addr_of(&(*y)); - assert!(addr_x == addr_y); + unsafe { + let x = ~0; + let addr_x: *int = ::cast::transmute(&*x); + let opt = Some(x); + let y = opt.unwrap(); + let addr_y: *int = ::cast::transmute(&*y); + assert!(addr_x == addr_y); + } } #[test] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index edc61299af96d..462c5be3bcf75 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -21,6 +21,11 @@ use str; use to_str::ToStr; use ascii::{AsciiCast, AsciiStr}; +#[cfg(windows)] +pub use Path = self::WindowsPath; +#[cfg(unix)] +pub use Path = self::PosixPath; + #[deriving(Clone, Eq)] pub struct WindowsPath { host: Option<~str>, @@ -72,22 +77,6 @@ pub trait GenericPath { fn is_absolute(&self) -> bool; } -#[cfg(windows)] -pub type Path = WindowsPath; - -#[cfg(windows)] -pub fn Path(s: &str) -> Path { - WindowsPath(s) -} - -#[cfg(unix)] -pub type Path = PosixPath; - -#[cfg(unix)] -pub fn Path(s: &str) -> Path { - PosixPath(s) -} - #[cfg(target_os = "linux")] #[cfg(target_os = "android")] mod stat { diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 2ec3afca61269..95b24d20a4bc2 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -82,7 +82,7 @@ bounded and unbounded protocols allows for less code duplication. */ -use cast::{forget, reinterpret_cast, transmute}; +use cast::{forget, transmute, transmute_copy}; use either::{Either, Left, Right}; use kinds::Owned; use libc; @@ -95,7 +95,7 @@ use vec; static SPIN_COUNT: uint = 0; macro_rules! move_it ( - { $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } ) + { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } ) ) #[deriving(Eq)] @@ -131,7 +131,7 @@ pub struct PacketHeader { mut state: State, mut blocked_task: *rust_task, - // This is a reinterpret_cast of a ~buffer, that can also be cast + // This is a transmute_copy of a ~buffer, that can also be cast // to a buffer_header if need be. mut buffer: *libc::c_void, } @@ -170,12 +170,12 @@ pub impl PacketHeader { // thing. You'll proobably want to forget them when you're done. unsafe fn buf_header(&self) -> ~BufferHeader { assert!(self.buffer.is_not_null()); - reinterpret_cast(&self.buffer) + transmute_copy(&self.buffer) } fn set_buffer(&self, b: ~Buffer) { unsafe { - self.buffer = reinterpret_cast(&b); + self.buffer = transmute_copy(&b); } } } @@ -211,14 +211,14 @@ fn unibuffer() -> ~Buffer> { }; unsafe { - b.data.header.buffer = reinterpret_cast(&b); + b.data.header.buffer = transmute_copy(&b); } b } pub fn packet() -> *Packet { let b = unibuffer(); - let p = ptr::addr_of(&(b.data)); + let p = ptr::to_unsafe_ptr(&(b.data)); // We'll take over memory management from here. unsafe { forget(b) } p @@ -229,7 +229,7 @@ pub fn entangle_buffer( init: &fn(*libc::c_void, x: &T) -> *Packet) -> (SendPacketBuffered, RecvPacketBuffered) { - let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data); + let p = init(unsafe { transmute_copy(&buffer) }, &buffer.data); unsafe { forget(buffer) } (SendPacketBuffered(p), RecvPacketBuffered(p)) } @@ -305,7 +305,7 @@ impl ::ops::Drop for BufferResource { fn finalize(&self) { unsafe { let b = move_it!(self.buffer); - //let p = ptr::addr_of(*b); + //let p = ptr::to_unsafe_ptr(*b); //error!("drop %?", p); let old_count = intrinsics::atomic_xsub_rel(&mut b.header.ref_count, 1); //let old_count = atomic_xchng_rel(b.header.ref_count, 0); @@ -322,7 +322,7 @@ impl ::ops::Drop for BufferResource { } fn BufferResource(b: ~Buffer) -> BufferResource { - //let p = ptr::addr_of(*b); + //let p = ptr::to_unsafe_ptr(*b); //error!("take %?", p); unsafe { intrinsics::atomic_xadd_acq(&mut b.header.ref_count, 1) }; @@ -336,7 +336,7 @@ pub fn send(p: SendPacketBuffered, payload: T) -> bool { let header = p.header(); let p_ = p.unwrap(); let p = unsafe { &*p_ }; - assert!(ptr::addr_of(&(p.header)) == header); + assert!(ptr::to_unsafe_ptr(&(p.header)) == header); assert!(p.payload.is_none()); p.payload = Some(payload); let old_state = swap_state_rel(&mut p.header.state, Full); @@ -356,7 +356,7 @@ pub fn send(p: SendPacketBuffered, payload: T) -> bool { unsafe { rustrt::task_signal_event( old_task, - ptr::addr_of(&(p.header)) as *libc::c_void); + ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } } @@ -521,7 +521,7 @@ fn sender_terminate(p: *Packet) { unsafe { rustrt::task_signal_event( old_task, - ptr::addr_of(&(p.header)) as *libc::c_void); + ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } } @@ -665,7 +665,7 @@ pub fn SendPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::addr_of(&((*p).header))))) + get_buffer(ptr::to_unsafe_ptr(&((*p).header))))) } } } @@ -681,7 +681,7 @@ pub impl SendPacketBuffered { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::addr_of(&(packet.header)); + let header = ptr::to_unsafe_ptr(&(packet.header)); //forget(packet); header }, @@ -747,7 +747,7 @@ impl Selectable for RecvPacketBuffered { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::addr_of(&(packet.header)); + let header = ptr::to_unsafe_ptr(&(packet.header)); //forget(packet); header }, @@ -763,7 +763,7 @@ pub fn RecvPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::addr_of(&((*p).header))))) + get_buffer(ptr::to_unsafe_ptr(&((*p).header))))) } } } @@ -885,9 +885,9 @@ mod test { #[test] fn test_oneshot() { - let (c, p) = oneshot::init(); + let (p, c) = oneshot(); - oneshot::client::send(c, ()); + c.send(()); recv_one(p) } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 94474c3c02d62..86b36834bbd6e 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -39,17 +39,6 @@ pub mod libc_ { } } -pub mod rusti { - #[abi = "rust-intrinsic"] - pub extern "rust-intrinsic" { - fn addr_of(&&val: T) -> *T; - } -} - -/// Get an unsafe pointer to a value -#[inline(always)] -pub fn addr_of(val: &T) -> *T { unsafe { rusti::addr_of(*val) } } - /// Calculate the offset from a pointer #[inline(always)] pub fn offset(ptr: *T, count: uint) -> *T { @@ -130,7 +119,7 @@ pub unsafe fn set_memory(dst: *mut T, c: int, count: uint) { /** Transform a region pointer - &T - to an unsafe pointer - *T. This is safe, but is implemented with an unsafe block due to - reinterpret_cast. + transmute. */ #[inline(always)] pub fn to_unsafe_ptr(thing: &T) -> *T { @@ -140,7 +129,7 @@ pub fn to_unsafe_ptr(thing: &T) -> *T { /** 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. + transmute. */ #[inline(always)] pub fn to_const_unsafe_ptr(thing: &const T) -> *const T { @@ -150,7 +139,7 @@ pub fn to_const_unsafe_ptr(thing: &const T) -> *const T { /** Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T. This is safe, but is implemented with an unsafe block due to - reinterpret_cast. + transmute. */ #[inline(always)] pub fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { @@ -160,7 +149,7 @@ pub fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { /** Cast a region pointer - &T - to a uint. This is safe, but is implemented with an unsafe block due to - reinterpret_cast. + transmute. (I couldn't think of a cutesy name for this one.) */ diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 52944391851cf..967a8cdf49bf3 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -698,7 +698,7 @@ impl Rng for @R { * generator. */ pub fn random() -> T { - task_rng().gen() + (*task_rng()).gen() } #[cfg(test)] diff --git a/src/libcore/rt/thread.rs b/src/libcore/rt/thread.rs index 910e445f47b04..0f1ae09bd944b 100644 --- a/src/libcore/rt/thread.rs +++ b/src/libcore/rt/thread.rs @@ -21,10 +21,10 @@ pub struct Thread { pub impl Thread { fn start(main: ~fn()) -> Thread { - fn substart(main: &fn()) -> *raw_thread { - unsafe { rust_raw_thread_start(&main) } + fn substart(main: &~fn()) -> *raw_thread { + unsafe { rust_raw_thread_start(main) } } - let raw = substart(main); + let raw = substart(&main); Thread { main: main, raw_thread: raw @@ -39,6 +39,6 @@ impl Drop for Thread { } extern { - pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; + pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread; pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread); } diff --git a/src/libcore/rt/uv/mod.rs b/src/libcore/rt/uv/mod.rs index 4cbc8d7056970..cb7925abdcdf7 100644 --- a/src/libcore/rt/uv/mod.rs +++ b/src/libcore/rt/uv/mod.rs @@ -366,14 +366,15 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf { /// Transmute an owned vector to a Buf pub fn vec_to_uv_buf(v: ~[u8]) -> Buf { - let data = unsafe { malloc(v.len() as size_t) } as *u8; - assert!(data.is_not_null()); - do vec::as_imm_buf(v) |b, l| { - let data = data as *mut u8; - unsafe { ptr::copy_memory(data, b, l) } + unsafe { + let data = malloc(v.len() as size_t) as *u8; + assert!(data.is_not_null()); + do vec::as_imm_buf(v) |b, l| { + let data = data as *mut u8; + ptr::copy_memory(data, b, l) + } + uvll::buf_init(data, v.len()) } - let buf = unsafe { uvll::buf_init(data, v.len()) }; - return buf; } /// Transmute a Buf that was once a ~[u8] back to ~[u8] @@ -384,6 +385,7 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> { return Some(v); } else { // No buffer + rtdebug!("No buffer!"); return None; } } diff --git a/src/libcore/rt/uvll.rs b/src/libcore/rt/uvll.rs index b7eff217ff8c6..c9a696fcd15ca 100644 --- a/src/libcore/rt/uvll.rs +++ b/src/libcore/rt/uvll.rs @@ -252,7 +252,7 @@ pub unsafe fn async_send(async_handle: *uv_async_t) { } pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { let out_buf = uv_buf_t { base: ptr::null(), len: 0 as size_t }; - let out_buf_ptr = ptr::addr_of(&out_buf); + let out_buf_ptr = ptr::to_unsafe_ptr(&out_buf); rust_uv_buf_init(out_buf_ptr, input, len as size_t); return out_buf; } @@ -330,7 +330,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) { pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr = ptr::to_unsafe_ptr(&err); let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); return fmt!("LIBUV ERROR: name: %s msg: %s", @@ -339,7 +339,7 @@ pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str { pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr = ptr::to_unsafe_ptr(&err); let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); uv_err_data { err_name: err_name, err_msg: err_msg } diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index be5f898936843..ebf36e4e09ab4 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -93,7 +93,10 @@ pub mod rustrt { pub mod rusti { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { + #[cfg(stage0)] pub fn frame_address(f: &once fn(x: *u8)); + #[cfg(not(stage0))] + pub fn frame_address(+f: &once fn(x: *u8)); } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 92c965256ceaf..064bffa00561f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -18,6 +18,7 @@ */ use at_vec; +use cast::transmute; use cast; use char; use clone::Clone; @@ -2045,7 +2046,7 @@ pub fn as_c_str(s: &str, f: &fn(*libc::c_char) -> T) -> T { #[inline(always)] pub fn as_buf(s: &str, f: &fn(*u8, uint) -> T) -> T { unsafe { - let v : *(*u8,uint) = ::cast::transmute(ptr::addr_of(&s)); + let v : *(*u8,uint) = transmute(&s); let (buf,len) = *v; f(buf, len) } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index bdc3a17308da5..8cad0a2288642 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -154,7 +154,7 @@ pub fn pref_align_of_val(_val: &T) -> uint { #[inline(always)] pub fn refcount(t: @T) -> uint { unsafe { - let ref_ptr: *uint = cast::reinterpret_cast(&t); + let ref_ptr: *uint = cast::transmute_copy(&t); *ref_ptr - 1 } } diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 5d1cba79c053d..67bc3adeb41c0 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -59,9 +59,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { let map_ptr = rt::rust_get_task_local_data(task); if map_ptr.is_null() { let map: TaskLocalMap = @mut ~[]; - // Use reinterpret_cast -- transmute would take map away from us also. - rt::rust_set_task_local_data( - task, cast::transmute(map)); + rt::rust_set_task_local_data(task, cast::transmute(map)); rt::rust_task_local_data_atexit(task, cleanup_task_local_map); // Also need to reference it an extra time to keep it for now. let nonmut = cast::transmute:: TaskLocalMap { } } -unsafe fn key_to_key_value( - key: LocalDataKey) -> *libc::c_void { - +unsafe fn key_to_key_value(key: LocalDataKey) -> *libc::c_void { // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. // Use reintepret_cast -- transmute would leak (forget) the closure. - let pair: (*libc::c_void, *libc::c_void) = cast::reinterpret_cast(&key); + let pair: (*libc::c_void, *libc::c_void) = cast::transmute_copy(&key); pair.first() } diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index 2163a0e325f13..96429932b184a 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -1028,10 +1028,10 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) { let (p, ch) = stream::(); let x = ~1; - let x_in_parent = ptr::addr_of(&(*x)) as uint; + let x_in_parent = ptr::to_unsafe_ptr(&*x) as uint; do spawnfn || { - let x_in_child = ptr::addr_of(&(*x)) as uint; + let x_in_child = ptr::to_unsafe_ptr(&*x) as uint; ch.send(x_in_child); } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 43fdee67b7a85..507643ea5ec30 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -93,7 +93,7 @@ use util; #[cfg(test)] use task::default_task_opts; macro_rules! move_it ( - { $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } ) + { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } ) ) type TaskSet = HashSet<*rust_task>; diff --git a/src/libcore/unstable/intrinsics.rs b/src/libcore/unstable/intrinsics.rs index a18ad1738861d..b58429a10aad5 100644 --- a/src/libcore/unstable/intrinsics.rs +++ b/src/libcore/unstable/intrinsics.rs @@ -47,9 +47,8 @@ pub extern "rust-intrinsic" { pub fn forget(_: T) -> (); // XXX: intrinsic uses legacy modes + #[cfg(stage0)] fn reinterpret_cast(&&src: T) -> U; - // XXX: intrinsic uses legacy modes - fn addr_of(&&scr: T) -> *T; pub fn needs_drop() -> bool; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ef42647411a34..86767dc5bad85 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -26,11 +26,11 @@ use iterator::Iterator; use kinds::Copy; use libc; use option::{None, Option, Some}; -use unstable::intrinsics; +use ptr::to_unsafe_ptr; use ptr; -use ptr::addr_of; use sys; use uint; +use unstable::intrinsics; use vec; #[cfg(notest)] use cmp::Equiv; @@ -117,7 +117,7 @@ pub fn reserve_at_least(v: &mut ~[T], n: uint) { #[inline(always)] pub fn capacity(v: &const ~[T]) -> uint { unsafe { - let repr: **raw::VecRepr = ::cast::transmute(v); + let repr: **raw::VecRepr = transmute(v); (**repr).unboxed.alloc / sys::nonzero_size_of::() } } @@ -131,7 +131,7 @@ pub fn len(v: &const [T]) -> uint { // A botch to tide us over until core and std are fully demuted. pub fn uniq_len(v: &const ~[T]) -> uint { unsafe { - let v: &~[T] = ::cast::transmute(v); + let v: &~[T] = transmute(v); as_const_buf(*v, |_p, len| len) } } @@ -280,9 +280,8 @@ pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] { assert!(end <= len(v)); do as_imm_buf(v) |p, _len| { unsafe { - ::cast::transmute( - (ptr::offset(p, start), - (end - start) * sys::nonzero_size_of::())) + transmute((ptr::offset(p, start), + (end - start) * sys::nonzero_size_of::())) } } } @@ -295,9 +294,8 @@ pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint) assert!(end <= v.len()); do as_mut_buf(v) |p, _len| { unsafe { - ::cast::transmute( - (ptr::mut_offset(p, start), - (end - start) * sys::nonzero_size_of::())) + transmute((ptr::mut_offset(p, start), + (end - start) * sys::nonzero_size_of::())) } } } @@ -310,9 +308,8 @@ pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint) assert!(end <= len(v)); do as_const_buf(v) |p, _len| { unsafe { - ::cast::transmute( - (ptr::const_offset(p, start), - (end - start) * sys::nonzero_size_of::())) + transmute((ptr::const_offset(p, start), + (end - start) * sys::nonzero_size_of::())) } } } @@ -489,14 +486,14 @@ pub fn shift(v: &mut ~[T]) -> T { { let first_slice = slice(*v, 0, 1); let last_slice = slice(*v, next_ln, ln); - raw::copy_memory(::cast::transmute(last_slice), first_slice, 1); + raw::copy_memory(transmute(last_slice), first_slice, 1); } // Memcopy everything to the left one element { let init_slice = slice(*v, 0, next_ln); let tail_slice = slice(*v, 1, ln); - raw::copy_memory(::cast::transmute(init_slice), + raw::copy_memory(transmute(init_slice), tail_slice, next_ln); } @@ -626,7 +623,7 @@ pub fn swap_remove(v: &mut ~[T], index: uint) -> T { #[inline(always)] pub fn push(v: &mut ~[T], initval: T) { unsafe { - let repr: **raw::VecRepr = ::cast::transmute(&mut *v); + let repr: **raw::VecRepr = transmute(&mut *v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, initval); @@ -640,10 +637,10 @@ pub fn push(v: &mut ~[T], initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast(v: &mut ~[T], initval: T) { - let repr: **mut raw::VecRepr = ::cast::transmute(v); + let repr: **mut raw::VecRepr = transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::nonzero_size_of::(); - let p = addr_of(&((**repr).unboxed.data)); + let p = to_unsafe_ptr(&((**repr).unboxed.data)); let p = ptr::offset(p, fill) as *mut T; intrinsics::move_val_init(&mut(*p), initval); } @@ -1622,8 +1619,7 @@ pub fn as_imm_buf(s: &[T], // instead! unsafe { - let v : *(*T,uint) = - ::cast::transmute(addr_of(&s)); + let v : *(*T,uint) = transmute(&s); let (buf,len) = *v; f(buf, len / sys::nonzero_size_of::()) } @@ -1633,8 +1629,7 @@ pub fn as_imm_buf(s: &[T], #[inline(always)] pub fn as_const_buf(s: &const [T], f: &fn(*const T, uint) -> U) -> U { unsafe { - let v : *(*const T,uint) = - ::cast::transmute(addr_of(&s)); + let v : *(*const T,uint) = transmute(&s); let (buf,len) = *v; f(buf, len / sys::nonzero_size_of::()) } @@ -1644,8 +1639,7 @@ pub fn as_const_buf(s: &const [T], f: &fn(*const T, uint) -> U) -> U { #[inline(always)] pub fn as_mut_buf(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U { unsafe { - let v : *(*mut T,uint) = - ::cast::transmute(addr_of(&s)); + let v : *(*mut T,uint) = transmute(&s); let (buf,len) = *v; f(buf, len / sys::nonzero_size_of::()) } @@ -2429,13 +2423,13 @@ pub struct UnboxedVecRepr { /// Unsafe operations pub mod raw { + use cast::transmute; use kinds::Copy; use managed; use option::{None, Some}; - use unstable::intrinsics; - use ptr::addr_of; use ptr; use sys; + use unstable::intrinsics; use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, len, with_capacity}; /// The internal representation of a (boxed) vector @@ -2458,7 +2452,7 @@ pub mod raw { */ #[inline(always)] pub unsafe fn set_len(v: &mut ~[T], new_len: uint) { - let repr: **mut VecRepr = ::cast::transmute(v); + let repr: **mut VecRepr = transmute(v); (**repr).unboxed.fill = new_len * sys::nonzero_size_of::(); } @@ -2473,22 +2467,22 @@ pub mod raw { */ #[inline(always)] pub unsafe fn to_ptr(v: &[T]) -> *T { - let repr: **SliceRepr = ::cast::transmute(&v); - ::cast::transmute(addr_of(&((**repr).data))) + let repr: **SliceRepr = transmute(&v); + transmute(&((**repr).data)) } /** see `to_ptr()` */ #[inline(always)] pub unsafe fn to_const_ptr(v: &const [T]) -> *const T { - let repr: **SliceRepr = ::cast::transmute(&v); - ::cast::transmute(addr_of(&((**repr).data))) + let repr: **SliceRepr = transmute(&v); + transmute(&((**repr).data)) } /** see `to_ptr()` */ #[inline(always)] pub unsafe fn to_mut_ptr(v: &mut [T]) -> *mut T { - let repr: **SliceRepr = ::cast::transmute(&v); - ::cast::transmute(addr_of(&((**repr).data))) + let repr: **SliceRepr = transmute(&v); + transmute(&((**repr).data)) } /** @@ -2500,8 +2494,7 @@ pub mod raw { len: uint, f: &fn(v: &[T]) -> U) -> U { let pair = (p, len * sys::nonzero_size_of::()); - let v : *(&'blk [T]) = - ::cast::transmute(addr_of(&pair)); + let v : *(&'blk [T]) = transmute(&pair); f(*v) } @@ -2514,8 +2507,7 @@ pub mod raw { len: uint, f: &fn(v: &mut [T]) -> U) -> U { let pair = (p, len * sys::nonzero_size_of::()); - let v : *(&'blk mut [T]) = - ::cast::transmute(addr_of(&pair)); + let v : *(&'blk mut [T]) = transmute(&pair); f(*v) } diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index df233a2f2b52b..fc1efd3313cbc 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -18,42 +18,38 @@ #[license = "MIT/ASL2"]; #[crate_type = "lib"]; -#[legacy_modes]; - -#[allow(vecs_implicitly_copyable)]; #[allow(non_camel_case_types)]; -#[allow(deprecated_mode)]; -#[allow(deprecated_pattern)]; extern mod std(vers = "0.7-pre"); extern mod syntax(vers = "0.7-pre"); use core::run; -use syntax::{ast, fold, visit, codemap}; +use syntax::diagnostic; +use syntax::parse::token::ident_interner; +use syntax::parse::token; use syntax::parse; use syntax::print::pprust; -use syntax::diagnostic; +use syntax::{ast, fold, visit, codemap}; #[deriving(Eq)] pub enum test_mode { tm_converge, tm_run, } pub struct Context { mode: test_mode } // + rng -pub fn write_file(filename: &Path, content: ~str) { - result::get( - &io::file_writer(filename, ~[io::Create, io::Truncate])) - .write_str(content); +pub fn write_file(filename: &Path, content: &str) { + result::get(&io::file_writer(filename, ~[io::Create, io::Truncate])) + .write_str(content); } -pub fn contains(haystack: ~str, needle: ~str) -> bool { +pub fn contains(haystack: &str, needle: &str) -> bool { str::contains(haystack, needle) } pub fn find_rust_files(files: &mut ~[Path], path: &Path) { if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") { // ignoring "utf8" tests because something is broken - files.push(*path); + files.push(path.clone()); } else if os::path_is_dir(path) && !contains(path.to_str(), ~"compile-fail") && !contains(path.to_str(), ~"build") { @@ -64,9 +60,9 @@ pub fn find_rust_files(files: &mut ~[Path], path: &Path) { } -pub fn common_exprs() -> ~[ast::expr] { - fn dse(e: ast::expr_) -> ast::expr { - ast::expr { +pub fn common_exprs() -> ~[@ast::expr] { + fn dse(e: ast::expr_) -> @ast::expr { + @ast::expr { id: 0, callee_id: -1, node: e, @@ -85,17 +81,17 @@ pub fn common_exprs() -> ~[ast::expr] { dse(ast::expr_lit(@dsl(ast::lit_bool(false)))), dse(ast::expr_lit(@dsl(ast::lit_bool(true)))), dse(ast::expr_unary(ast::box(ast::m_imm), - @dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))), + dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))), dse(ast::expr_unary(ast::uniq(ast::m_imm), - @dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))) + dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))) ] } pub fn safe_to_steal_expr(e: @ast::expr, tm: test_mode) -> bool { - safe_to_use_expr(*e, tm) + safe_to_use_expr(e, tm) } -pub fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool { +pub fn safe_to_use_expr(e: @ast::expr, tm: test_mode) -> bool { match tm { tm_converge => { match e.node { @@ -134,28 +130,31 @@ pub fn safe_to_steal_ty(t: @ast::Ty, tm: test_mode) -> bool { // Not type-parameterized: https://github.com/mozilla/rust/issues/898 (FIXED) pub fn stash_expr_if(c: @fn(@ast::expr, test_mode)->bool, - es: @mut ~[ast::expr], + es: @mut ~[@ast::expr], e: @ast::expr, tm: test_mode) { if c(e, tm) { - *es += ~[*e]; + *es += ~[e]; } else { /* now my indices are wrong :( */ } } -pub fn stash_ty_if(c: @fn(@ast::Ty, test_mode)->bool, - es: @mut ~[ast::Ty], +pub fn stash_ty_if(c: @fn(@ast::Ty, test_mode) -> bool, + es: @mut ~[@ast::Ty], e: @ast::Ty, tm: test_mode) { if c(e, tm) { - es.push(*e); + es.push(e); } else { /* now my indices are wrong :( */ } } -pub struct StolenStuff {exprs: ~[ast::expr], tys: ~[ast::Ty]} +pub struct StolenStuff { + exprs: ~[@ast::expr], + tys: ~[@ast::Ty] +} pub fn steal(crate: @ast::crate, tm: test_mode) -> StolenStuff { let exprs = @mut ~[]; @@ -166,20 +165,23 @@ pub fn steal(crate: @ast::crate, tm: test_mode) -> StolenStuff { .. *visit::default_simple_visitor() }); visit::visit_crate(crate, (), v); - StolenStuff {exprs: *exprs, tys: *tys} + StolenStuff { + exprs: (*exprs).clone(), + tys: (*tys).clone(), + } } pub fn safe_to_replace_expr(e: &ast::expr_, _tm: test_mode) -> bool { match *e { - // https://github.com/mozilla/rust/issues/652 - ast::expr_if(*) => { false } - ast::expr_block(_) => { false } + // https://github.com/mozilla/rust/issues/652 + ast::expr_if(*) => false, + ast::expr_block(_) => false, - // expr_call is also missing a constraint - ast::expr_fn_block(*) => { false } + // expr_call is also missing a constraint + ast::expr_fn_block(*) => false, - _ => { true } + _ => true, } } @@ -194,59 +196,66 @@ pub fn safe_to_replace_ty(t: &ast::ty_, _tm: test_mode) -> bool { } // Replace the |i|th expr (in fold order) of |crate| with |newexpr|. -pub fn replace_expr_in_crate(crate: @ast::crate, i: uint, - newexpr: ast::expr, tm: test_mode) -> - ast::crate { +pub fn replace_expr_in_crate(crate: @ast::crate, + i: uint, + newexpr: @ast::expr, + tm: test_mode) + -> @ast::crate { let j: @mut uint = @mut 0u; fn fold_expr_rep(j_: @mut uint, i_: uint, - newexpr_: ast::expr_, + newexpr_: &ast::expr_, original: &ast::expr_, fld: @fold::ast_fold, tm_: test_mode) - -> ast::expr_ { - *j_ += 1u; - if i_ + 1u == *j_ && safe_to_replace_expr(original, tm_) { - newexpr_ + -> ast::expr_ { + *j_ += 1; + if i_ + 1 == *j_ && safe_to_replace_expr(original, tm_) { + copy *newexpr_ } else { fold::noop_fold_expr(original, fld) } } let afp = @fold::AstFoldFns { fold_expr: fold::wrap(|a,b| { - fold_expr_rep(j, i, newexpr.node, a, b, tm) + fold_expr_rep(j, i, &newexpr.node, a, b, tm) }), .. *fold::default_ast_fold() }; let af = fold::make_fold(afp); let crate2: @ast::crate = @af.fold_crate(crate); - *crate2 + crate2 } // Replace the |i|th ty (in fold order) of |crate| with |newty|. -pub fn replace_ty_in_crate(crate: @ast::crate, i: uint, newty: ast::Ty, - tm: test_mode) -> ast::crate { +pub fn replace_ty_in_crate(crate: @ast::crate, + i: uint, + newty: @ast::Ty, + tm: test_mode) + -> @ast::crate { let j: @mut uint = @mut 0u; fn fold_ty_rep(j_: @mut uint, i_: uint, - newty_: ast::ty_, + newty_: &ast::ty_, original: &ast::ty_, fld: @fold::ast_fold, tm_: test_mode) - -> ast::ty_ { - *j_ += 1u; - if i_ + 1u == *j_ && safe_to_replace_ty(original, tm_) { - newty_ - } else { fold::noop_fold_ty(original, fld) } + -> ast::ty_ { + *j_ += 1; + if i_ + 1 == *j_ && safe_to_replace_ty(original, tm_) { + copy *newty_ + } else { + fold::noop_fold_ty(original, fld) + } } let afp = @fold::AstFoldFns { - fold_ty: fold::wrap(|a,b| fold_ty_rep(j, i, newty.node, a, b, tm) ), + fold_ty: fold::wrap(|a,b| fold_ty_rep(j, i, &newty.node, a, b, tm)), .. *fold::default_ast_fold() }; let af = fold::make_fold(afp); let crate2: @ast::crate = @af.fold_crate(crate); - *crate2 + crate2 } pub fn under(n: uint, it: &fn(uint)) { @@ -258,29 +267,44 @@ pub fn as_str(f: @fn(+x: @io::Writer)) -> ~str { io::with_str_writer(f) } -pub fn check_variants_of_ast(crate: @ast::crate, codemap: @codemap::CodeMap, - filename: &Path, cx: Context) { +pub fn check_variants_of_ast(crate: @ast::crate, + codemap: @codemap::CodeMap, + filename: &Path, + cx: Context) { let stolen = steal(crate, cx.mode); - let extra_exprs = do common_exprs().filtered |a| { - safe_to_use_expr(*a, cx.mode) + let extra_exprs = do common_exprs().filtered |&a| { + safe_to_use_expr(a, cx.mode) }; - check_variants_T(crate, codemap, filename, ~"expr", - extra_exprs + stolen.exprs, pprust::expr_to_str, - replace_expr_in_crate, cx); - check_variants_T(crate, codemap, filename, ~"ty", stolen.tys, - pprust::ty_to_str, replace_ty_in_crate, cx); -} - -pub fn check_variants_T( - crate: @ast::crate, - codemap: @codemap::CodeMap, - filename: &Path, - thing_label: ~str, - things: ~[T], - stringifier: @fn(@T, @syntax::parse::token::ident_interner) -> ~str, - replacer: @fn(@ast::crate, uint, T, test_mode) -> ast::crate, - cx: Context - ) { + check_variants_T(crate, + codemap, + filename, + ~"expr", + extra_exprs + stolen.exprs, + pprust::expr_to_str, + replace_expr_in_crate, + cx); + check_variants_T(crate, + codemap, + filename, + ~"ty", + stolen.tys, + pprust::ty_to_str, + replace_ty_in_crate, + cx); +} + +pub fn check_variants_T(crate: @ast::crate, + codemap: @codemap::CodeMap, + filename: &Path, + thing_label: ~str, + things: &[T], + stringifier: @fn(T, @ident_interner) -> ~str, + replacer: @fn(@ast::crate, + uint, + T, + test_mode) + -> @ast::crate, + cx: Context) { error!("%s contains %u %s objects", filename.to_str(), things.len(), thing_label); @@ -294,36 +318,43 @@ pub fn check_variants_T( error!("Replacing... #%?", uint::to_str(i)); let fname = str::from_slice(filename.to_str()); do under(uint::min(L, 30)) |j| { - error!("With... %?", stringifier(@things[j], intr)); - let crate2 = @replacer(crate, i, things[j], cx.mode); + let fname = fname.to_str(); + error!("With... %?", stringifier(things[j], intr)); + let crate2 = replacer(crate, i, things[j], cx.mode); // It would be best to test the *crate* for stability, but // testing the string for stability is easier and ok for now. let handler = diagnostic::mk_handler(None); let str3 = do io::with_str_reader("") |rdr| { - @as_str(|a|pprust::print_crate( - codemap, - intr, - diagnostic::mk_span_handler(handler, codemap), - crate2, - fname, - rdr, - a, - pprust::no_ann(), - false)) + let fname = fname.to_str(); + let string = do as_str |a| { + let span_handler = + diagnostic::mk_span_handler(handler, codemap); + pprust::print_crate(codemap, + intr, + span_handler, + crate2, + fname.to_str(), + rdr, + a, + pprust::no_ann(), + false) + }; + @string }; match cx.mode { - tm_converge => { - check_roundtrip_convergence(str3, 1u); - } - tm_run => { - let file_label = fmt!("rusttmp/%s_%s_%u_%u", - last_part(filename.to_str()), - thing_label, i, j); - let safe_to_run = !(content_is_dangerous_to_run(*str3) - || has_raw_pointers(crate2)); - check_whole_compiler(*str3, &Path(file_label), - safe_to_run); - } + tm_converge => check_roundtrip_convergence(str3, 1), + tm_run => { + let file_label = fmt!("rusttmp/%s_%s_%u_%u", + last_part(filename.to_str()), + thing_label, + i, + j); + let safe_to_run = !(content_is_dangerous_to_run(*str3) + || has_raw_pointers(crate2)); + check_whole_compiler(*str3, + &Path(file_label), + safe_to_run); + } } } } @@ -347,7 +378,8 @@ pub enum happiness { // - that would be tricky, requiring use of tasks or serialization // or randomness. // This seems to find plenty of bugs as it is :) -pub fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path, +pub fn check_whole_compiler(code: &str, + suggested_filename_prefix: &Path, allow_running: bool) { let filename = &suggested_filename_prefix.with_filetype("rs"); write_file(filename, code); @@ -460,20 +492,24 @@ pub fn parse_and_print(code: @~str) -> ~str { let filename = Path("tmp.rs"); let sess = parse::new_parse_sess(option::None); write_file(&filename, *code); - let crate = parse::parse_crate_from_source_str( - filename.to_str(), code, ~[], sess); + let crate = parse::parse_crate_from_source_str(filename.to_str(), + code, + ~[], + sess); do io::with_str_reader(*code) |rdr| { - as_str(|a| - pprust::print_crate( - sess.cm, - // Assuming there are no token_trees - syntax::parse::token::mk_fake_ident_interner(), - copy sess.span_diagnostic, - crate, - filename.to_str(), - rdr, a, - pprust::no_ann(), - false) ) + let filename = filename.to_str(); + do as_str |a| { + pprust::print_crate(sess.cm, + // Assuming there are no token_trees + token::mk_fake_ident_interner(), + copy sess.span_diagnostic, + crate, + filename.to_str(), + rdr, + a, + pprust::no_ann(), + false) + } } } @@ -493,7 +529,7 @@ pub fn has_raw_pointers(c: @ast::crate) -> bool { return *has_rp; } -pub fn content_is_dangerous_to_run(code: ~str) -> bool { +pub fn content_is_dangerous_to_run(code: &str) -> bool { let dangerous_patterns = ~[~"xfail-test", ~"import", // espeically fs, run @@ -505,7 +541,7 @@ pub fn content_is_dangerous_to_run(code: ~str) -> bool { return false; } -pub fn content_is_dangerous_to_compile(code: ~str) -> bool { +pub fn content_is_dangerous_to_compile(code: &str) -> bool { let dangerous_patterns = ~[~"xfail-test"]; @@ -513,7 +549,7 @@ pub fn content_is_dangerous_to_compile(code: ~str) -> bool { return false; } -pub fn content_might_not_converge(code: ~str) -> bool { +pub fn content_might_not_converge(code: &str) -> bool { let confusing_patterns = ~[~"xfail-test", ~"xfail-pretty", @@ -549,7 +585,6 @@ pub fn file_might_not_converge(filename: &Path) -> bool { } pub fn check_roundtrip_convergence(code: @~str, maxIters: uint) { - let mut i = 0u; let mut newv = code; let mut oldv = code; @@ -613,23 +648,27 @@ pub fn check_variants(files: &[Path], cx: Context) { let file_str = file.to_str(); error!("check_variants: %?", file_str); - let sess = parse::new_parse_sess(option::None); - let crate = - parse::parse_crate_from_source_str( - file_str, - s, ~[], sess); + let sess = parse::new_parse_sess(None); + let crate = parse::parse_crate_from_source_str(file_str.to_str(), + s, + ~[], + sess); io::with_str_reader(*s, |rdr| { + let file_str = file_str.to_str(); error!("%s", - as_str(|a| pprust::print_crate( - sess.cm, - // Assuming no token_trees - syntax::parse::token::mk_fake_ident_interner(), - copy sess.span_diagnostic, - crate, - file_str, - rdr, a, - pprust::no_ann(), - false))) + as_str(|a| { + pprust::print_crate( + sess.cm, + // Assuming no token_trees + token::mk_fake_ident_interner(), + copy sess.span_diagnostic, + crate, + file_str.to_str(), + rdr, + a, + pprust::no_ann(), + false) + })) }); check_variants_of_ast(crate, sess.cm, file, cx); } diff --git a/src/librustc/front/intrinsic.rs b/src/librustc/front/intrinsic.rs index dcf300bd31da6..452623c2742b9 100644 --- a/src/librustc/front/intrinsic.rs +++ b/src/librustc/front/intrinsic.rs @@ -132,7 +132,7 @@ pub mod intrinsic { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { pub fn get_tydesc() -> *(); - pub fn visit_tydesc(++td: *TyDesc, &&tv: @TyVisitor); + pub fn visit_tydesc(++td: *TyDesc, ++tv: @TyVisitor); } } } diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index e2672338a8a0b..8e689f3147b6b 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -128,7 +128,6 @@ pub enum astencode_tag { // Reserves 0x50 -- 0x6f tag_table_freevars = 0x59, tag_table_tcache = 0x5a, tag_table_param_defs = 0x5b, - tag_table_inferred_modes = 0x5c, tag_table_mutbl = 0x5d, tag_table_last_use = 0x5e, tag_table_spill = 0x5f, diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 1a94b57279cc4..cfe31360d321b 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -244,8 +244,8 @@ fn doc_transformed_self_ty(doc: ebml::Doc, } } -pub fn item_type(_item_id: ast::def_id, item: ebml::Doc, - tcx: ty::ctxt, cdata: cmd) -> ty::t { +pub fn item_type(_: ast::def_id, item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) + -> ty::t { doc_type(item, tcx, cdata) } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index bb8c93a9d5db1..011ee115e8c15 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -469,16 +469,9 @@ fn parse_onceness(c: char) -> ast::Onceness { } fn parse_arg(st: @mut PState, conv: conv_did) -> ty::arg { - ty::arg { mode: parse_mode(st), ty: parse_ty(st, conv) } -} - -fn parse_mode(st: @mut PState) -> ast::mode { - let m = ast::expl(match next(st) { - '+' => ast::by_copy, - '=' => ast::by_ref, - _ => fail!(~"bad mode") - }); - return m; + ty::arg { + ty: parse_ty(st, conv) + } } fn parse_closure_ty(st: @mut PState, conv: conv_did) -> ty::ClosureTy { @@ -511,8 +504,7 @@ fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig { assert!((next(st) == '[')); let mut inputs: ~[ty::arg] = ~[]; while peek(st) != ']' { - let mode = parse_mode(st); - inputs.push(ty::arg { mode: mode, ty: parse_ty(st, conv) }); + inputs.push(ty::arg { ty: parse_ty(st, conv) }); } st.pos += 1u; // eat the ']' let ret_ty = parse_ty(st, conv); diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 7c9de2d0b412e..763b1984b81c8 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -344,17 +344,9 @@ fn enc_sigil(w: @io::Writer, sigil: Sigil) { } pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) { - enc_mode(w, cx, arg.mode); enc_ty(w, cx, arg.ty); } -pub fn enc_mode(w: @io::Writer, cx: @ctxt, m: mode) { - match ty::resolved_mode(cx.tcx, m) { - by_copy => w.write_char('+'), - by_ref => w.write_char('='), - } -} - fn enc_purity(w: @io::Writer, p: purity) { match p { pure_fn => w.write_char('p'), diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index f1fd1cd72421b..c7c9c110586c7 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -410,7 +410,7 @@ impl tr for ast::def { ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) } ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) } ast::def_const(did) => { ast::def_const(did.tr(xcx)) } - ast::def_arg(nid, m, b) => { ast::def_arg(xcx.tr_id(nid), m, b) } + ast::def_arg(nid, b) => { ast::def_arg(xcx.tr_id(nid), b) } ast::def_local(nid, b) => { ast::def_local(xcx.tr_id(nid), b) } ast::def_variant(e_did, v_did) => { ast::def_variant(e_did.tr(xcx), v_did.tr(xcx)) @@ -571,6 +571,9 @@ fn encode_method_map_entry(ecx: @e::EncodeContext, do ebml_w.emit_field(~"origin", 1u) { mme.origin.encode(ebml_w); } + do ebml_w.emit_field(~"self_mode", 3) { + mme.self_mode.encode(ebml_w); + } } } @@ -590,6 +593,9 @@ fn encode_method_map_entry(ecx: @e::EncodeContext, do ebml_w.emit_struct_field("origin", 1u) { mme.origin.encode(ebml_w); } + do ebml_w.emit_struct_field("self_mode", 3) { + mme.self_mode.encode(ebml_w); + } } } @@ -611,6 +617,10 @@ impl read_method_map_entry_helper for reader::Decoder { Decodable::decode(self); method_origin.tr(xcx) }), + self_mode: self.read_field(~"self_mode", 3, || { + let self_mode: ty::SelfMode = Decodable::decode(self); + self_mode + }), } } } @@ -625,7 +635,7 @@ impl read_method_map_entry_helper for reader::Decoder { self_arg: self.read_struct_field("self_arg", 0u, || { self.read_arg(xcx) }), - explicit_self: self.read_struct_field("explicit_self", 2u, || { + explicit_self: self.read_struct_field("explicit_self", 2, || { let self_type: ast::self_ty_ = Decodable::decode(self); self_type }), @@ -634,6 +644,10 @@ impl read_method_map_entry_helper for reader::Decoder { Decodable::decode(self); method_origin.tr(xcx) }), + self_mode: self.read_struct_field("self_mode", 3, || { + let self_mode: ty::SelfMode = Decodable::decode(self); + self_mode + }), } } } @@ -978,20 +992,6 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext, } } - // I believe it is not necessary to encode this information. The - // ids will appear in the AST but in the *type* information, which - // is what we actually use in trans, all modes will have been - // resolved. - // - //for tcx.inferred_modes.find(&id).each |m| { - // ebml_w.tag(c::tag_table_inferred_modes) {|| - // ebml_w.id(id); - // ebml_w.tag(c::tag_table_val) {|| - // tyencode::enc_mode(ebml_w.writer, ty_str_ctxt(), m); - // } - // } - //} - if maps.mutbl_map.contains(&id) { do ebml_w.tag(c::tag_table_mutbl) { ebml_w.id(id); diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 92ac90e99da80..e40d0e63eb38e 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -147,38 +147,6 @@ fn req_loans_in_expr(ex: @ast::expr, visit::visit_expr(ex, self, vt); } - ast::expr_call(f, ref args, _) => { - let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f)); - let scope_r = ty::re_scope(ex.id); - for vec::each2(*args, arg_tys) |arg, arg_ty| { - match ty::resolved_mode(self.tcx(), arg_ty.mode) { - ast::by_ref => { - let arg_cmt = self.bccx.cat_expr(*arg); - self.guarantee_valid(arg_cmt, m_imm, scope_r); - } - ast::by_copy => {} - } - } - visit::visit_expr(ex, self, vt); - } - - ast::expr_method_call(_, _, _, ref args, _) => { - let arg_tys = ty::ty_fn_args(ty::node_id_to_type(self.tcx(), - ex.callee_id)); - let scope_r = ty::re_scope(ex.id); - for vec::each2(*args, arg_tys) |arg, arg_ty| { - match ty::resolved_mode(self.tcx(), arg_ty.mode) { - ast::by_ref => { - let arg_cmt = self.bccx.cat_expr(*arg); - self.guarantee_valid(arg_cmt, m_imm, scope_r); - } - ast::by_copy => {} - } - } - - visit::visit_expr(ex, self, vt); - } - ast::expr_match(ex_v, ref arms) => { let cmt = self.bccx.cat_expr(ex_v); for (*arms).each |arm| { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 6f7ccde586b0f..2de12b9eb9746 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -28,8 +28,8 @@ use syntax::ast_util::local_def; use syntax::visit::{default_simple_visitor, mk_simple_visitor, SimpleVisitor}; use syntax::visit::visit_crate; +use core::cast::transmute; use core::hashmap::HashMap; -use core::ptr; pub enum LangItem { ConstTraitLangItem, // 0 @@ -366,20 +366,22 @@ pub impl<'self> LanguageItemCollector<'self> { } fn collect_local_language_items(&self) { - let this = ptr::addr_of(&self); - visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor { - visit_item: |item| { - for item.attrs.each |attribute| { - unsafe { - (*this).match_and_collect_meta_item( - local_def(item.id), - attribute.node.value - ); + unsafe { + let this: *LanguageItemCollector<'self> = transmute(self); + visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor { + visit_item: |item| { + for item.attrs.each |attribute| { + unsafe { + (*this).match_and_collect_meta_item( + local_def(item.id), + attribute.node.value + ); + } } - } - }, - .. *default_simple_visitor() - })); + }, + .. *default_simple_visitor() + })); + } } fn collect_external_language_items(&self) { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index cd26708ef9a4a..faf4b1c31061b 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -19,7 +19,6 @@ use std::smallintmap::SmallIntMap; use syntax::attr; use syntax::codemap::span; use syntax::codemap; -use syntax::print::pprust::mode_to_str; use syntax::{ast, visit}; /** @@ -53,7 +52,6 @@ pub enum lint { unrecognized_lint, non_implicitly_copyable_typarams, vecs_implicitly_copyable, - deprecated_mode, deprecated_pattern, non_camel_case_types, type_limits, @@ -61,14 +59,11 @@ pub enum lint { deprecated_mutable_fields, deprecated_drop, unused_unsafe, - foreign_mode, managed_heap_memory, owned_heap_memory, heap_memory, - legacy_modes, - unused_variable, dead_assignment, unused_mut, @@ -159,20 +154,6 @@ pub fn get_lint_dict() -> LintDict { default: warn }), - (~"deprecated_mode", - LintSpec { - lint: deprecated_mode, - desc: "warn about deprecated uses of modes", - default: warn - }), - - (~"foreign_mode", - LintSpec { - lint: foreign_mode, - desc: "warn about deprecated uses of modes in foreign fns", - default: warn - }), - (~"deprecated_pattern", LintSpec { lint: deprecated_pattern, @@ -208,13 +189,6 @@ pub fn get_lint_dict() -> LintDict { default: allow }), - (~"legacy modes", - LintSpec { - lint: legacy_modes, - desc: "allow legacy modes", - default: forbid - }), - (~"type_limits", LintSpec { lint: type_limits, @@ -486,7 +460,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_path_statement(cx, i); check_item_non_camel_case_types(cx, i); check_item_heap(cx, i); - check_item_deprecated_modes(cx, i); check_item_type_limits(cx, i); check_item_default_methods(cx, i); check_item_deprecated_mutable_fields(cx, i); @@ -719,20 +692,6 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, decl: &ast::fn_decl) { - // warn about `&&` mode on foreign functions, both because it is - // deprecated and because its semantics have changed recently: - for decl.inputs.eachi |i, arg| { - match ty::resolved_mode(cx, arg.mode) { - ast::by_copy => {} - ast::by_ref => { - cx.sess.span_lint( - foreign_mode, fn_id, fn_id, arg.ty.span, - fmt!("foreign function uses `&&` mode \ - on argument %u", i)); - } - } - } - let tys = vec::map(decl.inputs, |a| a.ty ); for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { @@ -995,119 +954,13 @@ fn check_item_unused_mut(tcx: ty::ctxt, it: @ast::item) { visit::visit_item(it, (), visit); } -fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: &ast::fn_decl, - _body: &ast::blk, span: span, id: ast::node_id) { +fn check_fn(_: ty::ctxt, + fk: &visit::fn_kind, + _: &ast::fn_decl, + _: &ast::blk, + _: span, + id: ast::node_id) { debug!("lint check_fn fk=%? id=%?", fk, id); - - // Check for deprecated modes - match *fk { - // don't complain about blocks, since they tend to get their modes - // specified from the outside - visit::fk_fn_block(*) => {} - - _ => { - let fn_ty = ty::node_id_to_type(tcx, id); - check_fn_deprecated_modes(tcx, fn_ty, decl, span, id); - } - } - -} - -fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: &ast::fn_decl, - span: span, id: ast::node_id) { - match ty::get(fn_ty).sty { - ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) | - ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) => { - let mut counter = 0; - for vec::each2(sig.inputs, decl.inputs) |arg_ty, arg_ast| { - counter += 1; - debug!("arg %d, ty=%s, mode=%s", - counter, - ty_to_str(tcx, arg_ty.ty), - mode_to_str(arg_ast.mode)); - match arg_ast.mode { - ast::expl(ast::by_copy) => { - if !tcx.legacy_modes { - tcx.sess.span_lint( - deprecated_mode, id, id, span, - fmt!("argument %d uses by-copy mode", - counter)); - } - } - - ast::expl(_) => { - tcx.sess.span_lint( - deprecated_mode, id, id, - span, - fmt!("argument %d uses an explicit mode", counter)); - } - - ast::infer(_) => { - if tcx.legacy_modes { - let kind = ty::type_contents(tcx, arg_ty.ty); - if !kind.is_safe_for_default_mode(tcx) { - tcx.sess.span_lint( - deprecated_mode, id, id, - span, - fmt!("argument %d uses the default mode \ - but shouldn't", - counter)); - } - } - } - } - - match ty::get(arg_ty.ty).sty { - ty::ty_closure(*) | ty::ty_bare_fn(*) => { - let span = arg_ast.ty.span; - // Recurse to check fn-type argument - match arg_ast.ty.node { - ast::ty_closure(@ast::TyClosure{decl: ref d, _}) | - ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{ - check_fn_deprecated_modes(tcx, arg_ty.ty, - d, span, id); - } - ast::ty_path(*) => { - // This is probably a typedef, so we can't - // see the actual fn decl - // e.g. fn foo(f: InitOp) - } - _ => { - tcx.sess.span_warn(span, ~"what"); - error!("arg %d, ty=%s, mode=%s", - counter, - ty_to_str(tcx, arg_ty.ty), - mode_to_str(arg_ast.mode)); - error!("%?",arg_ast.ty.node); - fail!() - } - }; - } - _ => () - } - } - } - - _ => tcx.sess.impossible_case(span, ~"check_fn: function has \ - non-fn type") - } -} - -fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) { - match it.node { - ast::item_ty(ty, _) => { - match ty.node { - ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) | - ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => { - let fn_ty = ty::node_id_to_type(tcx, it.id); - check_fn_deprecated_modes( - tcx, fn_ty, decl, ty.span, it.id) - } - _ => () - } - } - _ => () - } } pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index fd836b20b8100..94d82d0acb8e4 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -110,6 +110,7 @@ use middle::typeck; use middle::moves; use util::ppaux::ty_to_str; +use core::cast::transmute; use core::hashmap::HashMap; use core::util::with; use syntax::ast::*; @@ -235,19 +236,19 @@ struct LocalInfo { } enum VarKind { - Arg(node_id, ident, rmode), + Arg(node_id, ident), Local(LocalInfo), ImplicitRet } fn relevant_def(def: def) -> Option { match def { - def_binding(nid, _) | - def_arg(nid, _, _) | - def_local(nid, _) | - def_self(nid, _) => Some(nid), + def_binding(nid, _) | + def_arg(nid, _) | + def_local(nid, _) | + def_self(nid, _) => Some(nid), - _ => None + _ => None } } @@ -320,10 +321,9 @@ pub impl IrMaps { self.num_vars += 1; match vk { - Local(LocalInfo {id:node_id, _}) | - Arg(node_id, _, _) => { + Local(LocalInfo { id: node_id, _ }) | Arg(node_id, _) => { self.variable_map.insert(node_id, v); - } + }, ImplicitRet => {} } @@ -344,8 +344,9 @@ pub impl IrMaps { fn variable_name(&mut self, var: Variable) -> @~str { match self.var_kinds[*var] { - Local(LocalInfo {ident: nm, _}) | - Arg(_, nm, _) => self.tcx.sess.str_of(nm), + Local(LocalInfo { ident: nm, _ }) | Arg(_, nm) => { + self.tcx.sess.str_of(nm) + }, ImplicitRet => @~"" } } @@ -371,25 +372,22 @@ pub impl IrMaps { let vk = self.var_kinds[*var]; debug!("Node %d is a last use of variable %?", expr_id, vk); match vk { - Arg(id, _, by_copy) | - Local(LocalInfo {id: id, kind: FromLetNoInitializer, _}) | - Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) | - Local(LocalInfo {id: id, kind: FromMatch(_), _}) => { - let v = match self.last_use_map.find(&expr_id) { - Some(&v) => v, - None => { - let v = @mut ~[]; - self.last_use_map.insert(expr_id, v); - v - } - }; + Arg(id, _) | + Local(LocalInfo { id: id, kind: FromLetNoInitializer, _ }) | + Local(LocalInfo { id: id, kind: FromLetWithInitializer, _ }) | + Local(LocalInfo { id: id, kind: FromMatch(_), _ }) => { + let v = match self.last_use_map.find(&expr_id) { + Some(&v) => v, + None => { + let v = @mut ~[]; + self.last_use_map.insert(expr_id, v); + v + } + }; - v.push(id); - } - Arg(_, _, by_ref) | - ImplicitRet => { - debug!("--but it is not owned"); - } + v.push(id); + } + ImplicitRet => debug!("--but it is not owned"), } } } @@ -418,15 +416,16 @@ fn visit_fn(fk: &visit::fn_kind, self.last_use_map, self.cur_item); - debug!("creating fn_maps: %x", ptr::addr_of(&(*fn_maps)) as uint); + unsafe { + debug!("creating fn_maps: %x", transmute(&*fn_maps)); + } for decl.inputs.each |arg| { - let mode = ty::resolved_mode(self.tcx, arg.mode); do pat_util::pat_bindings(self.tcx.def_map, arg.pat) |_bm, arg_id, _x, path| { debug!("adding argument %d", arg_id); let ident = ast_util::path_to_ident(path); - fn_maps.add_variable(Arg(arg_id, ident, mode)); + fn_maps.add_variable(Arg(arg_id, ident)); } }; @@ -436,16 +435,13 @@ fn visit_fn(fk: &visit::fn_kind, match method.self_ty.node { sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => { fn_maps.add_variable(Arg(method.self_id, - special_idents::self_, - by_copy)); + special_idents::self_)); } sty_static => {} } } fk_dtor(_, _, self_id, _) => { - fn_maps.add_variable(Arg(self_id, - special_idents::self_, - by_copy)); + fn_maps.add_variable(Arg(self_id, special_idents::self_)); } fk_item_fn(*) | fk_anon(*) | fk_fn_block(*) => {} } @@ -970,30 +966,8 @@ pub impl Liveness { entry_ln } - fn propagate_through_fn_block(&self, decl: &fn_decl, blk: &blk) - -> LiveNode { - // inputs passed by & mode should be considered live on exit: - for decl.inputs.each |arg| { - match ty::resolved_mode(self.tcx, arg.mode) { - by_ref => { - // By val and by ref do not own, so register a - // read at the end. This will prevent us from - // moving out of such variables but also prevent - // us from registering last uses and so forth. - do pat_util::pat_bindings(self.tcx.def_map, arg.pat) - |_bm, arg_id, _sp, _path| - { - let var = self.variable(arg_id, blk.span); - self.acc(self.s.exit_ln, var, ACC_READ); - } - } - by_copy => { - // By copy is an owned mode. If we don't use the - // variable, nobody will. - } - } - } - + fn propagate_through_fn_block(&self, _: &fn_decl, blk: &blk) + -> LiveNode { // the fallthrough exit is only for those cases where we do not // explicitly return: self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln); @@ -1768,7 +1742,7 @@ pub impl Liveness { // borrow checker let vk = self.ir.var_kinds[*var]; match vk { - Arg(_, name, _) => { + Arg(_, name) => { self.tcx.sess.span_err( move_expr.span, fmt!("illegal move from argument `%s`, which is not \ diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 49c5717a357ea..31cb39bc231b9 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -482,17 +482,14 @@ pub impl mem_categorization_ctxt { } } - ast::def_arg(vid, mode, mutbl) => { + ast::def_arg(vid, mutbl) => { // Idea: make this could be rewritten to model by-ref // stuff as `&const` and `&mut`? // m: mutability of the argument // lp: loan path, must be none for aliasable things let m = if mutbl {McDeclared} else {McImmutable}; - let lp = match ty::resolved_mode(self.tcx, mode) { - ast::by_copy => Some(@lp_arg(vid)), - ast::by_ref => None, - }; + let lp = Some(@lp_arg(vid)); @cmt_ { id:id, span:span, diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 0eb5c53d6886d..fe1466bf808a3 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -718,41 +718,22 @@ pub impl VisitContext { receiver_expr: @expr, visitor: vt) { - self.use_fn_arg(by_copy, receiver_expr, visitor); + self.use_fn_arg(receiver_expr, visitor); } fn use_fn_args(&self, - callee_id: node_id, + _: node_id, arg_exprs: &[@expr], - visitor: vt) - { - /*! - * - * Uses the argument expressions according to the function modes. - */ - - let arg_tys = - ty::ty_fn_args(ty::node_id_to_type(self.tcx, callee_id)); - for vec::each2(arg_exprs, arg_tys) |arg_expr, arg_ty| { - let arg_mode = ty::resolved_mode(self.tcx, arg_ty.mode); - self.use_fn_arg(arg_mode, *arg_expr, visitor); + visitor: vt) { + //! Uses the argument expressions. + for arg_exprs.each |arg_expr| { + self.use_fn_arg(*arg_expr, visitor); } } - fn use_fn_arg(&self, - arg_mode: rmode, - arg_expr: @expr, - visitor: vt) - { - /*! - * - * Uses the argument according to the given argument mode. - */ - - match arg_mode { - by_ref => self.use_expr(arg_expr, Read, visitor), - by_copy => self.consume_expr(arg_expr, visitor) - } + fn use_fn_arg(&self, arg_expr: @expr, visitor: vt) { + //! Uses the argument. + self.consume_expr(arg_expr, visitor) } fn arms_have_by_move_bindings(&self, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 5354ffc5d3c82..681c38633273c 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -42,7 +42,7 @@ use syntax::ast::Generics; use syntax::ast::{gt, ident, inherited, item, item_struct}; use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod}; use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le}; -use syntax::ast::{local, local_crate, lt, method, mode, mul}; +use syntax::ast::{local, local_crate, lt, method, mul}; use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident}; use syntax::ast::{Path, pat_lit, pat_range, pat_struct}; use syntax::ast::{prim_ty, private, provided}; @@ -123,7 +123,7 @@ pub struct Export2 { pub enum PatternBindingMode { RefutableMode, LocalIrrefutableMode, - ArgumentIrrefutableMode(mode) + ArgumentIrrefutableMode, } #[deriving(Eq)] @@ -3708,8 +3708,7 @@ pub impl Resolver { } Some(declaration) => { for declaration.inputs.each |argument| { - let binding_mode = - ArgumentIrrefutableMode(argument.mode); + let binding_mode = ArgumentIrrefutableMode; let mutability = if argument.is_mutbl {Mutable} else {Immutable}; self.resolve_pattern(argument.pat, @@ -4184,10 +4183,9 @@ pub impl Resolver { // But for locals, we use `def_local`. def_local(pattern.id, is_mutable) } - ArgumentIrrefutableMode(argument_mode) => { + ArgumentIrrefutableMode => { // And for function arguments, `def_arg`. - def_arg(pattern.id, argument_mode, - is_mutable) + def_arg(pattern.id, is_mutable) } }; diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index 3d1c0f3f82c5c..9c84b2a418232 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -33,11 +33,16 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { constraints.push(copy *c); let aoutty = ty::arg { - mode: ast::expl(ast::by_copy), ty: expr_ty(bcx, out) }; aoutputs.push(unpack_result!(bcx, { - callee::trans_arg_expr(bcx, aoutty, out, &mut cleanups, None, callee::DontAutorefArg) + callee::trans_arg_expr(bcx, + aoutty, + ty::ByCopy, + out, + &mut cleanups, + None, + callee::DontAutorefArg) })); let e = match out.node { @@ -46,12 +51,17 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { }; let outty = ty::arg { - mode: ast::expl(ast::by_copy), ty: expr_ty(bcx, e) }; unpack_result!(bcx, { - callee::trans_arg_expr(bcx, outty, e, &mut cleanups, None, callee::DontAutorefArg) + callee::trans_arg_expr(bcx, + outty, + ty::ByCopy, + e, + &mut cleanups, + None, + callee::DontAutorefArg) }) }; @@ -66,12 +76,17 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { constraints.push(copy *c); let inty = ty::arg { - mode: ast::expl(ast::by_copy), ty: expr_ty(bcx, in) }; unpack_result!(bcx, { - callee::trans_arg_expr(bcx, inty, in, &mut cleanups, None, callee::DontAutorefArg) + callee::trans_arg_expr(bcx, + inty, + ty::ByCopy, + in, + &mut cleanups, + None, + callee::DontAutorefArg) }) }; diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 03a8520186295..efa10dfc2aa34 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1728,7 +1728,6 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, raw_llargs: &[ValueRef], arg_tys: &[ty::arg]) -> block { let _icx = fcx.insn_ctxt("copy_args_to_allocas"); - let tcx = bcx.tcx(); let mut bcx = bcx; match fcx.llself { @@ -1757,24 +1756,16 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, // the argument would be passed by value, we store it into an alloca. // This alloca should be optimized away by LLVM's mem-to-reg pass in // the event it's not truly needed. - let llarg; - match ty::resolved_mode(tcx, arg_ty.mode) { - ast::by_ref => { - llarg = raw_llarg; - } - ast::by_copy => { - // only by value if immediate: - if datum::appropriate_mode(arg_ty.ty).is_by_value() { - let alloc = alloc_ty(bcx, arg_ty.ty); - Store(bcx, raw_llarg, alloc); - llarg = alloc; - } else { - llarg = raw_llarg; - } + // only by value if immediate: + let llarg = if datum::appropriate_mode(arg_ty.ty).is_by_value() { + let alloc = alloc_ty(bcx, arg_ty.ty); + Store(bcx, raw_llarg, alloc); + alloc + } else { + raw_llarg + }; - add_clean(bcx, llarg, arg_ty.ty); - } - } + add_clean(bcx, llarg, arg_ty.ty); bcx = _match::bind_irrefutable_pat(bcx, args[arg_n].pat, @@ -1966,7 +1957,6 @@ pub fn trans_enum_variant(ccx: @CrateContext, // Translate variant arguments to function arguments. let fn_args = do args.map |varg| { ast::arg { - mode: ast::expl(ast::by_copy), is_mutbl: false, ty: varg.ty, pat: ast_util::ident_to_pat( @@ -2041,7 +2031,6 @@ pub fn trans_tuple_struct(ccx: @CrateContext, // Translate struct fields to function arguments. let fn_args = do fields.map |field| { ast::arg { - mode: ast::expl(ast::by_copy), is_mutbl: false, ty: field.node.ty, pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(), @@ -2408,8 +2397,8 @@ pub fn create_entry_wrapper(ccx: @CrateContext, } else { let start_fn_type = csearch::get_type(ccx.tcx, start_def_id).ty; - trans_external_path(ccx, start_def_id, start_fn_type) - }; + trans_external_path(ccx, start_def_id, start_fn_type); + } let retptr = llvm::LLVMBuildAlloca(bld, T_i8(), noname()); diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 9ade69b8b6709..f5c496484a037 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -170,7 +170,7 @@ pub fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) { pub fn noname() -> *c_char { unsafe { static cnull: uint = 0u; - return cast::transmute(ptr::addr_of(&cnull)); + return cast::transmute(&cnull); } } @@ -827,8 +827,8 @@ pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef]) pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { unsafe { if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; } - let valptr = cast::transmute(ptr::addr_of(&val)); - let bbptr = cast::transmute(ptr::addr_of(&bb)); + let valptr = cast::transmute(&val); + let bbptr = cast::transmute(&bb); llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint); } } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 1965855586197..ad0fea3b4b4af 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -57,7 +57,7 @@ pub struct MethodData { llfn: ValueRef, llself: ValueRef, self_ty: ty::t, - self_mode: ast::rmode + self_mode: ty::SelfMode, } pub enum CalleeData { @@ -378,10 +378,20 @@ pub fn trans_lang_call(bcx: block, csearch::get_type(bcx.ccx().tcx, did).ty }; let rty = ty::ty_fn_ret(fty); - return callee::trans_call_inner( - bcx, None, fty, rty, - |bcx| trans_fn_ref_with_vtables_to_callee(bcx, did, 0, ~[], None), - ArgVals(args), dest, DontAutorefArg); + callee::trans_call_inner(bcx, + None, + fty, + rty, + |bcx| { + trans_fn_ref_with_vtables_to_callee(bcx, + did, + 0, + ~[], + None) + }, + ArgVals(args), + dest, + DontAutorefArg) } pub fn trans_lang_call_with_type_params(bcx: block, @@ -483,7 +493,8 @@ pub fn trans_call_inner(in_cx: block, } Method(d) => { // Weird but true: we pass self in the *environment* slot! - let llself = PointerCast(bcx, d.llself, + let llself = PointerCast(bcx, + d.llself, T_opaque_box_ptr(ccx)); (d.llfn, llself) } @@ -520,7 +531,7 @@ pub fn trans_call_inner(in_cx: block, // Now that the arguments have finished evaluating, we need to revoke // the cleanup for the self argument, if it exists match callee.data { - Method(d) if d.self_mode == ast::by_copy => { + Method(d) if d.self_mode == ty::ByCopy => { revoke_clean(bcx, d.llself); } _ => {} @@ -629,7 +640,11 @@ pub fn trans_args(cx: block, let last = arg_exprs.len() - 1u; for vec::eachi(arg_exprs) |i, arg_expr| { let arg_val = unpack_result!(bcx, { - trans_arg_expr(bcx, arg_tys[i], *arg_expr, &mut temp_cleanups, + trans_arg_expr(bcx, + arg_tys[i], + ty::ByCopy, + *arg_expr, + &mut temp_cleanups, if i == last { ret_flag } else { None }, autoref_arg) }); @@ -660,6 +675,7 @@ pub enum AutorefArg { // call takes place: pub fn trans_arg_expr(bcx: block, formal_ty: ty::arg, + self_mode: ty::SelfMode, arg_expr: @ast::expr, temp_cleanups: &mut ~[ValueRef], ret_flag: Option, @@ -667,10 +683,10 @@ pub fn trans_arg_expr(bcx: block, let _icx = bcx.insn_ctxt("trans_arg_expr"); let ccx = bcx.ccx(); - debug!("trans_arg_expr(formal_ty=(%?,%s), arg_expr=%s, \ + debug!("trans_arg_expr(formal_ty=(%s), self_mode=%?, arg_expr=%s, \ ret_flag=%?)", - formal_ty.mode, formal_ty.ty.repr(bcx.tcx()), + self_mode, arg_expr.repr(bcx.tcx()), ret_flag.map(|v| bcx.val_str(*v))); let _indenter = indenter(); @@ -686,8 +702,7 @@ pub fn trans_arg_expr(bcx: block, blk @ @ast::expr { node: ast::expr_fn_block(ref decl, ref body), _ - }) => - { + }) => { let scratch_ty = expr_ty(bcx, arg_expr); let scratch = alloc_ty(bcx, scratch_ty); let arg_ty = expr_ty(bcx, arg_expr); @@ -714,8 +729,6 @@ pub fn trans_arg_expr(bcx: block, debug!(" arg datum: %s", arg_datum.to_str(bcx.ccx())); - // finally, deal with the various modes - let arg_mode = ty::resolved_mode(ccx.tcx, formal_ty.mode); let mut val; if ty::type_is_bot(arg_datum.ty) { // For values of type _|_, we generate an @@ -735,24 +748,27 @@ pub fn trans_arg_expr(bcx: block, val = arg_datum.to_ref_llval(bcx); } DontAutorefArg => { - match arg_mode { - ast::by_ref => { + match self_mode { + ty::ByRef => { // This assertion should really be valid, but because // the explicit self code currently passes by-ref, it // does not hold. // //assert !bcx.ccx().maps.moves_map.contains_key( // &arg_expr.id); + debug!("by ref arg with type %s", + bcx.ty_to_str(arg_datum.ty)); val = arg_datum.to_ref_llval(bcx); } - - ast::by_copy => { + ty::ByCopy => { debug!("by copy arg with type %s, storing to scratch", bcx.ty_to_str(arg_datum.ty)); let scratch = scratch_datum(bcx, arg_datum.ty, false); - arg_datum.store_to_datum(bcx, arg_expr.id, - INIT, scratch); + arg_datum.store_to_datum(bcx, + arg_expr.id, + INIT, + scratch); // Technically, ownership of val passes to the callee. // However, we must cleanup should we fail before the @@ -761,12 +777,8 @@ pub fn trans_arg_expr(bcx: block, temp_cleanups.push(scratch.val); match arg_datum.appropriate_mode() { - ByValue => { - val = Load(bcx, scratch.val); - } - ByRef => { - val = scratch.val; - } + ByValue => val = Load(bcx, scratch.val), + ByRef => val = scratch.val, } } } @@ -776,6 +788,10 @@ pub fn trans_arg_expr(bcx: block, if formal_ty.ty != arg_datum.ty { // this could happen due to e.g. subtyping let llformal_ty = type_of::type_of_explicit_arg(ccx, &formal_ty); + let llformal_ty = match self_mode { + ty::ByRef => T_ptr(llformal_ty), + ty::ByCopy => llformal_ty, + }; debug!("casting actual type (%s) to match formal (%s)", bcx.val_str(val), bcx.llty_str(llformal_ty)); val = PointerCast(bcx, val, llformal_ty); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index c18c977bfb345..f8fb0f4b7cf31 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -41,6 +41,7 @@ use middle::ty; use middle::typeck; use util::ppaux::{Repr}; +use core::cast::transmute; use core::hash; use core::hashmap::{HashMap, HashSet}; use core::libc::{c_uint, c_longlong, c_ulonglong}; @@ -750,13 +751,11 @@ pub impl block_ { t.repr(self.tcx()) } fn to_str(@mut self) -> ~str { - match self.node_info { - Some(node_info) => { - fmt!("[block %d]", node_info.id) - } - None => { - fmt!("[block %x]", ptr::addr_of(&(*self)) as uint) - } + unsafe { + match self.node_info { + Some(node_info) => fmt!("[block %d]", node_info.id), + None => fmt!("[block %x]", transmute(&*self)), + } } } } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index f666eb2aaa64b..f83562add3169 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1072,7 +1072,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { } } } - ast::def_arg(nid, _, _) => { + ast::def_arg(nid, _) => { take_local(bcx, bcx.fcx.llargs, nid) } ast::def_local(nid, _) | ast::def_binding(nid, _) => { diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index aa6d9eec259e1..c45ba64c58470 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -716,37 +716,51 @@ pub fn trans_intrinsic(ccx: @CrateContext, } } ~"forget" => {} - ~"reinterpret_cast" => { - let tp_ty = substs.tys[0]; - let lltp_ty = type_of::type_of(ccx, tp_ty); - let llout_ty = type_of::type_of(ccx, substs.tys[1]); - let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty), - out_sz = machine::llbitsize_of_real(ccx, llout_ty); - if tp_sz != out_sz { - let sp = match *ccx.tcx.items.get(&ref_id.get()) { - ast_map::node_expr(e) => e.span, - _ => fail!(~"reinterpret_cast or forget has non-expr arg") - }; - ccx.sess.span_fatal( - sp, fmt!("reinterpret_cast called on types \ - with different size: %s (%u bit(s)) to %s \ - (%u bit(s))", - ty_to_str(ccx.tcx, tp_ty), tp_sz, - ty_to_str(ccx.tcx, substs.tys[1]), out_sz)); - } - if !ty::type_is_nil(substs.tys[1]) { - // NB: Do not use a Load and Store here. This causes - // massive code bloat when reinterpret_cast is used on - // large structural types. - let llretptr = fcx.llretptr.get(); - let llretptr = PointerCast(bcx, llretptr, T_ptr(T_i8())); - let llcast = get_param(decl, first_real_arg); - let llcast = PointerCast(bcx, llcast, T_ptr(T_i8())); - call_memcpy(bcx, llretptr, llcast, llsize_of(ccx, lltp_ty)); - } - } - ~"addr_of" => { - Store(bcx, get_param(decl, first_real_arg), fcx.llretptr.get()); + ~"transmute" => { + let (in_type, out_type) = (substs.tys[0], substs.tys[1]); + let llintype = type_of::type_of(ccx, in_type); + let llouttype = type_of::type_of(ccx, out_type); + + let in_type_size = machine::llbitsize_of_real(ccx, llintype); + let out_type_size = machine::llbitsize_of_real(ccx, llouttype); + if in_type_size != out_type_size { + let sp = match *ccx.tcx.items.get(&ref_id.get()) { + ast_map::node_expr(e) => e.span, + _ => fail!(~"transmute has non-expr arg"), + }; + let pluralize = |n| if 1u == n { "" } else { "s" }; + ccx.sess.span_fatal(sp, + fmt!("transmute called on types with \ + different sizes: %s (%u bit%s) to \ + %s (%u bit%s)", + ty_to_str(ccx.tcx, in_type), + in_type_size, + pluralize(in_type_size), + ty_to_str(ccx.tcx, out_type), + out_type_size, + pluralize(out_type_size))); + } + + if !ty::type_is_nil(out_type) { + // NB: Do not use a Load and Store here. This causes massive + // code bloat when `transmute` is used on large structural + // types. + let lldestptr = fcx.llretptr.get(); + let lldestptr = PointerCast(bcx, lldestptr, T_ptr(T_i8())); + + let llsrcval = get_param(decl, first_real_arg); + let llsrcptr = if ty::type_is_immediate(in_type) { + let llsrcptr = alloca(bcx, llintype); + Store(bcx, llsrcval, llsrcptr); + llsrcptr + } else { + llsrcval + }; + let llsrcptr = PointerCast(bcx, llsrcptr, T_ptr(T_i8())); + + let llsize = llsize_of(ccx, llintype); + call_memcpy(bcx, lldestptr, llsrcptr, llsize); + } } ~"needs_drop" => { let tp_ty = substs.tys[0]; @@ -757,9 +771,14 @@ pub fn trans_intrinsic(ccx: @CrateContext, ~"visit_tydesc" => { let td = get_param(decl, first_real_arg); let visitor = get_param(decl, first_real_arg + 1u); + //let llvisitorptr = alloca(bcx, val_ty(visitor)); + //Store(bcx, visitor, llvisitorptr); let td = PointerCast(bcx, td, T_ptr(ccx.tydesc_type)); - glue::call_tydesc_glue_full(bcx, visitor, td, - abi::tydesc_field_visit_glue, None); + glue::call_tydesc_glue_full(bcx, + visitor, + td, + abi::tydesc_field_visit_glue, + None); } ~"frame_address" => { let frameaddress = *ccx.intrinsics.get(&~"llvm.frameaddress"); @@ -772,10 +791,11 @@ pub fn trans_intrinsic(ccx: @CrateContext, sigil: ast::BorrowedSigil, onceness: ast::Many, region: ty::re_bound(ty::br_anon(0)), - sig: FnSig {bound_lifetime_names: opt_vec::Empty, - inputs: ~[arg {mode: ast::expl(ast::by_copy), - ty: star_u8}], - output: ty::mk_nil()} + sig: FnSig { + bound_lifetime_names: opt_vec::Empty, + inputs: ~[ arg { ty: star_u8 } ], + output: ty::mk_nil() + } }); let datum = Datum {val: get_param(decl, first_real_arg), mode: ByRef, ty: fty, source: ZeroMem}; diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 44e9c0f6802ae..90f9f93be2b48 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -145,14 +145,18 @@ pub fn trans_self_arg(bcx: block, let _icx = bcx.insn_ctxt("impl::trans_self_arg"); let mut temp_cleanups = ~[]; - // Compute the mode and type of self. + // Compute the type of self. let self_arg = arg { - mode: mentry.self_arg.mode, ty: monomorphize_type(bcx, mentry.self_arg.ty) }; - let result = trans_arg_expr(bcx, self_arg, base, - &mut temp_cleanups, None, DontAutorefArg); + let result = trans_arg_expr(bcx, + self_arg, + mentry.self_mode, + base, + &mut temp_cleanups, + None, + DontAutorefArg); // FIXME(#3446)---this is wrong, actually. The temp_cleanups // should be revoked only after all arguments have been passed. @@ -224,14 +228,13 @@ pub fn trans_method_callee(bcx: block, typeck::method_static(did) => { let callee_fn = callee::trans_fn_ref(bcx, did, callee_id); let Result {bcx, val} = trans_self_arg(bcx, self, mentry); - let tcx = bcx.tcx(); Callee { bcx: bcx, data: Method(MethodData { llfn: callee_fn.llfn, llself: val, self_ty: node_id_type(bcx, self.id), - self_mode: ty::resolved_mode(tcx, mentry.self_arg.mode) + self_mode: mentry.self_mode, }) } } @@ -442,7 +445,7 @@ pub fn trans_monomorphized_callee(bcx: block, trait_id: ast::def_id, n_method: uint, vtbl: typeck::vtable_origin) - -> Callee { + -> Callee { let _icx = bcx.insn_ctxt("impl::trans_monomorphized_callee"); return match vtbl { typeck::vtable_static(impl_did, ref rcvr_substs, rcvr_origins) => { @@ -463,8 +466,11 @@ pub fn trans_monomorphized_callee(bcx: block, bcx, mth_id, impl_did, callee_id, rcvr_origins); // translate the function - let callee = trans_fn_ref_with_vtables( - bcx, mth_id, callee_id, callee_substs, Some(callee_origins)); + let callee = trans_fn_ref_with_vtables(bcx, + mth_id, + callee_id, + callee_substs, + Some(callee_origins)); // create a llvalue that represents the fn ptr let fn_ty = node_id_type(bcx, callee_id); @@ -472,14 +478,13 @@ pub fn trans_monomorphized_callee(bcx: block, let llfn_val = PointerCast(bcx, callee.llfn, llfn_ty); // combine the self environment with the rest - let tcx = bcx.tcx(); Callee { bcx: bcx, data: Method(MethodData { llfn: llfn_val, llself: llself_val, self_ty: node_id_type(bcx, base.id), - self_mode: ty::resolved_mode(tcx, mentry.self_arg.mode) + self_mode: mentry.self_mode, }) } } @@ -496,7 +501,7 @@ pub fn combine_impl_and_methods_tps(bcx: block, impl_did: ast::def_id, callee_id: ast::node_id, rcvr_substs: &[ty::t]) - -> ~[ty::t] { + -> ~[ty::t] { /*! * * Creates a concatenated set of substitutions which includes @@ -668,7 +673,7 @@ pub fn trans_trait_callee_from_llval(bcx: block, Store(bcx, llself, llscratch); llself = llscratch; - self_mode = ast::by_ref; + self_mode = ty::ByRef; } ast::sty_box(_) => { // Bump the reference count on the box. @@ -686,7 +691,7 @@ pub fn trans_trait_callee_from_llval(bcx: block, Store(bcx, llself, llscratch); llself = llscratch; - self_mode = ast::by_ref; + self_mode = ty::ByRef; } ast::sty_uniq(_) => { // Pass the unique pointer. @@ -699,7 +704,7 @@ pub fn trans_trait_callee_from_llval(bcx: block, Store(bcx, llself, llscratch); llself = llscratch; - self_mode = ast::by_ref; + self_mode = ty::ByRef; } } diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 741b111b6a0a7..7e59f580a2c3c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -280,9 +280,15 @@ pub impl Reflector { let make_get_disr = || { let sub_path = bcx.fcx.path + ~[path_name(special_idents::anon)]; - let sym = mangle_internal_name_by_path_and_seq(ccx, sub_path, ~"get_disr"); - let args = [ty::arg { mode: ast::expl(ast::by_copy), - ty: opaqueptrty }]; + let sym = mangle_internal_name_by_path_and_seq(ccx, + sub_path, + ~"get_disr"); + let args = [ + ty::arg { + ty: opaqueptrty + } + ]; + let llfty = type_of_fn(ccx, args, ty::mk_int()); let llfdecl = decl_internal_cdecl_fn(ccx.llmod, sym, llfty); let arg = unsafe { @@ -347,13 +353,7 @@ pub impl Reflector { fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) { for sig.inputs.eachi |i, arg| { - let modeval = match arg.mode { - ast::infer(_) => 0u, - ast::expl(e) => match e { - ast::by_ref => 1u, - ast::by_copy => 5u - } - }; + let modeval = 5u; // "by copy" let extra = ~[self.c_uint(i), self.c_uint(modeval), self.c_tydesc(arg.ty)]; diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 5bf01b9a8831d..a842f91f0ed6e 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -19,11 +19,8 @@ use util::ppaux; use syntax::ast; -pub fn arg_is_indirect(ccx: @CrateContext, arg: &ty::arg) -> bool { - match ty::resolved_mode(ccx.tcx, arg.mode) { - ast::by_copy => !ty::type_is_immediate(arg.ty), - ast::by_ref => true - } +pub fn arg_is_indirect(_: @CrateContext, arg: &ty::arg) -> bool { + !ty::type_is_immediate(arg.ty) } pub fn type_of_explicit_arg(ccx: @CrateContext, arg: &ty::arg) -> TypeRef { diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index dc3fb027dea73..33145dd4334a5 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -78,12 +78,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => { for vec::each(sig.inputs) |arg| { - match ty::resolved_mode(ccx.tcx, arg.mode) { - by_copy => { - type_needs(cx, use_repr, arg.ty); - } - by_ref => {} - } + type_needs(cx, use_repr, arg.ty); } } _ => () @@ -122,9 +117,9 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) _) => { if abi.is_intrinsic() { let flags = match *cx.ccx.sess.str_of(i.ident) { - ~"size_of" | ~"pref_align_of" | ~"min_align_of" | - ~"init" | ~"reinterpret_cast" | - ~"move_val" | ~"move_val_init" => use_repr, + ~"size_of" | ~"pref_align_of" | ~"min_align_of" | + ~"init" | ~"transmute" | ~"move_val" | + ~"move_val_init" => use_repr, ~"get_tydesc" | ~"needs_drop" => use_tydesc, @@ -135,8 +130,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ~"atomic_xsub_acq" | ~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => 0, - ~"visit_tydesc" | ~"forget" | ~"addr_of" | - ~"frame_address" | ~"morestack_addr" => 0, + ~"visit_tydesc" | ~"forget" | ~"frame_address" | + ~"morestack_addr" => 0, ~"memmove32" | ~"memmove64" => 0, @@ -332,15 +327,9 @@ pub fn mark_for_expr(cx: Context, e: @expr) { node_type_needs(cx, use_tydesc, val.id); } expr_call(f, _, _) => { - for vec::each( - ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)) - ) |a| { - match a.mode { - expl(by_copy) => { - type_needs(cx, use_repr, a.ty); - } - _ => () - } + for vec::each(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, + f.id))) |a| { + type_needs(cx, use_repr, a.ty); } } expr_method_call(rcvr, _, _, _, _) => { @@ -349,12 +338,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) { for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, e.callee_id)).each |a| { - match a.mode { - expl(by_copy) => { - type_needs(cx, use_repr, a.ty); - } - _ => () - } + type_needs(cx, use_repr, a.ty); } mark_for_method_call(cx, e.id, e.callee_id); } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index edd3a295bf922..c7fb1e94adf4c 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -38,7 +38,6 @@ use syntax::ast_util; use syntax::attr; use syntax::codemap::span; use syntax::codemap; -use syntax::print::pprust; use syntax::parse::token::special_idents; use syntax::{ast, ast_map}; use syntax::opt_vec::OptVec; @@ -48,11 +47,8 @@ use syntax; // Data types -// Note: after typeck, you should use resolved_mode() to convert this mode -// into an rmode, which will take into account the results of mode inference. -#[deriving(Eq)] +#[deriving(Eq, IterBytes)] pub struct arg { - mode: ast::mode, ty: t } @@ -99,6 +95,16 @@ pub enum TraitStore { RegionTraitStore(Region), // &Trait } +// XXX: This should probably go away at some point. Maybe after destructors +// do? +#[auto_encode] +#[auto_decode] +#[deriving(Eq)] +pub enum SelfMode { + ByCopy, + ByRef, +} + pub struct field_ty { ident: ident, id: def_id, @@ -270,7 +276,6 @@ struct ctxt_ { ast_ty_to_ty_cache: @mut HashMap, enum_var_cache: @mut HashMap, ty_param_defs: @mut HashMap, - inferred_modes: @mut HashMap, adjustments: @mut HashMap, normalized_cache: @mut HashMap, lang_items: middle::lang_items::LanguageItems, @@ -630,7 +635,6 @@ pub enum type_err { terr_record_mutability, terr_record_fields(expected_found), terr_arg_count, - terr_mode_mismatch(expected_found), terr_regions_does_not_outlive(Region, Region), terr_regions_not_same(Region, Region), terr_regions_no_overlap(Region, Region), @@ -919,7 +923,6 @@ pub fn mk_ctxt(s: session::Session, trait_method_def_ids: @mut HashMap::new(), trait_methods_cache: @mut HashMap::new(), ty_param_defs: @mut HashMap::new(), - inferred_modes: @mut HashMap::new(), adjustments: @mut HashMap::new(), normalized_cache: new_ty_hash(), lang_items: lang_items, @@ -1199,15 +1202,17 @@ pub fn mk_bare_fn(cx: ctxt, fty: BareFnTy) -> t { } pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t { - let input_args = input_tys.map(|t| arg {mode: ast::expl(ast::by_copy), - ty: *t}); + let input_args = input_tys.map(|t| arg { ty: *t }); mk_bare_fn(cx, BareFnTy { purity: ast::pure_fn, abis: AbiSet::Rust(), - sig: FnSig {bound_lifetime_names: opt_vec::Empty, - inputs: input_args, - output: output}}) + sig: FnSig { + bound_lifetime_names: opt_vec::Empty, + inputs: input_args, + output: output + } + }) } @@ -1258,48 +1263,14 @@ pub fn mach_sty(cfg: @session::config, t: t) -> sty { } } -pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { - // FIXME(#2202) --- We retain by-ref for &fn things to workaround a - // memory leak that otherwise results when @fn is upcast to &fn. - match ty::get(ty).sty { - ty::ty_closure(ClosureTy {sigil: ast::BorrowedSigil, _}) => { - return ast::by_ref; - } - _ => {} - } - return if tcx.legacy_modes { - if type_is_borrowed(ty) { - // the old mode default was ++ for things like &ptr, but to be - // forward-compatible with non-legacy, we should use + - ast::by_copy - } else if ty::type_is_immediate(ty) { - ast::by_copy - } else { - ast::by_ref - } - } else { - ast::by_copy - }; - - fn type_is_borrowed(ty: t) -> bool { - match ty::get(ty).sty { - ty::ty_rptr(*) => true, - ty_evec(_, vstore_slice(_)) => true, - ty_estr(vstore_slice(_)) => true, - - // technically, we prob ought to include - // &fn(), but that is treated specially due to #2202 - _ => false - } - } -} - pub fn walk_ty(ty: t, f: &fn(t)) { maybe_walk_ty(ty, |t| { f(t); true }); } pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) { - if !f(ty) { return; } + if !f(ty) { + return; + } match get(ty).sty { ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_estr(_) | ty_type | ty_opaque_box | ty_self(_) | @@ -1331,7 +1302,9 @@ pub fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: &fn(t) -> t) -> t { pub fn fold_sig(sig: &FnSig, fldop: &fn(t) -> t) -> FnSig { let args = do sig.inputs.map |arg| { - arg { mode: arg.mode, ty: fldop(arg.ty) } + arg { + ty: fldop(arg.ty) + } }; FnSig { @@ -2704,13 +2677,6 @@ impl to_bytes::IterBytes for field { } } -impl to_bytes::IterBytes for arg { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - to_bytes::iter_bytes_2(&self.mode, - &self.ty, lsb0, f) - } -} - impl to_bytes::IterBytes for FnSig { fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.inputs, @@ -3376,78 +3342,6 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { } } -// Maintains a little union-set tree for inferred modes. `canon()` returns -// the current head value for `m0`. -fn canon(tbl: &mut HashMap>, - m0: ast::inferable) -> ast::inferable { - match m0 { - ast::infer(id) => { - let m1 = match tbl.find(&id) { - None => return m0, - Some(&m1) => m1 - }; - let cm1 = canon(tbl, m1); - // path compression: - if cm1 != m1 { tbl.insert(id, cm1); } - cm1 - }, - _ => m0 - } -} - -// Maintains a little union-set tree for inferred modes. `resolve_mode()` -// returns the current head value for `m0`. -pub fn canon_mode(cx: ctxt, m0: ast::mode) -> ast::mode { - canon(cx.inferred_modes, m0) -} - -// Returns the head value for mode, failing if `m` was a infer(_) that -// was never inferred. This should be safe for use after typeck. -pub fn resolved_mode(cx: ctxt, m: ast::mode) -> ast::rmode { - match canon_mode(cx, m) { - ast::infer(_) => { - cx.sess.bug(fmt!("mode %? was never resolved", m)); - } - ast::expl(m0) => m0 - } -} - -pub fn arg_mode(cx: ctxt, a: arg) -> ast::rmode { resolved_mode(cx, a.mode) } - -// Unifies `m1` and `m2`. Returns unified value or failure code. -pub fn unify_mode(cx: ctxt, modes: expected_found) - -> Result { - let m1 = modes.expected; - let m2 = modes.found; - match (canon_mode(cx, m1), canon_mode(cx, m2)) { - (m1, m2) if (m1 == m2) => { - result::Ok(m1) - } - (ast::infer(_), ast::infer(id2)) => { - cx.inferred_modes.insert(id2, m1); - result::Ok(m1) - } - (ast::infer(id), m) | (m, ast::infer(id)) => { - cx.inferred_modes.insert(id, m); - result::Ok(m1) - } - (_, _) => { - result::Err(terr_mode_mismatch(modes)) - } - } -} - -// If `m` was never unified, unifies it with `m_def`. Returns the final value -// for `m`. -pub fn set_default_mode(cx: ctxt, m: ast::mode, m_def: ast::rmode) { - match canon_mode(cx, m) { - ast::infer(id) => { - cx.inferred_modes.insert(id, ast::expl(m_def)); - } - ast::expl(_) => () - } -} - pub fn ty_sort_str(cx: ctxt, t: t) -> ~str { match get(t).sty { ty_nil | ty_bot | ty_bool | ty_int(_) | @@ -3545,11 +3439,6 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { *cx.sess.str_of(values.found)) } terr_arg_count => ~"incorrect number of function parameters", - terr_mode_mismatch(values) => { - fmt!("expected argument mode %s, but found %s", - pprust::mode_to_str(values.expected), - pprust::mode_to_str(values.found)) - } terr_regions_does_not_outlive(*) => { fmt!("lifetime mismatch") } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index ac745dce36d80..ffaa6d46d3379 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -501,52 +501,22 @@ pub fn ast_ty_to_ty( return typ; } -pub fn ty_of_arg( - self: &AC, - rscope: &RS, - a: ast::arg, - expected_ty: Option) - -> ty::arg { +pub fn ty_of_arg( + self: &AC, + rscope: &RS, + a: ast::arg, + expected_ty: Option) + -> ty::arg { let ty = match a.ty.node { - ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty, - ast::ty_infer => self.ty_infer(a.ty.span), - _ => ast_ty_to_ty(self, rscope, a.ty) - }; - - let mode = { - match a.mode { - ast::infer(_) if expected_ty.is_some() => { - result::get(&ty::unify_mode( - self.tcx(), - ty::expected_found {expected: expected_ty.get().mode, - found: a.mode})) - } - ast::infer(_) => { - match ty::get(ty).sty { - // If the type is not specified, then this must be a fn expr. - // Leave the mode as infer(_), it will get inferred based - // on constraints elsewhere. - ty::ty_infer(_) => a.mode, - - // If the type is known, then use the default for that type. - // Here we unify m and the default. This should update the - // tables in tcx but should never fail, because nothing else - // will have been unified with m yet: - _ => { - let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(), - ty)); - result::get(&ty::unify_mode( - self.tcx(), - ty::expected_found {expected: m1, - found: a.mode})) - } - } - } - ast::expl(_) => a.mode - } + ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty, + ast::ty_infer => self.ty_infer(a.ty.span), + _ => ast_ty_to_ty(self, rscope, a.ty), }; - arg {mode: mode, ty: ty} + arg { + ty: ty + } } pub fn bound_lifetimes( diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 40ad8bcb8b26c..fb5b53d9400fb 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -96,7 +96,7 @@ use util::common::indenter; use core::hashmap::HashSet; use std::list::Nil; use syntax::ast::{def_id, sty_value, sty_region, sty_box}; -use syntax::ast::{sty_uniq, sty_static, node_id, by_copy, by_ref}; +use syntax::ast::{sty_uniq, sty_static, node_id}; use syntax::ast::{m_const, m_mutbl, m_imm}; use syntax::ast; use syntax::ast_map; @@ -1051,9 +1051,9 @@ pub impl<'self> LookupContext<'self> { self.fcx.write_substs(self.callee_id, all_substs); method_map_entry { self_arg: arg { - mode: ast::expl(self_mode), ty: candidate.rcvr_ty, }, + self_mode: self_mode, explicit_self: candidate.method_ty.self_ty, origin: candidate.origin, } @@ -1298,6 +1298,9 @@ pub impl<'self> LookupContext<'self> { } } -pub fn get_mode_from_self_type(self_type: ast::self_ty_) -> ast::rmode { - match self_type { sty_value => by_copy, _ => by_ref } +pub fn get_mode_from_self_type(self_type: ast::self_ty_) -> SelfMode { + match self_type { + sty_value => ty::ByCopy, + _ => ty::ByRef, + } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e230495e56895..b9f3de873cf07 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -107,6 +107,7 @@ use util::common::{block_query, indenter, loop_query}; use util::ppaux::{bound_region_to_str}; use util::ppaux; +use core::cast::transmute; use core::hashmap::HashMap; use core::util::replace; use std::list::Nil; @@ -706,7 +707,11 @@ impl region_scope for FnCtxt { } pub impl FnCtxt { - fn tag(&self) -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) } + fn tag(&self) -> ~str { + unsafe { + fmt!("%x", transmute(self)) + } + } fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t { match self.inh.locals.find(&nid) { @@ -1287,8 +1292,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } fn err_args(len: uint) -> ~[ty::arg] { - vec::from_fn(len, |_| ty::arg {mode: ast::expl(ast::by_copy), - ty: ty::mk_err()}) + vec::from_fn(len, |_| ty::arg { ty: ty::mk_err() }) } // A generic function for checking assignment expressions @@ -1689,10 +1693,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let fty = if error_happened { fty_sig = FnSig { bound_lifetime_names: opt_vec::Empty, - inputs: fn_ty.sig.inputs.map(|an_arg| { - arg { mode: an_arg.mode, - ty: ty::mk_err() - }}), + inputs: fn_ty.sig.inputs.map(|_| { + arg { + ty: ty::mk_err() + } + }), output: ty::mk_err() }; ty::mk_err() @@ -2757,11 +2762,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, }; if bot_field { fcx.write_bot(id); - } - else if err_field { + } else if err_field { fcx.write_error(id); - } - else { + } else { let typ = ty::mk_tup(tcx, elt_ts); fcx.write_ty(id, typ); } @@ -2791,15 +2794,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, check_expr(fcx, idx); let raw_base_t = fcx.expr_ty(base); let idx_t = fcx.expr_ty(idx); - if ty::type_is_error(raw_base_t) - || ty::type_is_bot(raw_base_t) { + if ty::type_is_error(raw_base_t) || ty::type_is_bot(raw_base_t) { fcx.write_ty(id, raw_base_t); - } - else if ty::type_is_error(idx_t) - || ty::type_is_bot(idx_t) { + } else if ty::type_is_error(idx_t) || ty::type_is_bot(idx_t) { fcx.write_ty(id, idx_t); - } - else { + } else { let (base_t, derefs) = do_autoderef(fcx, expr.span, raw_base_t); let base_sty = structure_of(fcx, expr.span, base_t); match ty::index_sty(&base_sty) { @@ -2810,15 +2809,29 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } None => { let resolved = structurally_resolved_type(fcx, - expr.span, raw_base_t); - let ret_ty = lookup_op_method(fcx, expr, base, resolved, - tcx.sess.ident_of(~"index"), - ~[idx], DoDerefArgs, AutoderefReceiver, - || { - fcx.type_error_message(expr.span, |actual| - fmt!("cannot index a value \ - of type `%s`", actual), base_t, None); - }, expected); + expr.span, + raw_base_t); + let index_ident = tcx.sess.ident_of(~"index"); + let error_message = || { + fcx.type_error_message(expr.span, + |actual| { + fmt!("cannot index a value \ + of type `%s`", + actual) + }, + base_t, + None); + }; + let ret_ty = lookup_op_method(fcx, + expr, + base, + resolved, + index_ident, + ~[idx], + DoDerefArgs, + AutoderefReceiver, + error_message, + expected); fcx.write_ty(id, ret_ty); } } @@ -3175,8 +3188,8 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, -> ty_param_bounds_and_ty { match defn { - ast::def_arg(nid, _, _) | ast::def_local(nid, _) | - ast::def_self(nid, _) | ast::def_binding(nid, _) => { + ast::def_arg(nid, _) | ast::def_local(nid, _) | ast::def_self(nid, _) | + ast::def_binding(nid, _) => { let typ = fcx.local_ty(sp, nid); return no_params(typ); } @@ -3424,44 +3437,52 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t { ty::mk_param(ccx.tcx, n, local_def(0)) } - fn arg(m: ast::rmode, ty: ty::t) -> ty::arg { - arg {mode: ast::expl(m), ty: ty} + fn arg(ty: ty::t) -> ty::arg { + arg { + ty: ty + } } + let tcx = ccx.tcx; let (n_tps, inputs, output) = match *ccx.tcx.sess.str_of(it.ident) { ~"size_of" | ~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint()), ~"init" => (1u, ~[], param(ccx, 0u)), - ~"forget" => (1u, ~[arg(ast::by_copy, param(ccx, 0u))], - ty::mk_nil()), - ~"reinterpret_cast" => (2u, ~[arg(ast::by_ref, param(ccx, 0u))], - param(ccx, 1u)), - ~"addr_of" => (1u, ~[arg(ast::by_ref, param(ccx, 0u))], - ty::mk_imm_ptr(tcx, param(ccx, 0u))), + ~"forget" => (1u, ~[arg(param(ccx, 0u))], ty::mk_nil()), + ~"transmute" => (2, ~[ arg(param(ccx, 0)) ], param(ccx, 1)), ~"move_val" | ~"move_val_init" => { - (1u, ~[arg(ast::by_copy, - ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), - param(ccx, 0u))), - arg(ast::by_copy, param(ccx, 0u))], + (1u, + ~[ + arg(ty::mk_mut_rptr(tcx, + ty::re_bound(ty::br_anon(0)), + param(ccx, 0))), + arg(param(ccx, 0u)) + ], ty::mk_nil()) } ~"needs_drop" => (1u, ~[], ty::mk_bool()), ~"atomic_cxchg" | ~"atomic_cxchg_acq"| ~"atomic_cxchg_rel" => { - (0u, ~[arg(ast::by_copy, - ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), - ty::mk_int())), - arg(ast::by_copy, ty::mk_int()), - arg(ast::by_copy, ty::mk_int())], + (0, + ~[ + arg(ty::mk_mut_rptr(tcx, + ty::re_bound(ty::br_anon(0)), + ty::mk_int())), + arg(ty::mk_int()), + arg(ty::mk_int()) + ], ty::mk_int()) } ~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" | ~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" | ~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => { - (0u, ~[arg(ast::by_copy, - ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), - ty::mk_int())), - arg(ast::by_copy, ty::mk_int())], + (0, + ~[ + arg(ty::mk_mut_rptr(tcx, + ty::re_bound(ty::br_anon(0)), + ty::mk_int())), + arg(ty::mk_int()) + ], ty::mk_int()) } @@ -3470,14 +3491,15 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { (1u, ~[], ty::mk_nil_ptr(ccx.tcx)) } ~"visit_tydesc" => { - let tydesc_name = special_idents::tydesc; - assert!(tcx.intrinsic_defs.contains_key(&tydesc_name)); - let (_, tydesc_ty) = *tcx.intrinsic_defs.get(&tydesc_name); - let (_, visitor_object_ty) = ty::visitor_object_ty(ccx.tcx); - let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty, - mutbl: ast::m_imm}); - (0u, ~[arg(ast::by_copy, td_ptr), - arg(ast::by_ref, visitor_object_ty)], ty::mk_nil()) + let tydesc_name = special_idents::tydesc; + assert!(tcx.intrinsic_defs.contains_key(&tydesc_name)); + let (_, tydesc_ty) = *tcx.intrinsic_defs.get(&tydesc_name); + let (_, visitor_object_ty) = ty::visitor_object_ty(tcx); + let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt { + ty: tydesc_ty, + mutbl: ast::m_imm + }); + (0, ~[ arg(td_ptr), arg(visitor_object_ty) ], ty::mk_nil()) } ~"frame_address" => { let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy { @@ -3487,233 +3509,124 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { region: ty::re_bound(ty::br_anon(0)), sig: ty::FnSig { bound_lifetime_names: opt_vec::Empty, - inputs: ~[arg {mode: ast::expl(ast::by_copy), - ty: ty::mk_imm_ptr( - ccx.tcx, - ty::mk_mach_uint(ast::ty_u8))}], + inputs: ~[ + arg { + ty: ty::mk_imm_ptr(ccx.tcx, + ty::mk_mach_uint(ast::ty_u8)) + } + ], output: ty::mk_nil() } }); - (0u, ~[arg(ast::by_ref, fty)], ty::mk_nil()) + (0u, ~[ arg(fty) ], ty::mk_nil()) } ~"morestack_addr" => { (0u, ~[], ty::mk_nil_ptr(ccx.tcx)) } ~"memmove32" => { - (0, ~[arg(ast::by_copy, - ty::mk_ptr(tcx, - ty::mt { ty: ty::mk_u8(), mutbl: ast::m_mutbl })), - arg(ast::by_copy, - ty::mk_ptr(tcx, - ty::mt { ty: ty::mk_u8(), mutbl: ast::m_imm })), - arg(ast::by_copy, - ty::mk_u32())], + (0, + ~[ + arg(ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_mutbl + })), + arg(ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_imm + })), + arg(ty::mk_u32()) + ], ty::mk_nil()) } ~"memmove64" => { - (0, ~[arg(ast::by_copy, - ty::mk_ptr(tcx, - ty::mt { ty: ty::mk_u8(), mutbl: ast::m_mutbl })), - arg(ast::by_copy, - ty::mk_ptr(tcx, - ty::mt { ty: ty::mk_u8(), mutbl: ast::m_imm })), - arg(ast::by_copy, - ty::mk_u64())], + (0, + ~[arg(ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_mutbl + })), + arg(ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_imm + })), + arg(ty::mk_u64()) + ], ty::mk_nil()) } - ~"sqrtf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"sqrtf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"powif32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32()), - arg(ast::by_copy, ty::mk_i32())], - ty::mk_f32()) - } - ~"powif64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64()), - arg(ast::by_copy, ty::mk_i32())], - ty::mk_f64()) - } - ~"sinf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"sinf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"cosf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"cosf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"powf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32()), - arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"powf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64()), - arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"expf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"expf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"exp2f32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"exp2f64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"logf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"logf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"log10f32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"log10f64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"log2f32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"log2f64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"fmaf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32()), - arg(ast::by_copy, ty::mk_f32()), - arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"fmaf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64()), - arg(ast::by_copy, ty::mk_f64()), - arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"fabsf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"fabsf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"floorf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"floorf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"ceilf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"ceilf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"truncf32" => { - (0u, ~[arg(ast::by_copy, ty::mk_f32())], - ty::mk_f32()) - } - ~"truncf64" => { - (0u, ~[arg(ast::by_copy, ty::mk_f64())], - ty::mk_f64()) - } - ~"ctpop8" => { - (0u, ~[arg(ast::by_copy, ty::mk_i8())], - ty::mk_i8()) - } - ~"ctpop16" => { - (0u, ~[arg(ast::by_copy, ty::mk_i16())], - ty::mk_i16()) - } - ~"ctpop32" => { - (0u, ~[arg(ast::by_copy, ty::mk_i32())], - ty::mk_i32()) - } - ~"ctpop64" => { - (0u, ~[arg(ast::by_copy, ty::mk_i64())], - ty::mk_i64()) - } - ~"ctlz8" => { - (0u, ~[arg(ast::by_copy, ty::mk_i8())], - ty::mk_i8()) - } - ~"ctlz16" => { - (0u, ~[arg(ast::by_copy, ty::mk_i16())], - ty::mk_i16()) - } - ~"ctlz32" => { - (0u, ~[arg(ast::by_copy, ty::mk_i32())], - ty::mk_i32()) - } - ~"ctlz64" => { - (0u, ~[arg(ast::by_copy, ty::mk_i64())], - ty::mk_i64()) - } - ~"cttz8" => { - (0u, ~[arg(ast::by_copy, ty::mk_i8())], - ty::mk_i8()) - } - ~"cttz16" => { - (0u, ~[arg(ast::by_copy, ty::mk_i16())], - ty::mk_i16()) - } - ~"cttz32" => { - (0u, ~[arg(ast::by_copy, ty::mk_i32())], - ty::mk_i32()) - } - ~"cttz64" => { - (0u, ~[arg(ast::by_copy, ty::mk_i64())], - ty::mk_i64()) - } - ~"bswap16" => { - (0u, ~[arg(ast::by_copy, ty::mk_i16())], - ty::mk_i16()) - } - ~"bswap32" => { - (0u, ~[arg(ast::by_copy, ty::mk_i32())], - ty::mk_i32()) - } - ~"bswap64" => { - (0u, ~[arg(ast::by_copy, ty::mk_i64())], - ty::mk_i64()) - } - ref other => { - tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" + - (*other) + ~"`"); - return; - } + ~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"powif32" => { + (0, + ~[ arg(ty::mk_f32()), arg(ty::mk_i32()) ], + ty::mk_f32()) + } + ~"powif64" => { + (0, + ~[ arg(ty::mk_f64()), arg(ty::mk_i32()) ], + ty::mk_f64()) + } + ~"sinf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"sinf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"cosf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"cosf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"powf32" => { + (0, + ~[ arg(ty::mk_f32()), arg(ty::mk_f32()) ], + ty::mk_f32()) + } + ~"powf64" => { + (0, + ~[ arg(ty::mk_f64()), arg(ty::mk_f64()) ], + ty::mk_f64()) + } + ~"expf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"expf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"exp2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"exp2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"logf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"logf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"log10f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"log10f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"log2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"log2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"fmaf32" => { + (0, + ~[ arg(ty::mk_f32()), arg(ty::mk_f32()), arg(ty::mk_f32()) ], + ty::mk_f32()) + } + ~"fmaf64" => { + (0, + ~[ arg(ty::mk_f64()), arg(ty::mk_f64()), arg(ty::mk_f64()) ], + ty::mk_f64()) + } + ~"fabsf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"fabsf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"floorf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"floorf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"ceilf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"ceilf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"truncf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), + ~"truncf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"ctpop8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), + ~"ctpop16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), + ~"ctpop32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), + ~"ctpop64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), + ~"ctlz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), + ~"ctlz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), + ~"ctlz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), + ~"ctlz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), + ~"cttz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), + ~"cttz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), + ~"cttz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), + ~"cttz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), + ~"bswap16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), + ~"bswap32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), + ~"bswap64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), + ref other => { + tcx.sess.span_err(it.span, + ~"unrecognized intrinsic function: `" + + (*other) + ~"`"); + return; + } }; let fty = ty::mk_bare_fn(tcx, ty::BareFnTy { purity: ast::unsafe_fn, diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 1cffd375f9b6a..cb2b854276d6f 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -55,7 +55,7 @@ pub type rvt = visit::vt<@mut Rcx>; fn encl_region_of_def(fcx: @mut FnCtxt, def: ast::def) -> ty::Region { let tcx = fcx.tcx(); match def { - def_local(node_id, _) | def_arg(node_id, _, _) | + def_local(node_id, _) | def_arg(node_id, _) | def_self(node_id, _) | def_binding(node_id, _) => { tcx.region_maps.encl_region(node_id) } diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 0b0f7515b6b04..d6b09d1e7f453 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -66,7 +66,9 @@ fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) { for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { let method_map = fcx.ccx.method_map; let new_entry = method_map_entry { - self_arg: arg {mode: mme.self_arg.mode, ty: *t }, + self_arg: arg { + ty: *t + }, ..*mme }; debug!("writeback::resolve_method_map_entry(id=%?, \ @@ -213,52 +215,55 @@ fn visit_stmt(s: @ast::stmt, wbcx: @mut WbCtxt, v: wb_vt) { resolve_type_vars_for_node(wbcx, s.span, ty::stmt_node_id(s)); visit::visit_stmt(s, wbcx, v); } + fn visit_expr(e: @ast::expr, wbcx: @mut WbCtxt, v: wb_vt) { - if !wbcx.success { return; } + if !wbcx.success { + return; + } + resolve_type_vars_for_node(wbcx, e.span, e.id); resolve_method_map_entry(wbcx.fcx, e.span, e.id); resolve_method_map_entry(wbcx.fcx, e.span, e.callee_id); resolve_vtable_map_entry(wbcx.fcx, e.span, e.id); resolve_vtable_map_entry(wbcx.fcx, e.span, e.callee_id); + match e.node { - ast::expr_fn_block(ref decl, _) => { - for vec::each(decl.inputs) |input| { - let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id); - - // Just in case we never constrained the mode to anything, - // constrain it to the default for the type in question. - match (r_ty, input.mode) { - (Some(t), ast::infer(_)) => { - let tcx = wbcx.fcx.ccx.tcx; - let m_def = ty::default_arg_mode_for_ty(tcx, t); - ty::set_default_mode(tcx, input.mode, m_def); - } - _ => () - } - } - } + ast::expr_fn_block(ref decl, _) => { + for vec::each(decl.inputs) |input| { + let _ = resolve_type_vars_for_node(wbcx, e.span, input.id); + } + } - ast::expr_binary(*) | ast::expr_unary(*) | ast::expr_assign_op(*) - | ast::expr_index(*) => { - maybe_resolve_type_vars_for_node(wbcx, e.span, e.callee_id); - } + ast::expr_binary(*) | ast::expr_unary(*) | ast::expr_assign_op(*) | + ast::expr_index(*) => { + maybe_resolve_type_vars_for_node(wbcx, e.span, e.callee_id); + } - ast::expr_method_call(*) => { - // We must always have written in a callee ID type for these. - resolve_type_vars_for_node(wbcx, e.span, e.callee_id); - } + ast::expr_method_call(*) => { + // We must always have written in a callee ID type for these. + resolve_type_vars_for_node(wbcx, e.span, e.callee_id); + } - _ => () + _ => () } + visit::visit_expr(e, wbcx, v); } + fn visit_block(b: &ast::blk, wbcx: @mut WbCtxt, v: wb_vt) { - if !wbcx.success { return; } + if !wbcx.success { + return; + } + resolve_type_vars_for_node(wbcx, b.span, b.node.id); visit::visit_block(b, wbcx, v); } + fn visit_pat(p: @ast::pat, wbcx: @mut WbCtxt, v: wb_vt) { - if !wbcx.success { return; } + if !wbcx.success { + return; + } + resolve_type_vars_for_node(wbcx, p.span, p.id); debug!("Type for pattern binding %s (id %d) resolved to %s", pat_to_str(p, wbcx.fcx.ccx.tcx.sess.intr()), p.id, @@ -267,6 +272,7 @@ fn visit_pat(p: @ast::pat, wbcx: @mut WbCtxt, v: wb_vt) { p.id))); visit::visit_pat(p, wbcx, v); } + fn visit_local(l: @ast::local, wbcx: @mut WbCtxt, v: wb_vt) { if !wbcx.success { return; } let var_ty = wbcx.fcx.local_ty(l.span, l.node.id); diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 14c9bc36d7f7a..05b2f6f577b82 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -38,8 +38,9 @@ use middle::typeck::infer::combine::Combine; use middle::typeck::infer::InferCtxt; use middle::typeck::infer::{new_infer_ctxt, resolve_ivar}; use middle::typeck::infer::{resolve_nested_tvar, resolve_type}; -use syntax::ast::{crate, def_id, def_mod, def_trait}; -use syntax::ast::{item, item_impl, item_mod, local_crate, method, trait_ref}; +use syntax::ast::{crate, def_id, def_mod, def_struct, def_trait, def_ty}; +use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct}; +use syntax::ast::{local_crate, method, trait_ref, ty_path}; use syntax::ast; use syntax::ast_map::node_item; use syntax::ast_map; @@ -661,7 +662,19 @@ pub impl CoherenceChecker { // Then visit the module items. visit_mod(module_, item.span, item.id, (), visitor); } - item_impl(_, opt_trait, _, _) => { + item_impl(_, None, ast_ty, _) => { + if !self.ast_type_is_defined_in_local_crate(ast_ty) { + // This is an error. + let session = self.crate_context.tcx.sess; + session.span_err(item.span, + ~"cannot associate methods with \ + a type outside the crate the \ + type is defined in; define \ + and implement a trait or new \ + type instead"); + } + } + item_impl(_, Some(trait_ref), _, _) => { // `for_ty` is `Type` in `impl Trait for Type` let for_ty = ty::node_id_to_type(self.crate_context.tcx, @@ -671,40 +684,16 @@ pub impl CoherenceChecker { // type. This still might be OK if the trait is // defined in the same crate. - match opt_trait { - None => { - // There is no trait to implement, so - // this is an error. - - let session = self.crate_context.tcx.sess; - session.span_err(item.span, - ~"cannot implement \ - inherent methods for a \ - type outside the crate \ - the type was defined \ - in; define and \ - implement a trait or \ - new type instead"); - } + let trait_def_id = + self.trait_ref_to_trait_def_id(trait_ref); - Some(trait_ref) => { - // This is OK if and only if the trait was - // defined in this crate. - - let trait_def_id = - self.trait_ref_to_trait_def_id( - trait_ref); - - if trait_def_id.crate != local_crate { - let session = self.crate_context.tcx.sess; - session.span_err(item.span, - ~"cannot provide an \ - extension \ - implementation for a \ - trait not defined in \ - this crate"); - } - } + if trait_def_id.crate != local_crate { + let session = self.crate_context.tcx.sess; + session.span_err(item.span, + ~"cannot provide an \ + extension implementation \ + for a trait not defined \ + in this crate"); } } @@ -754,6 +743,46 @@ pub impl CoherenceChecker { } } + /// For coherence, when we have `impl Type`, we need to guarantee that + /// `Type` is "local" to the crate. For our purposes, this means that it + /// must precisely name some nominal type defined in this crate. + pub fn ast_type_is_defined_in_local_crate(&self, original_type: @ast::Ty) + -> bool { + match original_type.node { + ty_path(_, path_id) => { + match *self.crate_context.tcx.def_map.get(&path_id) { + def_ty(def_id) | def_struct(def_id) => { + if def_id.crate != local_crate { + return false; + } + + // Make sure that this type precisely names a nominal + // type. + match self.crate_context + .tcx + .items + .find(&def_id.node) { + None => { + self.crate_context.tcx.sess.span_bug( + original_type.span, + ~"resolve didn't resolve this type?!"); + } + Some(&node_item(item, _)) => { + match item.node { + item_struct(*) | item_enum(*) => true, + _ => false, + } + } + Some(_) => false, + } + } + _ => false + } + } + _ => false + } + } + // Converts an implementation in the AST to an Impl structure. fn create_impl_from_item(&self, item: @item) -> @Impl { fn add_provided_methods(all_methods: &mut ~[@MethodInfo], diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 828dfbb45cf72..0ffd398d03c19 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -552,10 +552,14 @@ pub fn compare_impl_method(tcx: ty::ctxt, // represent the self argument (unless this is a static method). // This argument will have the *transformed* self type. for trait_m.transformed_self_ty.each |&t| { - trait_fn_args.push(ty::arg {mode: ast::expl(ast::by_copy), ty: t}); + trait_fn_args.push(ty::arg { + ty: t + }); } for impl_m.transformed_self_ty.each |&t| { - impl_fn_args.push(ty::arg {mode: ast::expl(ast::by_copy), ty: t}); + impl_fn_args.push(ty::arg { + ty: t + }); } // Add in the normal arguments. diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 58ad2fc1924ed..e4db423c2e35c 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -95,7 +95,6 @@ pub trait Combine { b: &ty::ClosureTy) -> cres; fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres; fn flds(&self, a: ty::field, b: ty::field) -> cres; - fn modes(&self, a: ast::mode, b: ast::mode) -> cres; fn args(&self, a: ty::arg, b: ty::arg) -> cres; fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres; fn purities(&self, a: purity, b: purity) -> cres; @@ -312,28 +311,20 @@ pub fn super_flds( } } -pub fn super_modes( - self: &C, a: ast::mode, b: ast::mode) - -> cres { - - let tcx = self.infcx().tcx; - ty::unify_mode(tcx, expected_found(self, a, b)) -} - -pub fn super_args( - self: &C, a: ty::arg, b: ty::arg) - -> cres { - - do self.modes(a.mode, b.mode).chain |m| { - do self.contratys(a.ty, b.ty).chain |t| { - Ok(arg {mode: m, ty: t}) - } +pub fn super_args(self: &C, a: ty::arg, b: ty::arg) + -> cres { + do self.contratys(a.ty, b.ty).chain |t| { + Ok(arg { + ty: t + }) } } -pub fn super_vstores( - self: &C, vk: ty::terr_vstore_kind, - a: ty::vstore, b: ty::vstore) -> cres { +pub fn super_vstores(self: &C, + vk: ty::terr_vstore_kind, + a: ty::vstore, + b: ty::vstore) + -> cres { debug!("%s.super_vstores(a=%?, b=%?)", self.tag(), a, b); match (a, b) { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 78b3b097ae305..2bbcd24595cba 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -152,10 +152,6 @@ impl Combine for Glb { super_trait_stores(self, vk, a, b) } - fn modes(&self, a: ast::mode, b: ast::mode) -> cres { - super_modes(self, a, b) - } - fn args(&self, a: ty::arg, b: ty::arg) -> cres { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index c79e530084f41..8591433801796 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -234,10 +234,6 @@ impl Combine for Lub { super_trait_stores(self, vk, a, b) } - fn modes(&self, a: ast::mode, b: ast::mode) -> cres { - super_modes(self, a, b) - } - fn args(&self, a: ty::arg, b: ty::arg) -> cres { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index b9541d4c066b9..266d157c4d040 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -241,14 +241,10 @@ impl Combine for Sub { vk: ty::terr_vstore_kind, a: ty::TraitStore, b: ty::TraitStore) - -> cres { + -> cres { super_trait_stores(self, vk, a, b) } - fn modes(&self, a: ast::mode, b: ast::mode) -> cres { - super_modes(self, a, b) - } - fn args(&self, a: ty::arg, b: ty::arg) -> cres { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 14ef3feb7d53e..646b6412f5507 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -116,10 +116,13 @@ pub struct method_param { } pub struct method_map_entry { - // the type and mode of the self parameter, which is not reflected - // in the fn type (FIXME #3446) + // the type of the self parameter, which is not reflected in the fn type + // (FIXME #3446) self_arg: ty::arg, + // the mode of `self` + self_mode: ty::SelfMode, + // the type of explicit self on the method explicit_self: ast::self_ty_, @@ -329,7 +332,6 @@ fn check_main_fn_ty(ccx: @mut CrateCtxt, fn check_start_fn_ty(ccx: @mut CrateCtxt, start_id: ast::node_id, start_span: span) { - let tcx = ccx.tcx; let start_t = ty::node_id_to_type(tcx, start_id); match ty::get(start_t).sty { @@ -351,19 +353,25 @@ fn check_start_fn_ty(ccx: @mut CrateCtxt, _ => () } - fn arg(m: ast::rmode, ty: ty::t) -> ty::arg { - ty::arg {mode: ast::expl(m), ty: ty} + fn arg(ty: ty::t) -> ty::arg { + ty::arg { + ty: ty + } } let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { purity: ast::impure_fn, abis: abi::AbiSet::Rust(), - sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty, - inputs: ~[arg(ast::by_copy, ty::mk_int()), - arg(ast::by_copy, ty::mk_imm_ptr(tcx, - ty::mk_imm_ptr(tcx, ty::mk_u8()))), - arg(ast::by_copy, ty::mk_imm_ptr(tcx, ty::mk_u8()))], - output: ty::mk_int()} + sig: ty::FnSig { + bound_lifetime_names: opt_vec::Empty, + inputs: ~[ + arg(ty::mk_int()), + arg(ty::mk_imm_ptr(tcx, + ty::mk_imm_ptr(tcx, ty::mk_u8()))), + arg(ty::mk_imm_ptr(tcx, ty::mk_u8())) + ], + output: ty::mk_int() + } }); require_same_types(tcx, None, false, start_span, start_t, se_ty, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index f0ea91c91534e..aa8c3f8fd1b7e 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -8,28 +8,25 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::ty; -use middle::typeck; -use middle::ty::canon_mode; -use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid, - br_fresh}; -use middle::ty::{ctxt, field, method}; +use metadata::encoder; +use middle::ty::{ReSkolemized, ReVar}; +use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid}; +use middle::ty::{br_fresh, ctxt, field, method}; use middle::ty::{mt, t, param_bound, param_ty}; use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region}; -use middle::ty::{ReSkolemized, ReVar}; use middle::ty::{ty_bool, ty_bot, ty_box, ty_struct, ty_enum}; use middle::ty::{ty_err, ty_estr, ty_evec, ty_float, ty_bare_fn, ty_closure}; -use middle::ty::{ty_trait, ty_int}; use middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param}; use middle::ty::{ty_ptr, ty_rptr, ty_self, ty_tup, ty_type, ty_uniq}; +use middle::ty::{ty_trait, ty_int}; use middle::ty::{ty_uint, ty_unboxed_vec, ty_infer}; -use metadata::encoder; +use middle::ty; +use middle::typeck; +use syntax::abi::AbiSet; +use syntax::ast_map; use syntax::codemap::span; use syntax::print::pprust; -use syntax::print::pprust::mode_to_str; use syntax::{ast, ast_util}; -use syntax::ast_map; -use syntax::abi::AbiSet; pub trait Repr { fn repr(&self, tcx: ctxt) -> ~str; @@ -293,26 +290,14 @@ pub fn trait_ref_to_str(cx: ctxt, trait_ref: &ty::TraitRef) -> ~str { pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { fn fn_input_to_str(cx: ctxt, input: ty::arg) -> ~str { - let ty::arg {mode: mode, ty: ty} = input; - let modestr = match canon_mode(cx, mode) { - ast::infer(_) => ~"", - ast::expl(m) => { - if !ty::type_needs_infer(ty) && - m == ty::default_arg_mode_for_ty(cx, ty) { - ~"" - } else { - mode_to_str(ast::expl(m)) + ~":" - } - } - }; - fmt!("%s%s", modestr, ty_to_str(cx, ty)) + ty_to_str(cx, input.ty) } fn bare_fn_to_str(cx: ctxt, purity: ast::purity, abis: AbiSet, ident: Option, - sig: &ty::FnSig) -> ~str - { + sig: &ty::FnSig) + -> ~str { let mut s = ~"extern "; s.push_str(abis.to_str()); @@ -701,7 +686,7 @@ impl Repr for typeck::method_map_entry { impl Repr for ty::arg { fn repr(&self, tcx: ctxt) -> ~str { - fmt!("%?(%s)", self.mode, self.ty.repr(tcx)) + fmt!("(%s)", self.ty.repr(tcx)) } } diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index 0b297e9e6ba72..34dd6390ecc12 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -11,7 +11,6 @@ //! Unsafe debugging functions for inspecting values. use core::cast::transmute; -use core::ptr; use core::sys; pub mod rustrt { @@ -37,36 +36,31 @@ pub fn debug_tydesc() { pub fn debug_opaque(x: T) { unsafe { - rustrt::debug_opaque(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_opaque(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_box(x: @T) { unsafe { - rustrt::debug_box(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_box(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_tag(x: T) { unsafe { - rustrt::debug_tag(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_tag(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_fn(x: T) { unsafe { - rustrt::debug_fn(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_fn(sys::get_type_desc::(), transmute(&x)); } } pub unsafe fn ptr_cast(x: @T) -> @U { transmute( - rustrt::debug_ptrcast(sys::get_type_desc::(), - transmute(x))) + rustrt::debug_ptrcast(sys::get_type_desc::(), transmute(x))) } /// Triggers a debugger breakpoint diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 264f3072cb162..f59abfa81ca10 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -23,7 +23,7 @@ use core::cast; use core::cell::Cell; -use core::comm::{oneshot, PortOne, send_one}; +use core::comm::{ChanOne, PortOne, oneshot, send_one}; use core::pipes::recv; use core::task; @@ -120,8 +120,7 @@ pub fn from_value(val: A) -> Future { Future {state: Forced(val)} } -pub fn from_port(port: PortOne) -> - Future { +pub fn from_port(port: PortOne) -> Future { /*! * Create a future from a port * @@ -131,7 +130,7 @@ pub fn from_port(port: PortOne) -> let port = Cell(port); do from_fn || { - let port = port.take(); + let port = port.take().unwrap(); match recv(port) { oneshot::send(data) => data } @@ -158,10 +157,10 @@ pub fn spawn(blk: ~fn() -> A) -> Future { * value of the future. */ - let (chan, port) = oneshot::init(); + let (port, chan) = oneshot(); let chan = Cell(chan); - do task::spawn || { + do task::spawn { let chan = chan.take(); send_one(chan, blk()); } @@ -186,7 +185,7 @@ mod test { #[test] fn test_from_port() { - let (ch, po) = oneshot::init(); + let (po, ch) = oneshot(); send_one(ch, ~"whale"); let f = from_port(po); assert!(f.get() == ~"whale"); diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index aa1903e4a2179..800144c0ca7be 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -110,18 +110,18 @@ enum IpGetAddrErr { * object in the case of failure */ pub fn get_addr(node: &str, iotask: &iotask) - -> result::Result<~[IpAddr], IpGetAddrErr> { + -> result::Result<~[IpAddr], IpGetAddrErr> { let (output_po, output_ch) = stream(); let mut output_ch = Some(SharedChan::new(output_ch)); do str::as_buf(node) |node_ptr, len| { let output_ch = output_ch.swap_unwrap(); debug!("slice len %?", len); let handle = create_uv_getaddrinfo_t(); - let handle_ptr = ptr::addr_of(&handle); + let handle_ptr: *uv_getaddrinfo_t = &handle; let handle_data = GetAddrData { output_ch: output_ch.clone() }; - let handle_data_ptr = ptr::addr_of(&handle_data); + let handle_data_ptr: *GetAddrData = &handle_data; do interact(iotask) |loop_ptr| { unsafe { let result = uv_getaddrinfo( @@ -151,7 +151,7 @@ pub mod v4 { use uv_ip4_addr = uv::ll::ip4_addr; use uv_ip4_name = uv::ll::ip4_name; - use core::ptr; + use core::cast::transmute; use core::result; use core::str; use core::uint; @@ -189,7 +189,8 @@ pub mod v4 { impl AsUnsafeU32 for Ipv4Rep { // this is pretty dastardly, i know unsafe fn as_u32(&self) -> u32 { - *((ptr::addr_of(self)) as *u32) + let this: &mut u32 = transmute(self); + *this } } pub fn parse_to_ipv4_rep(ip: &str) -> result::Result { @@ -297,7 +298,8 @@ struct GetAddrData { output_ch: SharedChan> } -extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, +extern fn get_addr_cb(handle: *uv_getaddrinfo_t, + status: libc::c_int, res: *addrinfo) { unsafe { debug!("in get_addr_cb"); diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index ee109047cb161..764152d6812c5 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -156,7 +156,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, result_ch: result_ch, closed_signal_ch: closed_signal_ch }; - let conn_data_ptr = ptr::addr_of(&conn_data); + let conn_data_ptr: *ConnectReqData = &conn_data; let (reader_po, reader_ch) = stream::>(); let reader_ch = SharedChan::new(reader_ch); let stream_handle_ptr = malloc_uv_tcp_t(); @@ -173,7 +173,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, }, iotask: iotask.clone() }; - let socket_data_ptr = ptr::addr_of(&(*socket_data)); + let socket_data_ptr: *TcpSocketData = &*socket_data; // get an unsafe representation of our stream_handle_ptr that // we can send into the interact cb to be handled in libuv.. debug!("stream_handle_ptr outside interact %?", @@ -187,8 +187,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, 0i32 => { debug!("tcp_init successful"); debug!("dealing w/ ipv4 connection.."); - let connect_req_ptr = - ptr::addr_of(&((*socket_data_ptr).connect_req)); + let connect_req_ptr: *uv::ll::uv_connect_t = + &(*socket_data_ptr).connect_req; let addr_str = ip::format_addr(&input_ip); let connect_result = match input_ip { ip::Ipv4(ref addr) => { @@ -205,7 +205,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(&in_addr), + &in_addr, tcp_connect_on_connect_cb) } ip::Ipv6(ref addr) => { @@ -215,7 +215,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect6( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(&in_addr), + &in_addr, tcp_connect_on_connect_cb) } }; @@ -303,9 +303,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, * `TcpErrData` value as the `Err` variant */ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8]) - -> result::Result<(), TcpErrData> -{ - let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<(), TcpErrData> { + let socket_data_ptr: *TcpSocketData = &*sock.socket_data; write_common_impl(socket_data_ptr, raw_write_data) } @@ -343,7 +342,7 @@ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8]) pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) -> future::Future> { - let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); + let socket_data_ptr: *TcpSocketData = &*sock.socket_data; do future_spawn { let data_copy = copy(raw_write_data); write_common_impl(socket_data_ptr, data_copy) @@ -366,9 +365,10 @@ pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) * `TcpErrData` record */ pub fn read_start(sock: &TcpSocket) - -> result::Result<@Port< - result::Result<~[u8], TcpErrData>>, TcpErrData> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<@Port>, + TcpErrData> { + let socket_data: *TcpSocketData = &*sock.socket_data; read_start_common_impl(socket_data) } @@ -380,7 +380,7 @@ pub fn read_start(sock: &TcpSocket) * * `sock` - a `net::tcp::TcpSocket` that you wish to stop reading on */ pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> { - let socket_data = ptr::addr_of(&(*sock.socket_data)); + let socket_data: *TcpSocketData = &*sock.socket_data; read_stop_common_impl(socket_data) } @@ -400,8 +400,8 @@ pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> { * read attempt. Pass `0u` to wait indefinitely */ pub fn read(sock: &TcpSocket, timeout_msecs: uint) - -> result::Result<~[u8],TcpErrData> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<~[u8],TcpErrData> { + let socket_data: *TcpSocketData = &*sock.socket_data; read_common_impl(socket_data, timeout_msecs) } @@ -435,8 +435,8 @@ pub fn read(sock: &TcpSocket, timeout_msecs: uint) * read attempt. Pass `0u` to wait indefinitely */ fn read_future(sock: &TcpSocket, timeout_msecs: uint) - -> future::Future> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> future::Future> { + let socket_data: *TcpSocketData = &*sock.socket_data; do future_spawn { read_common_impl(socket_data, timeout_msecs) } @@ -534,8 +534,8 @@ pub fn accept(new_conn: TcpNewConnection) ipv6: (*server_data_ptr).ipv6, iotask : iotask.clone() }; - let client_socket_data_ptr = ptr::addr_of( - &(*client_socket_data)); + let client_socket_data_ptr: *TcpSocketData = + &*client_socket_data; let client_stream_handle_ptr = (*client_socket_data_ptr).stream_handle_ptr; @@ -661,7 +661,7 @@ fn listen_common(host_ip: ip::IpAddr, let (kill_po, kill_ch) = stream::>(); let kill_ch = SharedChan::new(kill_ch); let server_stream = uv::ll::tcp_t(); - let server_stream_ptr = ptr::addr_of(&server_stream); + let server_stream_ptr: *uv::ll::uv_tcp_t = &server_stream; let server_data: TcpListenFcData = TcpListenFcData { server_stream_ptr: server_stream_ptr, stream_closed_ch: stream_closed_ch, @@ -674,7 +674,7 @@ fn listen_common(host_ip: ip::IpAddr, }, mut active: true }; - let server_data_ptr = ptr::addr_of(&server_data); + let server_data_ptr: *TcpListenFcData = &server_data; let (setup_po, setup_ch) = stream(); @@ -699,16 +699,14 @@ fn listen_common(host_ip: ip::IpAddr, let in_addr = uv::ll::ip4_addr( addr_str, port as int); - uv::ll::tcp_bind(server_stream_ptr, - ptr::addr_of(&in_addr)) + uv::ll::tcp_bind(server_stream_ptr, &in_addr) } ip::Ipv6(ref addr) => { debug!("addr: %?", addr); let in_addr = uv::ll::ip6_addr( addr_str, port as int); - uv::ll::tcp_bind6(server_stream_ptr, - ptr::addr_of(&in_addr)) + uv::ll::tcp_bind6(server_stream_ptr, &in_addr) } }; match bind_result { @@ -856,12 +854,12 @@ pub impl TcpSocket { if self.socket_data.ipv6 { let addr = uv::ll::ip6_addr("", 0); uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr, - ptr::addr_of(&addr)); + &addr); ip::Ipv6(addr) } else { let addr = uv::ll::ip4_addr("", 0); uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr, - ptr::addr_of(&addr)); + &addr); ip::Ipv4(addr) } } @@ -973,13 +971,12 @@ impl io::Reader for TcpSocketBuf { impl io::Writer for TcpSocketBuf { pub fn write(&self, data: &const [u8]) { unsafe { - let socket_data_ptr = - ptr::addr_of(&(*((*(self.data)).sock).socket_data)); + let socket_data_ptr: *TcpSocketData = + &(*((*(self.data)).sock).socket_data); let w_result = write_common_impl(socket_data_ptr, - vec::slice(data, - 0, - vec::len(data) - ).to_vec()); + vec::slice(data, + 0, + data.len()).to_vec()); if w_result.is_err() { let err_data = w_result.get_err(); debug!( @@ -1012,7 +1009,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) { let close_data = TcpSocketCloseData { closed_ch: closed_ch }; - let close_data_ptr = ptr::addr_of(&close_data); + let close_data_ptr: *TcpSocketCloseData = &close_data; let stream_handle_ptr = (*socket_data).stream_handle_ptr; do iotask::interact(&(*socket_data).iotask) |loop_ptr| { unsafe { @@ -1150,19 +1147,21 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData, raw_write_data: ~[u8]) -> result::Result<(), TcpErrData> { unsafe { - let write_req_ptr = ptr::addr_of(&((*socket_data_ptr).write_req)); + let write_req_ptr: *uv::ll::uv_write_t = + &(*socket_data_ptr).write_req; let stream_handle_ptr = (*socket_data_ptr).stream_handle_ptr; - let write_buf_vec = ~[ uv::ll::buf_init( - vec::raw::to_ptr(raw_write_data), - vec::len(raw_write_data)) ]; - let write_buf_vec_ptr = ptr::addr_of(&write_buf_vec); + let write_buf_vec = ~[ + uv::ll::buf_init(vec::raw::to_ptr(raw_write_data), + raw_write_data.len()) + ]; + let write_buf_vec_ptr: *~[uv::ll::uv_buf_t] = &write_buf_vec; let (result_po, result_ch) = stream::(); let result_ch = SharedChan::new(result_ch); let write_data = WriteReqData { result_ch: result_ch }; - let write_data_ptr = ptr::addr_of(&write_data); + let write_data_ptr: *WriteReqData = &write_data; do iotask::interact(&(*socket_data_ptr).iotask) |loop_ptr| { unsafe { debug!("in interact cb for tcp::write %?", diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 60f25c2a270b2..47af3576c9062 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -11,7 +11,6 @@ //! A priority queue implemented with a binary heap use core::old_iter::BaseIter; -use core::ptr::addr_of; #[abi = "rust-intrinsic"] extern "rust-intrinsic" mod rusti { @@ -151,7 +150,7 @@ pub impl PriorityQueue { priv fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { - let new = *addr_of(&self.data[pos]); + let new = *ptr::to_unsafe_ptr(&self.data[pos]); while pos > start { let parent = (pos - 1) >> 1; @@ -171,7 +170,7 @@ pub impl PriorityQueue { priv fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; - let new = *addr_of(&self.data[pos]); + let new = *ptr::to_unsafe_ptr(&self.data[pos]); let mut child = 2 * pos + 1; while child < end { diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 58e5352890fad..e86ec79318880 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -828,18 +828,22 @@ mod tests { let m = ~Mutex(); let m2 = m.clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(&(*sharedstate)); - do task::spawn || { - let sharedstate: &mut int = - unsafe { cast::transmute(ptr) }; - access_shared(sharedstate, m2, 10); - c.send(()); + { + let ptr: *int = &*sharedstate; + do task::spawn || { + let sharedstate: &mut int = + unsafe { cast::transmute(ptr) }; + access_shared(sharedstate, m2, 10); + c.send(()); + } } - access_shared(sharedstate, m, 10); - let _ = p.recv(); + { + access_shared(sharedstate, m, 10); + let _ = p.recv(); - assert!(*sharedstate == 20); + assert!(*sharedstate == 20); + } fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) { for n.times { @@ -1106,17 +1110,21 @@ mod tests { let (p,c) = comm::stream(); let x2 = (*x).clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(&(*sharedstate)); - do task::spawn || { - let sharedstate: &mut int = - unsafe { cast::transmute(ptr) }; - access_shared(sharedstate, &x2, mode1, 10); - c.send(()); + { + let ptr: *int = &*sharedstate; + do task::spawn || { + let sharedstate: &mut int = + unsafe { cast::transmute(ptr) }; + access_shared(sharedstate, &x2, mode1, 10); + c.send(()); + } } - access_shared(sharedstate, x, mode2, 10); - let _ = p.recv(); + { + access_shared(sharedstate, x, mode2, 10); + let _ = p.recv(); - assert!(*sharedstate == 20); + assert!(*sharedstate == 20); + } fn access_shared(sharedstate: &mut int, x: &RWlock, mode: RWlockMode, n: uint) { diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 69e01d4e4dbdd..b19b2f2889e71 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -42,7 +42,7 @@ pub fn delayed_send(iotask: &IoTask, let (timer_done_po, timer_done_ch) = stream::<()>(); let timer_done_ch = SharedChan::new(timer_done_ch); let timer = uv::ll::timer_t(); - let timer_ptr = ptr::addr_of(&timer); + let timer_ptr: *uv::ll::uv_timer_t = &timer; do iotask::interact(iotask) |loop_ptr| { unsafe { let init_result = uv::ll::timer_init(loop_ptr, timer_ptr); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 2ab5ce8698c25..e49cee434f81f 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -162,7 +162,7 @@ mod test { debug!("EXIT_CH_PTR newly created exit_ch_ptr: %?", exit_ch_ptr); let timer_handle = ll::timer_t(); - let timer_ptr = ptr::addr_of(&timer_handle); + let timer_ptr: *ll::uv_timer_t = &timer_handle; do iotask::interact(iotask) |loop_ptr| { unsafe { debug!(~"user code inside interact loop!!!"); diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 309ae32dc59af..e19010e8552a2 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -17,10 +17,9 @@ use ll = uv_ll; +use core::comm::{stream, Port, Chan, SharedChan}; use core::libc::c_void; use core::libc; -use core::comm::{stream, Port, Chan, SharedChan}; -use core::ptr::addr_of; /// Used to abstract-away direct interaction with a libuv loop. pub struct IoTask { @@ -106,7 +105,7 @@ fn run_loop(iotask_ch: &Chan) { // set up the special async handle we'll use to allow multi-task // communication with this loop let async = ll::async_t(); - let async_handle = addr_of(&async); + let async_handle: *ll::uv_async_t = &async; // associate the async handle with the loop ll::async_init(loop_ptr, async_handle, wake_up_cb); @@ -118,11 +117,11 @@ fn run_loop(iotask_ch: &Chan) { async_handle: async_handle, msg_po: msg_po }; - ll::set_data_for_uv_handle(async_handle, addr_of(&data)); + ll::set_data_for_uv_handle(async_handle, &data); // Send out a handle through which folks can talk to us // while we dwell in the I/O loop - let iotask = IoTask{ + let iotask = IoTask { async_handle: async_handle, op_chan: SharedChan::new(msg_ch) }; @@ -223,7 +222,7 @@ struct AhData { #[cfg(test)] fn impl_uv_iotask_async(iotask: &IoTask) { let async_handle = ll::async_t(); - let ah_ptr = ptr::addr_of(&async_handle); + let ah_ptr: *ll::uv_async_t = &async_handle; let (exit_po, exit_ch) = stream::<()>(); let ah_data = AhData { iotask: iotask.clone(), diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index fb40596b888ef..8d7a97e2e483c 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1021,19 +1021,17 @@ pub unsafe fn async_send(async_handle: *uv_async_t) { } pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { let out_buf = uv_buf_t { base: ptr::null(), len: 0 as libc::size_t }; - let out_buf_ptr = ptr::addr_of(&out_buf); + let out_buf_ptr: *uv_buf_t = &out_buf; rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t); return out_buf; } -pub unsafe fn ip4_addr(ip: &str, port: int) --> sockaddr_in { +pub unsafe fn ip4_addr(ip: &str, port: int) -> sockaddr_in { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip4_addr(ip_buf as *u8, port as libc::c_int) } } -pub unsafe fn ip6_addr(ip: &str, port: int) --> sockaddr_in6 { +pub unsafe fn ip6_addr(ip: &str, port: int) -> sockaddr_in6 { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip6_addr(ip_buf as *u8, port as libc::c_int) @@ -1183,7 +1181,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) { pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr: *uv_err_t = &err; let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); return fmt!("LIBUV ERROR: name: %s msg: %s", @@ -1192,7 +1190,7 @@ pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { pub unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr: *uv_err_t = &err; let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); uv_err_data { err_name: err_name, err_msg: err_msg } @@ -1347,9 +1345,9 @@ mod test { unsafe { let test_loop = loop_new(); let tcp_handle = tcp_t(); - let tcp_handle_ptr = ptr::addr_of(&tcp_handle); + let tcp_handle_ptr: *uv_tcp_t = &tcp_handle; let connect_handle = connect_t(); - let connect_req_ptr = ptr::addr_of(&connect_handle); + let connect_req_ptr: *uv_connect_t = &connect_handle; // this is the persistent payload of data that we // need to pass around to get this example to work. @@ -1365,43 +1363,42 @@ mod test { // this is the enclosing record, we'll pass a ptr to // this to C.. let write_handle = write_t(); - let write_handle_ptr = ptr::addr_of(&write_handle); + let write_handle_ptr: *uv_write_t = &write_handle; debug!("tcp req: tcp stream: %d write_handle: %d", tcp_handle_ptr as int, write_handle_ptr as int); let client_data = request_wrapper { write_req: write_handle_ptr, - req_buf: ptr::addr_of(&req_msg), + req_buf: &req_msg, read_chan: client_chan }; - let tcp_init_result = tcp_init( - test_loop as *libc::c_void, tcp_handle_ptr); - if (tcp_init_result == 0i32) { + let tcp_init_result = tcp_init(test_loop as *libc::c_void, + tcp_handle_ptr); + if (tcp_init_result == 0) { debug!(~"sucessful tcp_init_result"); debug!(~"building addr..."); let addr = ip4_addr(ip, port); // FIXME ref #2064 - let addr_ptr = ptr::addr_of(&addr); + let addr_ptr: *sockaddr_in = &addr; debug!("after build addr in rust. port: %u", - addr.sin_port as uint); + addr.sin_port as uint); // this should set up the connection request.. debug!("b4 call tcp_connect connect cb: %u ", - on_connect_cb as uint); - let tcp_connect_result = tcp_connect( - connect_req_ptr, tcp_handle_ptr, - addr_ptr, on_connect_cb); - if (tcp_connect_result == 0i32) { + on_connect_cb as uint); + let tcp_connect_result = tcp_connect(connect_req_ptr, + tcp_handle_ptr, + addr_ptr, + on_connect_cb); + if (tcp_connect_result == 0) { // not set the data on the connect_req // until its initialized - set_data_for_req( - connect_req_ptr as *libc::c_void, - ptr::addr_of(&client_data) as *libc::c_void); - set_data_for_uv_handle( - tcp_handle_ptr as *libc::c_void, - ptr::addr_of(&client_data) as *libc::c_void); + set_data_for_req(connect_req_ptr as *libc::c_void, + &client_data); + set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void, + &client_data); debug!(~"before run tcp req loop"); run(test_loop); debug!(~"after run tcp req loop"); @@ -1607,37 +1604,37 @@ mod test { unsafe { let test_loop = loop_new(); let tcp_server = tcp_t(); - let tcp_server_ptr = ptr::addr_of(&tcp_server); + let tcp_server_ptr: *uv_tcp_t = &tcp_server; let tcp_client = tcp_t(); - let tcp_client_ptr = ptr::addr_of(&tcp_client); + let tcp_client_ptr: *uv_tcp_t = &tcp_client; let server_write_req = write_t(); - let server_write_req_ptr = ptr::addr_of(&server_write_req); + let server_write_req_ptr: *uv_write_t = &server_write_req; let resp_str_bytes = str::to_bytes(server_resp_msg); let resp_msg_ptr: *u8 = vec::raw::to_ptr(resp_str_bytes); debug!("resp_msg ptr: %u", resp_msg_ptr as uint); let resp_msg = ~[ - buf_init(resp_msg_ptr, vec::len(resp_str_bytes)) + buf_init(resp_msg_ptr, resp_str_bytes.len()) ]; let continue_async_handle = async_t(); - let continue_async_handle_ptr = - ptr::addr_of(&continue_async_handle); + let continue_async_handle_ptr: *uv_async_t = + &continue_async_handle; let async_data = async_handle_data { continue_chan: continue_chan }; - let async_data_ptr = ptr::addr_of(&async_data); + let async_data_ptr: *async_handle_data = &async_data; let server_data = tcp_server_data { client: tcp_client_ptr, server: tcp_server_ptr, server_kill_msg: kill_server_msg, - server_resp_buf: ptr::addr_of(&resp_msg), + server_resp_buf: &resp_msg, server_chan: server_chan, server_write_req: server_write_req_ptr }; - let server_data_ptr = ptr::addr_of(&server_data); + let server_data_ptr: *tcp_server_data = &server_data; set_data_for_uv_handle(tcp_server_ptr as *libc::c_void, server_data_ptr as *libc::c_void); @@ -1647,11 +1644,10 @@ mod test { if (tcp_init_result == 0i32) { let server_addr = ip4_addr(server_ip, server_port); // FIXME ref #2064 - let server_addr_ptr = ptr::addr_of(&server_addr); + let server_addr_ptr: *sockaddr_in = &server_addr; // uv_tcp_bind() - let bind_result = tcp_bind(tcp_server_ptr, - server_addr_ptr); + let bind_result = tcp_bind(tcp_server_ptr, server_addr_ptr); if (bind_result == 0i32) { debug!(~"successful uv_tcp_bind, listening"); diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index ae09b9b902657..bb4a9e97ea1f4 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -16,10 +16,13 @@ use serialize::{Encoder, Encodable, Decoder, Decodable}; use sort; use core::cell::Cell; -use core::comm::{oneshot, PortOne, send_one}; +use core::cmp; +use core::comm::{ChanOne, PortOne, oneshot, send_one}; +use core::either::{Either, Left, Right}; +use core::hashmap::HashMap; +use core::io; use core::pipes::recv; use core::run; -use core::hashmap::HashMap; use core::to_bytes; /** @@ -340,13 +343,13 @@ impl TPrep for Prep { } _ => { - let (chan, port) = oneshot::init(); + let (port, chan) = oneshot(); let mut blk = None; blk <-> bo; let blk = blk.unwrap(); let chan = Cell(chan); - do task::spawn || { + do task::spawn { let exe = Exec { discovered_inputs: WorkMap::new(), discovered_outputs: WorkMap::new(), @@ -383,7 +386,7 @@ fn unwrap fail!(), Some(Left(v)) => v, Some(Right(port)) => { - let (exe, v) = match recv(port) { + let (exe, v) = match recv(port.unwrap()) { oneshot::send(data) => data }; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4137b3b8aa1fb..ba6fe1cda4f31 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -198,7 +198,7 @@ pub enum def { def_mod(def_id), def_foreign_mod(def_id), def_const(def_id), - def_arg(node_id, mode, bool /* is_mutbl */), + def_arg(node_id, bool /* is_mutbl */), def_local(node_id, bool /* is_mutbl */), def_variant(def_id /* enum */, def_id /* variant */), def_ty(def_id), @@ -417,43 +417,6 @@ pub enum unop { neg } -// Generally, after typeck you can get the inferred value -// using ty::resolved_T(...). -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum inferable { - expl(T), - infer(node_id) -} - -impl to_bytes::IterBytes for inferable { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - match *self { - expl(ref t) => - to_bytes::iter_bytes_2(&0u8, t, lsb0, f), - - infer(ref n) => - to_bytes::iter_bytes_2(&1u8, n, lsb0, f), - } - } -} - -// "resolved" mode: the real modes. -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum rmode { by_ref, by_copy } - -impl to_bytes::IterBytes for rmode { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - (*self as u8).iter_bytes(lsb0, f) - } -} - -// inferable mode. -pub type mode = inferable; - pub type stmt = spanned; #[auto_encode] @@ -941,7 +904,6 @@ pub struct inline_asm { #[auto_decode] #[deriving(Eq)] pub struct arg { - mode: mode, is_mutbl: bool, ty: @Ty, pat: @pat, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c28d369e7f8ad..148b713a4f58f 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -58,7 +58,7 @@ pub fn def_id_of_def(d: def) -> def_id { def_use(id) | def_struct(id) | def_trait(id) => { id } - def_arg(id, _, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) + def_arg(id, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) | def_upvar(id, _, _, _) | def_binding(id, _) | def_region(id) | def_typaram_binder(id) | def_label(id) => { local_def(id) diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 534027bd2958b..dfebf6f786a28 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -52,7 +52,10 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) let mut dialect = ast::asm_att; let mut state = Asm; - loop outer: { + + // Not using labeled break to get us through one round of bootstrapping. + let mut continue = true; + while continue { match state { Asm => { asm = expr_to_str(cx, p.parse_expr(), @@ -139,20 +142,30 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) p.bump(); match next_state(state) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } } } else if *p.token == token::MOD_SEP { p.bump(); let s = match next_state(state) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } }; match next_state(s) { Some(x) => x, - None => break outer + None => { + continue = false; + break + } } } else if *p.token == token::EOF { - break outer; + continue = false; + break; } else { state }; diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0d451c66edb2b..2ceb6f0c4bb75 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -215,7 +215,50 @@ pub fn expand_auto_decode( } } -priv impl @ext_ctxt { +trait ExtCtxtMethods { + fn bind_path(&self, + span: span, + ident: ast::ident, + path: @ast::Path, + bounds: @OptVec) + -> ast::TyParam; + fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; + fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Path; + fn path_tps_global(&self, + span: span, + strs: ~[ast::ident], + tps: ~[@ast::Ty]) + -> @ast::Path; + fn ty_path(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Ty; + fn binder_pat(&self, span: span, nm: ast::ident) -> @ast::pat; + fn stmt(&self, expr: @ast::expr) -> @ast::stmt; + fn lit_str(&self, span: span, s: @~str) -> @ast::expr; + fn lit_uint(&self, span: span, i: uint) -> @ast::expr; + fn lambda(&self, blk: ast::blk) -> @ast::expr; + fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk; + fn expr_blk(&self, expr: @ast::expr) -> ast::blk; + fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_var(&self, span: span, var: ~str) -> @ast::expr; + fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) + -> @ast::expr; + fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) + -> @ast::expr; + fn expr_method_call(&self, + span: span, + expr: @ast::expr, + ident: ast::ident, + args: ~[@ast::expr]) + -> @ast::expr; + fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr; + fn lambda_stmts(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr; +} + +impl ExtCtxtMethods for @ext_ctxt { fn bind_path( &self, _span: span, @@ -608,7 +651,6 @@ fn mk_ser_method( }; let ser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty_s, pat: @ast::pat { @@ -670,20 +712,22 @@ fn mk_deser_method( span: span, }; - let deser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), - is_mutbl: false, - ty: ty_d, - pat: @ast::pat { + let deser_inputs = ~[ + ast::arg { + is_mutbl: false, + ty: ty_d, + pat: @ast::pat { + id: cx.next_id(), + node: ast::pat_ident(ast::bind_by_copy, + ast_util::ident_to_path(span, + cx.ident_of( + ~"__d")), + None), + span: span, + }, id: cx.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - ast_util::ident_to_path(span, cx.ident_of(~"__d")), - None), - span: span, - }, - id: cx.next_id(), - }]; + } + ]; let deser_decl = ast::fn_decl { inputs: deser_inputs, @@ -1120,7 +1164,6 @@ fn mk_enum_deser_body( ast::expr_fn_block( ast::fn_decl { inputs: ~[ast::arg { - mode: ast::infer(ext_cx.next_id()), is_mutbl: false, ty: @ast::Ty { id: ext_cx.next_id(), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c4c2fed778f4f..4c876669f471d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -419,7 +419,6 @@ pub fn mk_arg(cx: @ext_ctxt, -> ast::arg { let arg_pat = mk_pat_ident(cx, span, ident); ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty, pat: arg_pat, diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index ede3711b052dc..deaf1b1c754a0 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -196,7 +196,6 @@ impl ext_ctxt_ast_builder for @ext_ctxt { fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { ast::arg { - mode: ast::infer(self.next_id()), is_mutbl: false, ty: ty, pat: @ast::pat { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index e6f5d3608afc2..3311c61de8b64 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -75,10 +75,10 @@ impl gen_send for message { body += ~"let b = pipe.reuse_buffer();\n"; body += fmt!("let %s = ::core::pipes::SendPacketBuffered(\ - ::ptr::addr_of(&(b.buffer.data.%s)));\n", + &(b.buffer.data.%s));\n", sp, next.name); body += fmt!("let %s = ::core::pipes::RecvPacketBuffered(\ - ::ptr::addr_of(&(b.buffer.data.%s)));\n", + &(b.buffer.data.%s));\n", rp, next.name); } else { @@ -365,9 +365,9 @@ impl gen_init for protocol { |s| ext_cx.parse_stmt( fmt!("data.%s.set_buffer(buffer)", s.name))), - ext_cx.parse_expr( - fmt!("::ptr::addr_of(&(data.%s))", - self.states[0].name)))); + ext_cx.parse_expr(fmt!( + "::core::ptr::to_unsafe_ptr(&(data.%s))", + self.states[0].name)))); quote_expr!({ let buffer = $buffer; diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index da6d0e8bf7be6..d82608846ab98 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -105,7 +105,6 @@ fn fold_attribute_(at: attribute, fld: @ast_fold) -> attribute { //used in noop_fold_foreign_item and noop_fold_fn_decl fn fold_arg_(a: arg, fld: @ast_fold) -> arg { ast::arg { - mode: a.mode, is_mutbl: a.is_mutbl, ty: fld.fold_ty(a.ty), pat: fld.fold_pat(a.pat), @@ -868,7 +867,11 @@ impl ast_fold for AstFoldFns { } } -pub impl @ast_fold { +pub trait AstFoldExtensions { + fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute]; +} + +impl AstFoldExtensions for @ast_fold { fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute] { attrs.map(|x| fold_attribute_(*x, *self)) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d27d788e23a95..7e7931bbb606b 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -569,9 +569,8 @@ mod test { let parser = string_to_parser(@~"b : int"); assert_eq!(parser.parse_arg_general(true), ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(4,4), // this is bizarre... // check this in the original parser? @@ -579,9 +578,9 @@ mod test { idents:~[mk_ident(105)], rp: None, types: ~[]}, - 3), + 2), span:sp(4,7)}, - pat: @ast::pat{id:2, + pat: @ast::pat{id:1, node: ast::pat_ident(ast::bind_by_copy, @ast::Path{ span:sp(0,1), @@ -592,7 +591,7 @@ mod test { None // no idea ), span: sp(0,3)}, // really? - id: 5 // fixme + id: 4 // fixme }) } @@ -604,21 +603,20 @@ mod test { Some( @ast::item{ident:mk_ident(100), attrs:~[], - id: 11, // fixme + id: 10, // fixme node: ast::item_fn(ast::fn_decl{ inputs: ~[ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(10,13), global:false, idents:~[mk_ident(106)], rp: None, types: ~[]}, - 3), + 2), span:sp(10,13)}, - pat: @ast::pat{id:2, // fixme + pat: @ast::pat{id:1, // fixme node: ast::pat_ident( ast::bind_by_copy, @ast::Path{ @@ -630,9 +628,9 @@ mod test { None // no idea ), span: sp(6,9)}, // bleah. - id: 5 // fixme + id: 4 // fixme }], - output: @ast::Ty{id:6, // fixme + output: @ast::Ty{id:5, // fixme node: ast::ty_nil, span:sp(15,15)}, // not sure cf: ast::return_val @@ -649,8 +647,8 @@ mod test { view_items: ~[], stmts: ~[@spanned{ node: ast::stmt_semi(@ast::expr{ - id: 7, - callee_id: 8, + id: 6, + callee_id: 7, node: ast::expr_path( @ast::Path{ span:sp(17,18), @@ -659,10 +657,10 @@ mod test { rp:None, types: ~[]}), span: sp(17,18)}, - 9), // fixme + 8), // fixme span: sp(17,18)}], expr: None, - id: 10, // fixme + id: 9, // fixme rules: ast::default_blk // no idea }}), vis: ast::inherited, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 30275436c065f..50bdfb2f55726 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,10 +17,10 @@ use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; -use ast::{blk_check_mode, box, by_copy, by_ref}; +use ast::{blk_check_mode, box}; use ast::{crate, crate_cfg, decl, decl_item}; use ast::{decl_local, default_blk, deref, quot, enum_def}; -use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again}; +use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; use ast::{expr_field, expr_fn_block, expr_if, expr_index}; @@ -32,13 +32,13 @@ use ast::{expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod}; -use ast::{ident, impure_fn, infer, inherited, item, item_, item_const}; +use ast::{ident, impure_fn, inherited, item, item_, item_const}; use ast::{item_const, item_enum, item_fn, item_foreign_mod, item_impl}; use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int}; use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const}; use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; -use ast::{match_seq, match_tok, method, mode, mt, mul, mutability}; +use ast::{match_seq, match_tok, method, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct}; use ast::{pat_tup, pat_uniq, pat_wild, private}; @@ -348,6 +348,20 @@ pub impl Parser { self.token_is_keyword(&~"fn", tok) } + fn token_is_lifetime(&self, tok: &token::Token) -> bool { + match *tok { + token::LIFETIME(*) => true, + _ => false, + } + } + + fn get_lifetime(&self, tok: &token::Token) -> ast::ident { + match *tok { + token::LIFETIME(ref ident) => copy *ident, + _ => self.bug(~"not a lifetime"), + } + } + // parse a ty_bare_fun type: fn parse_ty_bare_fn(&self) -> ty_ { @@ -765,22 +779,22 @@ pub impl Parser { } // parse an optional mode. - fn parse_arg_mode(&self) -> mode { + // XXX: Remove after snapshot. + fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); - expl(by_copy) } else if self.eat(&token::ANDAND) { - expl(by_ref) + // Ignore. } else if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) { // ++ mode is obsolete, but we need a snapshot // to stop parsing it. - expl(by_copy) + // Ignore. } else { - expl(by_copy) + // Ignore. } } else { - infer(self.get_id()) + // Ignore. } } @@ -810,16 +824,14 @@ pub impl Parser { // This version of parse arg doesn't necessarily require // identifier names. fn parse_arg_general(&self, require_name: bool) -> arg { - let m; let mut is_mutbl = false; let pat = if require_name || self.is_named_argument() { - m = self.parse_arg_mode(); + self.parse_arg_mode(); is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); self.expect(&token::COLON); pat } else { - m = infer(self.get_id()); ast_util::ident_to_pat(self.get_id(), *self.last_span, special_idents::invalid) @@ -827,8 +839,12 @@ pub impl Parser { let t = self.parse_ty(false); - ast::arg { mode: m, is_mutbl: is_mutbl, - ty: t, pat: pat, id: self.get_id() } + ast::arg { + is_mutbl: is_mutbl, + ty: t, + pat: pat, + id: self.get_id(), + } } // parse a single function argument @@ -838,7 +854,7 @@ pub impl Parser { // parse an argument in a lambda header e.g. |arg, arg| fn parse_fn_block_arg(&self) -> arg_or_capture_item { - let m = self.parse_arg_mode(); + self.parse_arg_mode(); let is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); let t = if self.eat(&token::COLON) { @@ -851,7 +867,6 @@ pub impl Parser { } }; either::Left(ast::arg { - mode: m, is_mutbl: is_mutbl, ty: t, pat: pat, @@ -1227,8 +1242,14 @@ pub impl Parser { expr_do_body); } else if self.eat_keyword(&~"while") { return self.parse_while_expr(); + } else if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + self.expect(&token::COLON); + self.expect_keyword(&~"loop"); + return self.parse_loop_expr(Some(lifetime)); } else if self.eat_keyword(&~"loop") { - return self.parse_loop_expr(); + return self.parse_loop_expr(None); } else if self.eat_keyword(&~"match") { return self.parse_match_expr(); } else if self.eat_keyword(&~"unsafe") { @@ -1289,8 +1310,10 @@ pub impl Parser { } else { ex = expr_ret(None); } } else if self.eat_keyword(&~"break") { // BREAK expression - if is_ident(&*self.token) { - ex = expr_break(Some(self.parse_ident())); + if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + ex = expr_break(Some(lifetime)); } else { ex = expr_break(None); } @@ -1994,37 +2017,32 @@ pub impl Parser { return self.mk_expr(lo, hi, expr_while(cond, body)); } - fn parse_loop_expr(&self) -> @expr { + fn parse_loop_expr(&self, opt_ident: Option) -> @expr { // loop headers look like 'loop {' or 'loop unsafe {' let is_loop_header = *self.token == token::LBRACE || (is_ident(&*self.token) && self.look_ahead(1) == token::LBRACE); - // labeled loop headers look like 'loop foo: {' - let is_labeled_loop_header = - is_ident(&*self.token) - && !self.is_any_keyword(© *self.token) - && self.look_ahead(1) == token::COLON; - if is_loop_header || is_labeled_loop_header { + if is_loop_header { // This is a loop body - let opt_ident; - if is_labeled_loop_header { - opt_ident = Some(self.parse_ident()); - self.expect(&token::COLON); - } else { - opt_ident = None; - } - let lo = self.last_span.lo; let body = self.parse_block(); let hi = body.span.hi; return self.mk_expr(lo, hi, expr_loop(body, opt_ident)); } else { // This is a 'continue' expression + if opt_ident.is_some() { + self.span_err(*self.last_span, + ~"a label may not be used with a `loop` \ + expression"); + } + let lo = self.span.lo; - let ex = if is_ident(&*self.token) { - expr_again(Some(self.parse_ident())) + let ex = if self.token_is_lifetime(&*self.token) { + let lifetime = self.get_lifetime(&*self.token); + self.bump(); + expr_again(Some(lifetime)) } else { expr_again(None) }; @@ -2440,18 +2458,21 @@ pub impl Parser { // used by the copy foo and ref foo patterns to give a good // error message when parsing mistakes like ref foo(a,b) - fn parse_pat_ident(&self, refutable: bool, - binding_mode: ast::binding_mode) -> ast::pat_ { + fn parse_pat_ident(&self, + refutable: bool, + binding_mode: ast::binding_mode) + -> ast::pat_ { if !is_plain_ident(&*self.token) { - self.span_fatal( - *self.last_span, - ~"expected identifier, found path"); + self.span_fatal(*self.last_span, + ~"expected identifier, found path"); } // why a path here, and not just an identifier? let name = self.parse_path_without_tps(); let sub = if self.eat(&token::AT) { Some(self.parse_pat(refutable)) - } else { None }; + } else { + None + }; // just to be friendly, if they write something like // ref Some(i) @@ -4406,10 +4427,11 @@ pub impl Parser { // text that can't be parsed as an item // - mod_items uses extern_mod_allowed = true // - block_tail_ uses extern_mod_allowed = false - fn parse_items_and_view_items(&self, first_item_attrs: ~[attribute], + fn parse_items_and_view_items(&self, + first_item_attrs: ~[attribute], mut extern_mod_allowed: bool, macros_allowed: bool) - -> ParsedItemsAndViewItems { + -> ParsedItemsAndViewItems { let mut attrs = vec::append(first_item_attrs, self.parse_outer_attributes()); // First, parse view items. @@ -4539,8 +4561,11 @@ pub impl Parser { fn parse_str(&self) -> @~str { match *self.token { - token::LIT_STR(s) => { self.bump(); self.id_to_str(s) } - _ => self.fatal(~"expected string literal") + token::LIT_STR(s) => { + self.bump(); + self.id_to_str(s) + } + _ => self.fatal(~"expected string literal") } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 918fc8051943f..d5645ada9294a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1210,12 +1210,13 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { print_block(s, blk); } ast::expr_loop(ref blk, opt_ident) => { - head(s, ~"loop"); - space(s.s); for opt_ident.each |ident| { + word(s.s, ~"'"); print_ident(s, *ident); word_space(s, ~":"); } + head(s, ~"loop"); + space(s.s); print_block(s, blk); } ast::expr_match(expr, ref arms) => { @@ -1363,12 +1364,20 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { ast::expr_break(opt_ident) => { word(s.s, ~"break"); space(s.s); - for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) } + for opt_ident.each |ident| { + word(s.s, ~"'"); + print_ident(s, *ident); + space(s.s); + } } ast::expr_again(opt_ident) => { word(s.s, ~"loop"); space(s.s); - for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) } + for opt_ident.each |ident| { + word(s.s, ~"'"); + print_ident(s, *ident); + space(s.s) + } } ast::expr_ret(result) => { word(s.s, ~"return"); @@ -1718,19 +1727,6 @@ pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -pub fn mode_to_str(m: ast::mode) -> ~str { - match m { - ast::expl(ast::by_ref) => ~"&&", - ast::expl(ast::by_copy) => ~"+", - ast::infer(_) => ~"" - } -} - -pub fn print_arg_mode(s: @ps, m: ast::mode) { - let ms = mode_to_str(m); - if ms != ~"" { word(s.s, ms); } -} - pub fn print_bounds(s: @ps, bounds: @OptVec) { if !bounds.is_empty() { word(s.s, ~":"); @@ -1879,7 +1875,6 @@ pub fn print_mt(s: @ps, mt: &ast::mt) { pub fn print_arg(s: @ps, input: ast::arg) { ibox(s, indent_unit); - print_arg_mode(s, input.mode); if input.is_mutbl { word_space(s, ~"mut"); } diff --git a/src/llvm b/src/llvm index 2e9f0d21fe321..56dd407f4f97a 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 +Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb diff --git a/src/test/auxiliary/cci_iter_lib.rs b/src/test/auxiliary/cci_iter_lib.rs index 107f0ac32a4bf..e44267373efbf 100644 --- a/src/test/auxiliary/cci_iter_lib.rs +++ b/src/test/auxiliary/cci_iter_lib.rs @@ -9,14 +9,13 @@ // except according to those terms. #[link(name="cci_iter_lib", vers="0.0")]; -#[legacy_modes]; #[inline] -pub fn iter(v: ~[T], f: &fn(T)) { +pub fn iter(v: &[T], f: &fn(&T)) { let mut i = 0u; let n = vec::len(v); while i < n { - f(v[i]); + f(&v[i]); i += 1u; } } diff --git a/src/test/auxiliary/cci_nested_lib.rs b/src/test/auxiliary/cci_nested_lib.rs index ab9dc29441a96..5701912b5f6fd 100644 --- a/src/test/auxiliary/cci_nested_lib.rs +++ b/src/test/auxiliary/cci_nested_lib.rs @@ -8,17 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[legacy_modes]; - -pub struct Entry {key: A, value: B} +pub struct Entry { + key: A, + value: B +} -pub struct alist { eq_fn: @fn(A,A) -> bool, data: @mut ~[Entry] } +pub struct alist { + eq_fn: @fn(A,A) -> bool, + data: @mut ~[Entry] +} -pub fn alist_add(lst: alist, k: A, v: B) { +pub fn alist_add(lst: &alist, k: A, v: B) { lst.data.push(Entry{key:k, value:v}); } -pub fn alist_get(lst: alist, k: A) -> B { +pub fn alist_get(lst: &alist, k: A) -> B { let eq_fn = lst.eq_fn; for lst.data.each |entry| { if eq_fn(entry.key, k) { return entry.value; } @@ -28,13 +32,13 @@ pub fn alist_get(lst: alist, k: A) -> B { #[inline] pub fn new_int_alist() -> alist { - fn eq_int(&&a: int, &&b: int) -> bool { a == b } + fn eq_int(a: int, b: int) -> bool { a == b } return alist {eq_fn: eq_int, data: @mut ~[]}; } #[inline] pub fn new_int_alist_2() -> alist { #[inline] - fn eq_int(&&a: int, &&b: int) -> bool { a == b } + fn eq_int(a: int, b: int) -> bool { a == b } return alist {eq_fn: eq_int, data: @mut ~[]}; } diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index 775955ff38c43..fa32b9603a5da 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -56,6 +56,3 @@ fn context_res() -> context_res { pub type context = arc_destruct; -pub impl context { - fn socket(&self) { } -} diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index bd3de4a1b8aba..c8555ab1286b1 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -10,7 +10,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[legacy_modes]; #[allow(deprecated_mode)]; /*! @@ -226,7 +225,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } /// A parallel version of the bfs function. -fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { +fn pbfs(graph: &arc::ARC, key: node_id) -> bfs_result { // This works by doing functional updates of a color vector. enum color { @@ -237,7 +236,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { black(node_id) }; - let graph_vec = arc::get(&graph); // FIXME #3387 requires this temp + let graph_vec = arc::get(graph); // FIXME #3387 requires this temp let mut colors = do vec::from_fn(graph_vec.len()) |i| { if i as node_id == key { gray(key) @@ -272,7 +271,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { let color_vec = arc::get(&color); // FIXME #3387 requires this temp colors = do par::mapi(*color_vec) { let colors = arc::clone(&color); - let graph = arc::clone(&graph); + let graph = arc::clone(graph); let result: ~fn(+x: uint, +y: &color) -> color = |i, c| { let colors = arc::get(&colors); let graph = arc::get(&graph); @@ -497,7 +496,7 @@ fn main() { } let start = time::precise_time_s(); - let bfs_tree = pbfs(graph_arc, *root); + let bfs_tree = pbfs(&graph_arc, *root); let stop = time::precise_time_s(); total_par += stop - start; diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index dbfd38ccf2624..3833c88465254 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -18,8 +18,6 @@ // different scalability characteristics compared to the select // version. -#[legacy_modes]; - extern mod std; use core::io::Writer; use core::io::WriterUtil; @@ -27,7 +25,7 @@ use core::io::WriterUtil; use core::comm::{Port, Chan, SharedChan}; macro_rules! move_out ( - { $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } } + { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } ) enum request { @@ -36,7 +34,7 @@ enum request { stop } -fn server(requests: Port, responses: comm::Chan) { +fn server(requests: &Port, responses: &comm::Chan) { let mut count = 0u; let mut done = false; while !done { @@ -78,7 +76,7 @@ fn run(args: &[~str]) { }; } do task::spawn || { - server(from_parent, to_parent); + server(&from_parent, &to_parent); } for vec::each(worker_results) |r| { diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 492b13f570869..c4044d45f36c8 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -14,8 +14,6 @@ // // I *think* it's the same, more or less. -#[legacy_modes]; - extern mod std; use core::io::Writer; use core::io::WriterUtil; @@ -23,7 +21,7 @@ use core::io::WriterUtil; use core::comm::{Port, PortSet, Chan, stream}; macro_rules! move_out ( - { $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } } + { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } ) enum request { @@ -32,7 +30,7 @@ enum request { stop } -fn server(requests: PortSet, responses: Chan) { +fn server(requests: &PortSet, responses: &Chan) { let mut count = 0; let mut done = false; while !done { @@ -75,7 +73,7 @@ fn run(args: &[~str]) { }; } do task::spawn || { - server(from_parent, to_parent); + server(&from_parent, &to_parent); } for vec::each(worker_results) |r| { diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 1fdc826c48109..14e955dd7bdae 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -30,7 +30,7 @@ proto! ring ( ) macro_rules! move_out ( - ($x:expr) => { unsafe { let y = *ptr::addr_of(&$x); y } } + ($x:expr) => { unsafe { let y = *ptr::to_unsafe_ptr(&$x); y } } ) fn thread_ring(i: uint, diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 64fb9652ceae0..4a6e90f411686 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -44,7 +44,7 @@ proto! pingpong_unbounded ( // This stuff should go in libcore::pipes macro_rules! move_it ( - { $x:expr } => { let t = *ptr::addr_of(&($x)); t } + { $x:expr } => { let t = *ptr::to_unsafe_ptr(&($x)); t } ) macro_rules! follow ( diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 4c8c984cd07c9..4cd7b58ce12a0 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -11,8 +11,6 @@ // xfail-pretty (extra blank line is inserted in vec::mapi call) // multi tasking k-nucleotide -#[legacy_modes]; - extern mod std; use std::sort; use core::hashmap::HashMap; @@ -105,9 +103,9 @@ fn windows_with_carry(bb: &[u8], nn: uint, return vec::slice(bb, len - (nn - 1u), len).to_vec(); } -fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>, - to_parent: comm::Chan<~str>) { - +fn make_sequence_processor(sz: uint, + from_parent: &comm::Port<~[u8]>, + to_parent: &comm::Chan<~str>) { let mut freqs: HashMap<~[u8], uint> = HashMap::new(); let mut carry: ~[u8] = ~[]; let mut total: uint = 0u; @@ -142,7 +140,7 @@ fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>, // given a FASTA file on stdin, process sequence THREE fn main() { let args = os::args(); - let rdr = if os::getenv(~"RUST_BENCH").is_some() { + let rdr = if os::getenv(~"RUST_BENCH").is_some() { // FIXME: Using this compile-time env variable is a crummy way to // get to this massive data set, but include_bin! chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) @@ -170,7 +168,7 @@ fn main() { let (from_parent, to_child) = comm::stream(); do task::spawn_with(from_parent) |from_parent| { - make_sequence_processor(sz, from_parent, to_parent_); + make_sequence_processor(sz, &from_parent, &to_parent_); }; to_child diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index f7bd779a8d89e..acb8a6bcbeed6 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -19,8 +19,6 @@ */ -#[legacy_modes]; - extern mod std; use std::{time, getopts}; @@ -32,7 +30,7 @@ use core::result; use core::result::{Ok, Err}; fn fib(n: int) -> int { - fn pfib(c: Chan, n: int) { + fn pfib(c: &Chan, n: int) { if n == 0 { c.send(0); } else if n <= 2 { @@ -40,15 +38,15 @@ fn fib(n: int) -> int { } else { let p = PortSet::new(); let ch = p.chan(); - task::spawn(|| pfib(ch, n - 1) ); + task::spawn(|| pfib(&ch, n - 1) ); let ch = p.chan(); - task::spawn(|| pfib(ch, n - 2) ); + task::spawn(|| pfib(&ch, n - 2) ); c.send(p.recv() + p.recv()); } } let (p, ch) = stream(); - let _t = task::spawn(|| pfib(ch, n) ); + let _t = task::spawn(|| pfib(&ch, n) ); p.recv() } diff --git a/src/test/compile-fail/arg-style-mismatch.rs b/src/test/compile-fail/arg-style-mismatch.rs deleted file mode 100644 index 2efc16de8307f..0000000000000 --- a/src/test/compile-fail/arg-style-mismatch.rs +++ /dev/null @@ -1,15 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mismatched types - -fn f(&&_x: int) {} -fn g(_a: &fn(+v: int)) {} -fn main() { g(f); } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index 6f3ccfd35ac21..3e9e306ed2bfc 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[legacy_modes]; - -fn takes_mut(&&x: @mut int) { } -fn takes_imm(&&x: @int) { } +fn takes_mut(x: @mut int) { } +fn takes_imm(x: @int) { } fn apply(t: T, f: &fn(T)) { f(t) diff --git a/src/test/compile-fail/issue-3096-2.rs b/src/test/compile-fail/issue-3096-2.rs index fcde73d3f4569..da13d450273ba 100644 --- a/src/test/compile-fail/issue-3096-2.rs +++ b/src/test/compile-fail/issue-3096-2.rs @@ -11,6 +11,6 @@ enum bottom { } fn main() { - let x = ptr::addr_of(&()) as *bottom; + let x = ptr::to_unsafe_ptr(&()) as *bottom; match x { } //~ ERROR non-exhaustive patterns } diff --git a/src/test/compile-fail/liveness-move-from-args.rs b/src/test/compile-fail/liveness-move-from-args.rs deleted file mode 100644 index c60848e5cc6c5..0000000000000 --- a/src/test/compile-fail/liveness-move-from-args.rs +++ /dev/null @@ -1,22 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn take(_x: ~int) { } - -fn from_by_ref_arg(&&x: ~int) { - take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode -} - -fn from_copy_arg(+x: ~int) { - take(x); -} - -fn main() { -} diff --git a/src/test/compile-fail/mode-inference-fail.rs b/src/test/compile-fail/mode-inference-fail.rs deleted file mode 100644 index 4994bb323d9c5..0000000000000 --- a/src/test/compile-fail/mode-inference-fail.rs +++ /dev/null @@ -1,23 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[legacy_modes]; - -// In this test, the mode gets inferred to ++ due to the apply_int(), -// but then we get a failure in the generic apply(). - -fn apply(f: &fn(A) -> A, a: A) -> A { f(a) } -fn apply_int(f: &fn(int) -> int, a: int) -> int { f(a) } - -fn main() { - let f = {|i| i}; - assert!(apply_int(f, 2) == 2); - assert!(apply(f, 2) == 2); //~ ERROR expected argument mode && -} diff --git a/src/test/compile-fail/mutable-arguments.rs b/src/test/compile-fail/mutable-arguments.rs deleted file mode 100644 index 39e47fb1aabdb..0000000000000 --- a/src/test/compile-fail/mutable-arguments.rs +++ /dev/null @@ -1,35 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Note: it would be nice to give fewer warnings in these cases. - -fn mutate_by_mut_ref(x: &mut uint) { - *x = 0; -} - -fn mutate_by_ref(&&x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument -} - -fn mutate_by_copy(+x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument - //~^ WARNING value assigned to `x` is never read -} - -fn mutate_by_move(+x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument - //~^ WARNING value assigned to `x` is never read -} - -fn main() { -} diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs index d8192a24652e6..b89e22582bb3a 100644 --- a/src/test/compile-fail/non-copyable-void.rs +++ b/src/test/compile-fail/non-copyable-void.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x : *~[int] = ptr::addr_of(&~[1,2,3]); + let x : *~[int] = &~[1,2,3]; let y : *libc::c_void = x as *libc::c_void; unsafe { let _z = copy *y; diff --git a/src/test/compile-fail/packed-struct-generic-transmute.rs b/src/test/compile-fail/packed-struct-generic-transmute.rs index 3ed9d00be28b1..c03261816ef31 100644 --- a/src/test/compile-fail/packed-struct-generic-transmute.rs +++ b/src/test/compile-fail/packed-struct-generic-transmute.rs @@ -13,7 +13,7 @@ // the error points to the start of the file, not the line with the // transmute -// error-pattern: reinterpret_cast called on types with different size +// error-pattern: transmute called on types with different size #[packed] struct Foo { diff --git a/src/test/compile-fail/packed-struct-transmute.rs b/src/test/compile-fail/packed-struct-transmute.rs index d2aca3c0d6b61..cad78f9e5d1f5 100644 --- a/src/test/compile-fail/packed-struct-transmute.rs +++ b/src/test/compile-fail/packed-struct-transmute.rs @@ -13,7 +13,7 @@ // the error points to the start of the file, not the line with the // transmute -// error-pattern: reinterpret_cast called on types with different size +// error-pattern: transmute called on types with different size #[packed] struct Foo { diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 7a8038bbb887a..120428e02f4cb 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[legacy_modes]; - enum ast<'self> { num(uint), add(&'self ast<'self>, &'self ast<'self>) diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index e576faa16ea81..d5d54ade4443a 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -21,7 +21,7 @@ struct r { impl Drop for r { fn finalize(&self) { unsafe { - let _v2: ~int = cast::reinterpret_cast(&self.v); + let _v2: ~int = cast::transmute(self.v); } } } @@ -35,7 +35,7 @@ fn r(v: *int) -> r { fn main() { unsafe { let i1 = ~0; - let i1p = cast::reinterpret_cast(&i1); + let i1p = cast::transmute_copy(&i1); cast::forget(i1); let x = @r(i1p); failfn(); diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs index 9c7caebc2eb6e..9bfe29a5e8e4c 100644 --- a/src/test/run-pass-fulldeps/qquote.rs +++ b/src/test/run-pass-fulldeps/qquote.rs @@ -10,8 +10,6 @@ // xfail-pretty -#[legacy_modes]; - extern mod std; extern mod syntax; diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs index 8e71d8d4a6708..d9f3f10a11b03 100644 --- a/src/test/run-pass/alt-pattern-drop.rs +++ b/src/test/run-pass/alt-pattern-drop.rs @@ -25,7 +25,7 @@ fn foo(s: @int) { _ => { debug!("?"); fail!(); } } debug!(::core::sys::refcount(s)); - assert!((::core::sys::refcount(s) == count + 1u)); + assert_eq!(::core::sys::refcount(s), count + 1u); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. } @@ -39,5 +39,5 @@ pub fn main() { debug!("%u", ::core::sys::refcount(s)); let count2 = ::core::sys::refcount(s); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. - assert!(count == count2); + assert_eq!(count, count2); } diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs index e0a2d1ffa1c95..e7624c9e3b939 100644 --- a/src/test/run-pass/binops.rs +++ b/src/test/run-pass/binops.rs @@ -64,9 +64,9 @@ fn test_box() { fn test_ptr() { unsafe { - let p1: *u8 = ::core::cast::reinterpret_cast(&0); - let p2: *u8 = ::core::cast::reinterpret_cast(&0); - let p3: *u8 = ::core::cast::reinterpret_cast(&1); + let p1: *u8 = ::core::cast::transmute(0); + let p2: *u8 = ::core::cast::transmute(0); + let p3: *u8 = ::core::cast::transmute(1); assert!(p1 == p2); assert!(p1 != p3); @@ -107,8 +107,8 @@ fn test_class() { unsafe { error!("q = %x, r = %x", - (::core::cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&q))), - (::core::cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&r)))); + (::core::cast::transmute::<*p, uint>(&q)), + (::core::cast::transmute::<*p, uint>(&r))); } assert!((q == r)); r.y = 17; diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index afa312ea35e7e..d65a043bf47e9 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -14,7 +14,7 @@ fn borrow(x: &int, f: &fn(x: &int)) { fn test1(x: @~int) { do borrow(&*(*x).clone()) |p| { - let x_a = ptr::addr_of(&(**x)); + let x_a = ptr::to_unsafe_ptr(&**x); assert!((x_a as uint) != ptr::to_uint(p)); assert!(unsafe{*x_a} == *p); } diff --git a/src/test/run-pass/borrowck-preserve-box-in-discr.rs b/src/test/run-pass/borrowck-preserve-box-in-discr.rs index 7e871bc7caaec..db88646631357 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-discr.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-discr.rs @@ -17,13 +17,14 @@ pub fn main() { match x { @F {f: ref b_x} => { assert!(**b_x == 3); - assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(**b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(**b_x))); x = @F {f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(**b_x)) as uint); assert!(**b_x == 3); - assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(**b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(**b_x))); } } } diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs index a22dc6215251d..3c95054d10c93 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -23,11 +23,12 @@ pub fn main() { let mut x = @F {f: ~3}; do borrow(x.f) |b_x| { assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x))); x = @F {f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(*b_x)) as uint); assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); } } diff --git a/src/test/run-pass/borrowck-preserve-box-in-pat.rs b/src/test/run-pass/borrowck-preserve-box-in-pat.rs index f9991199c8128..ad0c5b69ba849 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-pat.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-pat.rs @@ -17,13 +17,14 @@ pub fn main() { match x { @@F{f: ref b_x} => { assert!(**b_x == 3); - assert!(ptr::addr_of(&(x.f)) == ptr::addr_of(b_x)); + assert!(ptr::to_unsafe_ptr(&(x.f)) == ptr::to_unsafe_ptr(b_x)); *x = @F {f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(**b_x)) as uint); assert!(**b_x == 3); - assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(**b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(**b_x))); } } } diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 990473256461e..cce08ab235613 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -23,11 +23,12 @@ pub fn main() { let mut x = ~@F{f: ~3}; do borrow(x.f) |b_x| { assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x))); *x = @F{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(*b_x)) as uint); assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); } } diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs index 0fe3b7947f466..104b0ae6bc551 100644 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -21,11 +21,12 @@ pub fn main() { let mut x = @3; do borrow(x) |b_x| { assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x)) == ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x)) == ptr::to_unsafe_ptr(&(*b_x))); x = @22; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(*b_x)) as uint); assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x)) != ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x))); } } diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs index 5939391413c3e..4c5b9f9bf1f82 100644 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -23,11 +23,12 @@ pub fn main() { let mut x = @F {f: ~3}; do borrow((*x).f) |b_x| { assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x))); x = @F {f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); + debug!("ptr::to_unsafe_ptr(*b_x) = %x", + ptr::to_unsafe_ptr(&(*b_x)) as uint); assert!(*b_x == 3); - assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x))); + assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); } } diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs index 7731ef8908de7..5d20990a5a93b 100644 --- a/src/test/run-pass/cap-clause-move.rs +++ b/src/test/run-pass/cap-clause-move.rs @@ -10,22 +10,22 @@ pub fn main() { let x = ~1; - let y = ptr::addr_of(&(*x)) as uint; - let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint; + let y = ptr::to_unsafe_ptr(&(*x)) as uint; + let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert!(lam_move() == y); let x = ~2; - let y = ptr::addr_of(&(*x)) as uint; - let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint; + let y = ptr::to_unsafe_ptr(&(*x)) as uint; + let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert!(lam_move() == y); let x = ~3; - let y = ptr::addr_of(&(*x)) as uint; - let snd_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint; + let y = ptr::to_unsafe_ptr(&(*x)) as uint; + let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert!(snd_move() == y); let x = ~4; - let y = ptr::addr_of(&(*x)) as uint; - let lam_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint; + let y = ptr::to_unsafe_ptr(&(*x)) as uint; + let lam_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert!(lam_move() == y); } diff --git a/src/test/run-pass/cci_iter_exe.rs b/src/test/run-pass/cci_iter_exe.rs index 5511301911089..cb713adcb28fc 100644 --- a/src/test/run-pass/cci_iter_exe.rs +++ b/src/test/run-pass/cci_iter_exe.rs @@ -11,15 +11,13 @@ // xfail-fast - check-fast doesn't understand aux-build // aux-build:cci_iter_lib.rs -#[legacy_modes]; - extern mod cci_iter_lib; pub fn main() { //let bt0 = sys::rusti::frame_address(1u32); //debug!("%?", bt0); do cci_iter_lib::iter(~[1, 2, 3]) |i| { - io::print(fmt!("%d", i)); + io::print(fmt!("%d", *i)); //assert!(bt0 == sys::rusti::frame_address(2u32)); } } diff --git a/src/test/run-pass/cci_nested_exe.rs b/src/test/run-pass/cci_nested_exe.rs index f6bfa25d94d86..847d8a4d1f90e 100644 --- a/src/test/run-pass/cci_nested_exe.rs +++ b/src/test/run-pass/cci_nested_exe.rs @@ -16,14 +16,14 @@ use cci_nested_lib::*; pub fn main() { let lst = new_int_alist(); - alist_add(lst, 22, ~"hi"); - alist_add(lst, 44, ~"ho"); - assert!(alist_get(lst, 22) == ~"hi"); - assert!(alist_get(lst, 44) == ~"ho"); + alist_add(&lst, 22, ~"hi"); + alist_add(&lst, 44, ~"ho"); + assert!(alist_get(&lst, 22) == ~"hi"); + assert!(alist_get(&lst, 44) == ~"ho"); let lst = new_int_alist_2(); - alist_add(lst, 22, ~"hi"); - alist_add(lst, 44, ~"ho"); - assert!(alist_get(lst, 22) == ~"hi"); - assert!(alist_get(lst, 44) == ~"ho"); + alist_add(&lst, 22, ~"hi"); + alist_add(&lst, 44, ~"ho"); + assert!(alist_get(&lst, 22) == ~"hi"); + assert!(alist_get(&lst, 44) == ~"ho"); } diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index ebc4668e70f40..1c0a09d52cfc8 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -9,7 +9,6 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; trait noisy { fn speak(&mut self); @@ -66,6 +65,7 @@ pub fn main() { let mut nyan = cat(0u, 2, ~"nyan"); nyan.eat(); assert!((!nyan.eat())); - for uint::range(1u, 10u) |_i| { make_speak(nyan); }; - assert!((nyan.eat())); + for uint::range(1u, 10u) |_i| { + make_speak(copy nyan); + } } diff --git a/src/test/run-pass/const-region-ptrs-noncopy.rs b/src/test/run-pass/const-region-ptrs-noncopy.rs index 960faf131e8b0..b8812649fd1c1 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -14,5 +14,5 @@ static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]); static y: &'static Pair<'static> = &Pair {a: 15, b: x}; pub fn main() { - assert!(ptr::addr_of(x) == ptr::addr_of(y.b)); + assert!(ptr::to_unsafe_ptr(x) == ptr::to_unsafe_ptr(y.b)); } diff --git a/src/test/run-pass/enum-alignment.rs b/src/test/run-pass/enum-alignment.rs index e8de422d5ce60..cf92515e01028 100644 --- a/src/test/run-pass/enum-alignment.rs +++ b/src/test/run-pass/enum-alignment.rs @@ -9,12 +9,15 @@ // except according to those terms. fn addr_of(ptr: &T) -> uint { - let ptr = ptr::addr_of(ptr); + let ptr = ptr::to_unsafe_ptr(ptr); unsafe { ptr as uint } } fn is_aligned(ptr: &T) -> bool { - (addr_of(ptr) % sys::min_align_of::()) == 0 + unsafe { + let addr: uint = ::cast::transmute(ptr); + (addr % sys::min_align_of::()) == 0 + } } pub fn main() { diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 2fa9a9c768ba4..5d26fbdd78933 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -10,7 +10,6 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; type compare = @fn(T, T) -> bool; @@ -20,7 +19,7 @@ fn test_generic(expected: T, eq: compare) { } fn test_vec() { - fn compare_vec(&&v1: @int, &&v2: @int) -> bool { return v1 == v2; } + fn compare_vec(v1: @int, v2: @int) -> bool { return v1 == v2; } test_generic::<@int>(@1, compare_vec); } diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index e4a5d49736e99..0d70bff364973 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -10,7 +10,6 @@ // xfail-fast // -*- rust -*- -#[legacy_modes]; type compare = @fn(T, T) -> bool; @@ -20,7 +19,7 @@ fn test_generic(expected: T, eq: compare) { } fn test_vec() { - fn compare_vec(&&v1: ~int, &&v2: ~int) -> bool { return v1 == v2; } + fn compare_vec(v1: ~int, v2: ~int) -> bool { return v1 == v2; } test_generic::<~int>(~1, compare_vec); } diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index 910e0b2da958d..12193037e1192 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -10,7 +10,6 @@ // xfail-fast // -*- rust -*- -#[legacy_modes]; type compare = @fn(T, T) -> bool; @@ -20,7 +19,7 @@ fn test_generic(expected: T, not_expected: T, eq: compare) { } fn test_vec() { - fn compare_box(&&v1: @int, &&v2: @int) -> bool { return v1 == v2; } + fn compare_box(v1: @int, v2: @int) -> bool { return v1 == v2; } test_generic::<@int>(@1, @2, compare_box); } diff --git a/src/test/run-pass/intrinsic-frame-address.rs b/src/test/run-pass/intrinsic-frame-address.rs index 4e00b36cbebff..70898d2db9375 100644 --- a/src/test/run-pass/intrinsic-frame-address.rs +++ b/src/test/run-pass/intrinsic-frame-address.rs @@ -9,7 +9,6 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; mod rusti { #[abi = "rust-intrinsic"] diff --git a/src/test/run-pass/issue-2214.rs b/src/test/run-pass/issue-2214.rs index d5e9e8df91ea1..d63e01ec39607 100644 --- a/src/test/run-pass/issue-2214.rs +++ b/src/test/run-pass/issue-2214.rs @@ -16,7 +16,7 @@ use core::f64::*; fn to_c_int(v: &mut int) -> &mut c_int { unsafe { - cast::reinterpret_cast(&v) + cast::transmute_copy(&v) } } diff --git a/src/test/run-pass/issue-2216.rs b/src/test/run-pass/issue-2216.rs index 0be4084b08397..98965cb6d9102 100644 --- a/src/test/run-pass/issue-2216.rs +++ b/src/test/run-pass/issue-2216.rs @@ -11,17 +11,17 @@ pub fn main() { let mut x = 0; - loop foo: { - loop bar: { - loop quux: { + 'foo: loop { + 'bar: loop { + 'quux: loop { if 1 == 2 { - break foo; + break 'foo; } else { - break bar; + break 'bar; } } - loop foo; + loop 'foo; } x = 42; break; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 816c20ba35f49..f54d3d39831f4 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -232,7 +232,7 @@ pub mod pingpong { pub fn liberate_ping(+p: ping) -> ::pipes::send_packet { unsafe { let addr : *::pipes::send_packet = match &p { - &ping(ref x) => { cast::transmute(ptr::addr_of(x)) } + &ping(ref x) => { cast::transmute(x) } }; let liberated_value = *addr; cast::forget(p); @@ -243,7 +243,7 @@ pub mod pingpong { pub fn liberate_pong(+p: pong) -> ::pipes::send_packet { unsafe { let addr : *::pipes::send_packet = match &p { - &pong(ref x) => { cast::transmute(ptr::addr_of(x)) } + &pong(ref x) => { cast::transmute(x) } }; let liberated_value = *addr; cast::forget(p); diff --git a/src/test/run-pass/labeled-break.rs b/src/test/run-pass/labeled-break.rs index b26d8f78e649b..06ca401a136e7 100644 --- a/src/test/run-pass/labeled-break.rs +++ b/src/test/run-pass/labeled-break.rs @@ -12,9 +12,9 @@ // xfail-test pub fn main() { - loop foo: { + 'foo: loop { loop { - break foo; + break 'foo; } } } diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index d6b8acd94de37..c4ce1434165e3 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -45,7 +45,7 @@ proto! bank ( ) macro_rules! move_it ( - { $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } } + { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } ) fn switch(+endp: pipes::RecvPacket, diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 7dea787e1a1ce..6d82663d19560 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -40,7 +40,7 @@ mod pingpong { do pipes::entangle_buffer(buffer) |buffer, data| { data.ping.set_buffer(buffer); data.pong.set_buffer(buffer); - ptr::addr_of(&(data.ping)) + ptr::to_unsafe_ptr(&(data.ping)) } } pub struct ping(server::pong); @@ -53,8 +53,8 @@ mod pingpong { pub fn ping(+pipe: ping) -> pong { { let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.pong))); - let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.pong))); + let s = SendPacketBuffered(&b.buffer.data.pong); + let c = RecvPacketBuffered(&b.buffer.data.pong); let message = ::pingpong::ping(s); send(pipe, message); c @@ -75,8 +75,8 @@ mod pingpong { pub fn pong(+pipe: pong) -> ping { { let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.ping))); - let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.ping))); + let s = SendPacketBuffered(&b.buffer.data.ping); + let c = RecvPacketBuffered(&b.buffer.data.ping); let message = ::pingpong::pong(s); send(pipe, message); c diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 8f3a1dd90c24c..e520d221c9935 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -642,7 +642,7 @@ struct Triple { x: int, y: int, z: int } pub fn main() { unsafe { let r = (1,2,3,true,false, Triple {x:5,y:4,z:3}, (12,)); - let p = ptr::addr_of(&r) as *c_void; + let p = ptr::to_unsafe_ptr(&r) as *c_void; let u = my_visitor(@mut Stuff {ptr1: p, ptr2: p, vals: ~[]}); diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index a74bc82569bf0..c46e41ab0eb1c 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -25,8 +25,8 @@ struct Ccx { fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> { unsafe { - return cast::reinterpret_cast( - &libc::malloc(sys::size_of::>() as libc::size_t)); + cast::transmute(libc::malloc(sys::size_of::>() + as libc::size_t)) } } @@ -38,7 +38,7 @@ fn g(fcx : &Fcx) { let bcx = Bcx { fcx: fcx }; let bcx2 = h(&bcx); unsafe { - libc::free(cast::reinterpret_cast(&bcx2)); + libc::free(cast::transmute(bcx2)); } } diff --git a/src/test/run-pass/resource-cycle.rs b/src/test/run-pass/resource-cycle.rs index 058cb4ec77e48..fdb8c2a496c6b 100644 --- a/src/test/run-pass/resource-cycle.rs +++ b/src/test/run-pass/resource-cycle.rs @@ -18,10 +18,10 @@ impl Drop for r { fn finalize(&self) { unsafe { debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)), - cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(&(self.v))), - cast::reinterpret_cast::<*int, uint>(&self.v)); - let v2: ~int = cast::reinterpret_cast(&self.v); + cast::transmute::<*r, uint>(self), + cast::transmute::<**int, uint>(&(self.v)), + cast::transmute::<*int, uint>(self.v)); + let v2: ~int = cast::transmute(self.v); } } } @@ -44,38 +44,36 @@ struct Node { pub fn main() { unsafe { let i1 = ~0; - let i1p = cast::reinterpret_cast(&i1); + let i1p = cast::transmute_copy(&i1); cast::forget(i1); let i2 = ~0; - let i2p = cast::reinterpret_cast(&i2); + let i2p = cast::transmute_copy(&i2); cast::forget(i2); let mut x1 = @mut t(Node{ next: None, r: { let rs = r(i1p); - debug!("r = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs))); + debug!("r = %x", cast::transmute::<*r, uint>(&rs)); rs } }); debug!("x1 = %x, x1.r = %x", - cast::reinterpret_cast::<@mut t, uint>(&x1), - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x1.r)))); + cast::transmute::<@mut t, uint>(x1), + cast::transmute::<*r, uint>(&x1.r)); let mut x2 = @mut t(Node{ next: None, r: { let rs = r(i2p); - debug!("r2 = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs))); + debug!("r2 = %x", cast::transmute::<*r, uint>(&rs)); rs } }); debug!("x2 = %x, x2.r = %x", - cast::reinterpret_cast::<@mut t, uint>(&x2), - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x2.r)))); + cast::transmute::<@mut t, uint>(x2), + cast::transmute::<*r, uint>(&(x2.r))); x1.next = Some(x2); x2.next = Some(x1); diff --git a/src/test/run-pass/resource-cycle2.rs b/src/test/run-pass/resource-cycle2.rs index e3b03060893a2..2a59d4d2190d1 100644 --- a/src/test/run-pass/resource-cycle2.rs +++ b/src/test/run-pass/resource-cycle2.rs @@ -23,7 +23,7 @@ struct r { impl Drop for r { fn finalize(&self) { unsafe { - let v2: ~int = cast::reinterpret_cast(&self.v.c); + let v2: ~int = cast::transmute(self.v.c); } } } @@ -44,10 +44,10 @@ struct Node { pub fn main() { unsafe { let i1 = ~0xA; - let i1p = cast::reinterpret_cast(&i1); + let i1p = cast::transmute_copy(&i1); cast::forget(i1); let i2 = ~0xA; - let i2p = cast::reinterpret_cast(&i2); + let i2p = cast::transmute_copy(&i2); cast::forget(i2); let u1 = U {a: 0xB, b: 0xC, c: i1p}; diff --git a/src/test/run-pass/resource-cycle3.rs b/src/test/run-pass/resource-cycle3.rs index c76c1c6aeb910..0d699a6e49b6c 100644 --- a/src/test/run-pass/resource-cycle3.rs +++ b/src/test/run-pass/resource-cycle3.rs @@ -27,8 +27,8 @@ struct R { impl Drop for R { fn finalize(&self) { unsafe { - let _v2: ~int = cast::reinterpret_cast(&self.v.c); - // let _v3: ~int = unsafe::reinterpret_cast(self.x); + let _v2: ~int = cast::transmute(self.v.c); + // let _v3: ~int = cast::transmute_copy(self.x); } } } @@ -38,7 +38,7 @@ fn r(v: U, w: int, _x: *int) -> R { R { v: v, w: w, - x: cast::reinterpret_cast(&0) + x: cast::transmute(0) } } } @@ -53,10 +53,10 @@ struct Node { pub fn main() { unsafe { let i1 = ~0xA; - let i1p = cast::reinterpret_cast(&i1); + let i1p = cast::transmute_copy(&i1); cast::forget(i1); let i2 = ~0xA; - let i2p = cast::reinterpret_cast(&i2); + let i2p = cast::transmute_copy(&i2); cast::forget(i2); let u1 = U {a: 0xB, b: 0xC, c: i1p}; diff --git a/src/test/run-pass/rt-sched-1.rs b/src/test/run-pass/rt-sched-1.rs index 8bf5627b4cd49..e7dd240eb184c 100644 --- a/src/test/run-pass/rt-sched-1.rs +++ b/src/test/run-pass/rt-sched-1.rs @@ -48,7 +48,7 @@ pub fn main() { ch.send(()); } }; - let fptr = cast::reinterpret_cast(&ptr::addr_of(&f)); + let fptr = cast::transmute(&f); rustrt::start_task(new_task_id, fptr); cast::forget(f); po.recv(); diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index a91a6a9282006..afed0bd9ac3f8 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cell::Cell; + pub fn main() { test05(); } fn test05_start(&&f: ~fn(int)) { @@ -20,7 +22,8 @@ fn test05() { error!(*three + n); // will copy x into the closure assert!((*three == 3)); }; + let fn_to_send = Cell(fn_to_send); task::spawn(|| { - test05_start(fn_to_send); + test05_start(fn_to_send.take()); }); } diff --git a/src/test/run-pass/stable-addr-of.rs b/src/test/run-pass/stable-addr-of.rs index a2e43f14898f5..3731f41f8f81c 100644 --- a/src/test/run-pass/stable-addr-of.rs +++ b/src/test/run-pass/stable-addr-of.rs @@ -12,5 +12,5 @@ pub fn main() { let foo = 1; - assert!(ptr::addr_of(&foo) == ptr::addr_of(&foo)); + assert!(ptr::to_unsafe_ptr(&foo) == ptr::to_unsafe_ptr(&foo)); } diff --git a/src/test/run-pass/static-method-test.rs b/src/test/run-pass/static-method-test.rs index 388a7100daf44..973897cd14521 100644 --- a/src/test/run-pass/static-method-test.rs +++ b/src/test/run-pass/static-method-test.rs @@ -9,7 +9,6 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; // A trait for objects that can be used to do an if-then-else // (No actual need for this to be static, but it is a simple test.) @@ -59,10 +58,10 @@ fn build>(builder: &fn(push: &fn(+v: A))) -> B { /// Apply a function to each element of an iterable and return the results fn map, U, BU: buildable> - (v: IT, f: &fn(T) -> U) -> BU { + (v: IT, f: &fn(&T) -> U) -> BU { do build |push| { for v.each() |elem| { - push(f(*elem)); + push(f(elem)); } } } @@ -79,9 +78,9 @@ pub fn main() { let v: @[int] = seq_range(0, 10); assert!(v == @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - let v: @[int] = map(&[1,2,3], |x| 1+x); + let v: @[int] = map(&[1,2,3], |&x| 1+x); assert!(v == @[2, 3, 4]); - let v: ~[int] = map(&[1,2,3], |x| 1+x); + let v: ~[int] = map(&[1,2,3], |&x| 1+x); assert!(v == ~[2, 3, 4]); assert!(bool_like::select(true, 9, 14) == 9); diff --git a/src/test/run-pass/tag-align-dyn-u64.rs b/src/test/run-pass/tag-align-dyn-u64.rs index 1798bb688bd27..a9c59de49eeaa 100644 --- a/src/test/run-pass/tag-align-dyn-u64.rs +++ b/src/test/run-pass/tag-align-dyn-u64.rs @@ -24,7 +24,7 @@ fn mk_rec() -> t_rec { } fn is_8_byte_aligned(&&u: a_tag) -> bool { - let p = ptr::addr_of(u) as uint; + let p = ptr::to_unsafe_ptr(u) as uint; return (p & 7u) == 0u; } diff --git a/src/test/run-pass/tag-align-dyn-variants.rs b/src/test/run-pass/tag-align-dyn-variants.rs index 80e300596b957..4fc6410f8f3d0 100644 --- a/src/test/run-pass/tag-align-dyn-variants.rs +++ b/src/test/run-pass/tag-align-dyn-variants.rs @@ -27,7 +27,7 @@ fn mk_rec(a: A, b: B) -> t_rec { } fn is_aligned(amnt: uint, &&u: A) -> bool { - let p = ptr::addr_of(u) as uint; + let p = ptr::to_unsafe_ptr(u) as uint; return (p & (amnt-1u)) == 0u; } diff --git a/src/test/run-pass/tag-align-u64.rs b/src/test/run-pass/tag-align-u64.rs index 21c51220be878..fd96d7d0242c3 100644 --- a/src/test/run-pass/tag-align-u64.rs +++ b/src/test/run-pass/tag-align-u64.rs @@ -24,7 +24,7 @@ fn mk_rec() -> t_rec { } fn is_8_byte_aligned(&&u: a_tag) -> bool { - let p = ptr::addr_of(u) as u64; + let p = ptr::to_unsafe_ptr(u) as u64; return (p & 7u64) == 0u64; } diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index 34ce56250fce1..0806f1ea92aec 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -38,7 +38,7 @@ pub fn main() { } fn test_color(color: color, val: int, name: ~str) { - //assert!(unsafe::reinterpret_cast(color) == val); + //assert!(unsafe::transmute(color) == val); assert!(color as int == val); assert!(color as float == val as float); assert!(get_color_alt(color) == name); diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index ffcba42ff518b..6fc29fa32db32 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -9,7 +9,6 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; extern mod std; @@ -18,7 +17,7 @@ use core::comm::Port; pub fn main() { test05(); } -fn test05_start(ch : Chan) { +fn test05_start(ch : &Chan) { ch.send(10); error!("sent 10"); ch.send(20); @@ -29,8 +28,8 @@ fn test05_start(ch : Chan) { fn test05() { let (po, ch) = comm::stream(); - task::spawn(|| test05_start(ch) ); - let mut value = po.recv(); + task::spawn(|| test05_start(&ch) ); + let mut value: int = po.recv(); error!(value); value = po.recv(); error!(value); diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index a246f1f4af2b1..f22328a3e1b32 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -9,11 +9,10 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; extern mod std; -fn start(c: comm::Chan, start: int, number_of_messages: int) { +fn start(c: &comm::Chan, start: int, number_of_messages: int) { let mut i: int = 0; while i < number_of_messages { c.send(start + i); i += 1; } } @@ -21,6 +20,6 @@ fn start(c: comm::Chan, start: int, number_of_messages: int) { pub fn main() { debug!("Check that we don't deadlock."); let (p, ch) = comm::stream(); - task::try(|| start(ch, 0, 10) ); + task::try(|| start(&ch, 0, 10) ); debug!("Joined task"); } diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs index 81b4988852559..12f9a113dfc3e 100644 --- a/src/test/run-pass/task-comm-7.rs +++ b/src/test/run-pass/task-comm-7.rs @@ -9,13 +9,12 @@ // except according to those terms. // xfail-fast -#[legacy_modes]; extern mod std; pub fn main() { test00(); } -fn test00_start(c: comm::Chan, start: int, number_of_messages: int) { +fn test00_start(c: &comm::Chan, start: int, number_of_messages: int) { let mut i: int = 0; while i < number_of_messages { c.send(start + i); i += 1; } } @@ -28,19 +27,19 @@ fn test00() { let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 0, number_of_messages); + test00_start(&c, number_of_messages * 0, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 1, number_of_messages); + test00_start(&c, number_of_messages * 1, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 2, number_of_messages); + test00_start(&c, number_of_messages * 2, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 3, number_of_messages); + test00_start(&c, number_of_messages * 3, number_of_messages); } let mut i: int = 0; diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 042ae1785d1be..7cd08695da0f0 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -26,7 +26,7 @@ impl Drop for notify { unsafe { error!("notify: task=%? v=%x unwinding=%b b=%b", task::get_task(), - ptr::addr_of(&(*(self.v))) as uint, + ptr::to_unsafe_ptr(&(*(self.v))) as uint, task::failing(), *(self.v)); let b = *(self.v); @@ -47,7 +47,7 @@ fn joinable(f: ~fn()) -> Port { let b = @mut false; error!("wrapper: task=%? allocated v=%x", task::get_task(), - ptr::addr_of(&(*b)) as uint); + ptr::to_unsafe_ptr(&(*b)) as uint); let _r = notify(c, b); f(); *b = true; diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index b3f5bad56ef06..ba10bfb670452 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -14,10 +14,10 @@ pub fn main() { let (p, ch) = stream::(); let x = ~1; - let x_in_parent = ptr::addr_of(&(*x)) as uint; + let x_in_parent = ptr::to_unsafe_ptr(&(*x)) as uint; task::spawn(|| { - let x_in_child = ptr::addr_of(&(*x)) as uint; + let x_in_child = ptr::to_unsafe_ptr(&(*x)) as uint; ch.send(x_in_child); }); diff --git a/src/test/run-pass/unify-return-ty.rs b/src/test/run-pass/unify-return-ty.rs index 5452936c411a0..820d42ab14d57 100644 --- a/src/test/run-pass/unify-return-ty.rs +++ b/src/test/run-pass/unify-return-ty.rs @@ -15,7 +15,7 @@ extern mod std; fn null() -> *T { unsafe { - cast::reinterpret_cast(&0) + cast::transmute(0) } } diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index 3a23a8246a561..7327f4a3498e0 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -19,7 +19,7 @@ struct Pointy { } fn make_uniq_closure(a: A) -> ~fn() -> uint { - let result: ~fn() -> uint = || ptr::addr_of(&a) as uint; + let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint; result }