~~~~
# use std::map;
# fn f() {
-# fn id<T:copy>(t: T) -> T { t }
+# fn id<T:Copy>(t: T) -> T { t }
type t = map::hashmap<int,~str>; // Type arguments used in a type expression
let x = id::<int>(10); // Type arguments used in a call expression
# }
~~~~
# use std::list::*;
-fn pure_foldl<T, U: copy>(ls: List<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
+fn pure_foldl<T, U: Copy>(ls: List<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
match ls {
Nil => u,
Cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
parameter is given a [`copy` bound](#type-kinds).
~~~~
-fn id<T: copy>(x: T) -> T { x }
+fn id<T: Copy>(x: T) -> T { x }
~~~~
Similarly, [trait](#traits) bounds can be specified for type
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
~~~~~~~
-fn map<A: copy, B: copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
+fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
if xs.len() == 0 { return ~[]; }
let first: B = f(xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
is assumed to be noncopyable. To change that, a bound is declared:
~~~~
-fn box<T: copy>(x: T) -> @T { @x }
+fn box<T: Copy>(x: T) -> @T { @x }
~~~~
Calling this second version of `box` on a noncopyable type is not
// This does not compile
fn head_bad<T>(v: ~[T]) -> T { v[0] }
// This does
-fn head<T: copy>(v: ~[T]) -> T { v[0] }
+fn head<T: Copy>(v: ~[T]) -> T { v[0] }
~~~~
When instantiating a generic function, you can only instantiate it
with types that fit its kinds. So you could not apply `head` to a
resource type. Rust has several kinds that can be used as type bounds:
-* `copy` - Copyable types. All types are copyable unless they
+* `Copy` - Copyable types. All types are copyable unless they
are classes with destructors or otherwise contain
classes with destructors.
-* `send` - Sendable types. All types are sendable unless they
+* `Send` - Sendable types. All types are sendable unless they
contain shared boxes, closures, or other local-heap-allocated
types.
-* `const` - Constant types. These are types that do not contain
+* `Const` - Constant types. These are types that do not contain
mutable fields nor shared boxes.
> ***Note:*** Rust type kinds are syntactically very similar to
~~~~
mod buffalo {
type buffalo = int;
- fn buffalo<buffalo: copy>(buffalo: buffalo) -> buffalo { buffalo }
+ fn buffalo<buffalo>(+buffalo: buffalo) -> buffalo { buffalo }
}
fn main() {
let buffalo: buffalo::buffalo = 1;
pprust::ty_to_str, replace_ty_in_crate, cx);
}
-fn check_variants_T<T: copy>(
+fn check_variants_T<T: Copy>(
crate: ast::crate,
codemap: codemap::codemap,
filename: &Path,
// Appending
#[inline(always)]
-pure fn append<T: copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
+pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| {
for vec::each(lhs) |x| { push(x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
-pure fn from_elem<T: copy>(n_elts: uint, t: T) -> @[T] {
+pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(t); i += 1u; }
}
#[cfg(notest)]
-impl<T: copy> @[T]: Add<&[const T],@[T]> {
+impl<T: Copy> @[T]: Add<&[const T],@[T]> {
#[inline(always)]
pure fn add(rhs: &[const T]) -> @[T] {
append(self, rhs)
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
-enum Port<T: send> {
+enum Port<T: Send> {
Port_(@PortPtr<T>)
}
* data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels.
*/
-enum Chan<T: send> {
+enum Chan<T: Send> {
Chan_(port_id)
}
/// Constructs a port
-fn Port<T: send>() -> Port<T> {
+fn Port<T: Send>() -> Port<T> {
Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}
-impl<T: send> Port<T> {
+impl<T: Send> Port<T> {
fn chan() -> Chan<T> { Chan(self) }
fn send(+v: T) { self.chan().send(v) }
}
-impl<T: send> Chan<T> {
+impl<T: Send> Chan<T> {
fn chan() -> Chan<T> { self }
fn send(+v: T) { send(self, v) }
}
/// Open a new receiving channel for the duration of a function
-fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
+fn listen<T: Send, U>(f: fn(Chan<T>) -> U) -> U {
let po = Port();
f(po.chan())
}
-struct PortPtr<T:send> {
+struct PortPtr<T:Send> {
po: *rust_port,
drop unsafe {
do task::unkillable {
}
}
-fn PortPtr<T: send>(po: *rust_port) -> PortPtr<T> {
+fn PortPtr<T: Send>(po: *rust_port) -> PortPtr<T> {
PortPtr {
po: po
}
* Fails if the port is detached or dead. Fails if the port
* is owned by a different task.
*/
-fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
+fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
struct PortRef {
p: *rust_port,
* Constructs a channel. The channel is bound to the port used to
* construct it.
*/
-fn Chan<T: send>(p: Port<T>) -> Chan<T> {
+fn Chan<T: Send>(p: Port<T>) -> Chan<T> {
Chan_(rustrt::get_port_id((**p).po))
}
* Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it.
*/
-fn send<T: send>(ch: Chan<T>, +data: T) {
+fn send<T: Send>(ch: Chan<T>, +data: T) {
let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
* Receive from a port. If no data is available on the port then the
* task will block until data becomes available.
*/
-fn recv<T: send>(p: Port<T>) -> T { recv_((**p).po) }
+fn recv<T: Send>(p: Port<T>) -> T { recv_((**p).po) }
/// Returns true if there are messages available
-fn peek<T: send>(p: Port<T>) -> bool { peek_((**p).po) }
+fn peek<T: Send>(p: Port<T>) -> bool { peek_((**p).po) }
#[doc(hidden)]
-fn recv_chan<T: send>(ch: comm::Chan<T>) -> T {
+fn recv_chan<T: Send>(ch: comm::Chan<T>) -> T {
as_raw_port(ch, |x|recv_(x))
}
-fn peek_chan<T: send>(ch: comm::Chan<T>) -> bool {
+fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
as_raw_port(ch, |x|peek_(x))
}
/// Receive on a raw port pointer
-fn recv_<T: send>(p: *rust_port) -> T {
+fn recv_<T: Send>(p: *rust_port) -> T {
let yield = 0u;
let yieldp = ptr::addr_of(yield);
let mut res;
}
/// Receive on one of two ports
-fn select2<A: send, B: send>(p_a: Port<A>, p_b: Port<B>)
+fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0u, yieldp = ptr::addr_of(yield);
list
}
-fn from_vec<T: copy>(+vec: &[T]) -> DList<T> {
+fn from_vec<T: Copy>(+vec: &[T]) -> DList<T> {
do vec::foldl(DList(), vec) |list,data| {
list.push(data); // Iterating left-to-right -- add newly to the tail.
list
}
}
-impl<T: copy> DList<T> {
+impl<T: Copy> DList<T> {
/// Remove data from the head of the list. O(1).
fn pop() -> Option<T> { self.pop_n().map (|nobe| nobe.data) }
/// Remove data from the tail of the list. O(1).
}
}
-impl<A: copy> DVec<A> {
+impl<A: Copy> DVec<A> {
/**
* Append all elements of a vector to the end of the list
*
}
}
-impl<A:copy> DVec<A>: Index<uint,A> {
+impl<A:Copy> DVec<A>: Index<uint,A> {
pure fn index(&&idx: uint) -> A {
self.get_elt(idx)
}
}
}
-fn lefts<T: copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
+fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
//! Extracts from a vector of either all the left values
let mut result: ~[T] = ~[];
return result;
}
-fn rights<T, U: copy>(eithers: &[Either<T, U>]) -> ~[U] {
+fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
//! Extracts from a vector of either all the right values
let mut result: ~[U] = ~[];
return result;
}
-fn partition<T: copy, U: copy>(eithers: &[Either<T, U>])
+fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
-> {lefts: ~[T], rights: ~[U]} {
/*!
* Extracts from a vector of either all the left values and right values
return {lefts: lefts, rights: rights};
}
-pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> {
+pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
//! Flips between left and right of a given either
match *eith {
}
}
-pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> Result<U, T> {
+pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>) -> Result<U, T> {
/*!
* Converts either::t to a result::t
*
}
/// Methods on the `future` type
-impl<A:copy> Future<A> {
+impl<A:Copy> Future<A> {
fn get() -> A {
//! Get the value of the future
Future {state: Forced(val)}
}
-fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
+fn from_port<A:Send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
/*!
* Create a future from a port
*
Future {state: Pending(f)}
}
-fn spawn<A:send>(+blk: fn~() -> A) -> Future<A> {
+fn spawn<A:Send>(+blk: fn~() -> A) -> Future<A> {
/*!
* Create a future from a unique closure.
*
}
}
-fn get<A:copy>(future: &Future<A>) -> A {
+fn get<A:Copy>(future: &Future<A>) -> A {
//! Get the value of the future
*get_ref(future)
}
proto! future_pipe (
- waiting:recv<T:send> {
+ waiting:recv<T:Send> {
completed(T) -> !
}
)
}
}
-impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> {
+impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
}
-impl<A: copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {
+impl<A: Copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {
pure fn min() -> A { iter::min(self) }
pure fn max() -> A { iter::max(self) }
}
pure fn timesi(it: fn(uint) -> bool);
}
-trait CopyableIter<A:copy> {
+trait CopyableIter<A:Copy> {
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A];
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
pure fn to_vec() -> ~[A];
pure fn find(p: fn(A) -> bool) -> Option<A>;
}
-trait CopyableOrderedIter<A:copy Ord> {
+trait CopyableOrderedIter<A:Copy Ord> {
pure fn min() -> A;
pure fn max() -> A;
}
return false;
}
-pure fn filter_to_vec<A:copy,IA:BaseIter<A>>(self: IA,
+pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: IA,
prd: fn(A) -> bool) -> ~[A] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
}
}
-pure fn map_to_vec<A:copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
+pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
-> ~[B] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
}
}
-pure fn flat_map_to_vec<A:copy,B:copy,IA:BaseIter<A>,IB:BaseIter<B>>(
+pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
self: IA, op: fn(A) -> IB) -> ~[B] {
do vec::build |push| {
return b;
}
-pure fn to_vec<A:copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
+pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
}
}
}
-pure fn min<A:copy Ord,IA:BaseIter<A>>(self: IA) -> A {
+pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
Some(a_) if a_ < b => {
}
}
-pure fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A {
+pure fn max<A:Copy,IA:BaseIter<A>>(self: IA) -> A {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
Some(a_) if a_ > b => {
}
}
-pure fn find<A: copy,IA:BaseIter<A>>(self: IA,
+pure fn find<A: Copy,IA:BaseIter<A>>(self: IA,
p: fn(A) -> bool) -> Option<A> {
for self.each |i| {
if p(i) { return Some(i) }
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
-pure fn from_elem<T: copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
+pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(t); i += 1u; }
/// Appending two generic sequences
#[inline(always)]
-pure fn append<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
+pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
lhs: IT, rhs: IT) -> BT {
let size_opt = lhs.size_hint().chain(
|sz1| rhs.size_hint().map(|sz2| sz1+sz2));
/// Copies a generic sequence, possibly converting it to a different
/// type of sequence.
#[inline(always)]
-pure fn copy_seq<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
+pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
v: IT) -> BT {
do build_sized_opt(v.size_hint()) |push| {
for v.each |x| { push(x); }
Some(T),
}
-pure fn get<T: copy>(opt: Option<T>) -> T {
+pure fn get<T: Copy>(opt: Option<T>) -> T {
/*!
* Gets the value out of an option
*
}
}
-pure fn expect<T: copy>(opt: Option<T>, reason: ~str) -> T {
+pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T {
/*!
* Gets the value out of an option, printing a specified message on
* failure
!is_none(opt)
}
-pure fn get_default<T: copy>(opt: Option<T>, def: T) -> T {
+pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T {
//! Returns the contained value or a default
match opt { Some(x) => x, None => def }
pure fn get_ref() -> &self/T { get_ref(self) }
}
-impl<T: copy> Option<T> {
+impl<T: Copy> Option<T> {
/**
* Gets the value out of an option
*
// This is for protocols to associate extra data to thread around.
#[doc(hidden)]
-type Buffer<T: send> = {
+type Buffer<T: Send> = {
header: BufferHeader,
data: T,
};
reinterpret_cast(&self.buffer)
}
- fn set_buffer<T: send>(b: ~Buffer<T>) unsafe {
+ fn set_buffer<T: Send>(b: ~Buffer<T>) unsafe {
self.buffer = reinterpret_cast(&b);
}
}
}
#[doc(hidden)]
-type Packet<T: send> = {
+type Packet<T: Send> = {
header: PacketHeader,
mut payload: Option<T>,
};
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
-type packet<T: send> = Packet<T>;
+type packet<T: Send> = Packet<T>;
#[doc(hidden)]
trait HasBuffer {
fn set_buffer_(b: *libc::c_void);
}
-impl<T: send> Packet<T>: HasBuffer {
+impl<T: Send> Packet<T>: HasBuffer {
fn set_buffer_(b: *libc::c_void) {
self.header.buffer = b;
}
}
#[cfg(stage0)] // XXX remove me
-impl<T: send> packet<T>: has_buffer {
+impl<T: Send> packet<T>: has_buffer {
fn set_buffer(b: *libc::c_void) {
self.header.buffer = b;
}
}
#[doc(hidden)]
-fn mk_packet<T: send>() -> Packet<T> {
+fn mk_packet<T: Send>() -> Packet<T> {
{
header: PacketHeader(),
mut payload: None
}
#[doc(hidden)]
-fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
+fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
let b = ~{
header: BufferHeader(),
data: {
}
#[doc(hidden)]
-fn packet<T: send>() -> *Packet<T> {
+fn packet<T: Send>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(b.data);
// We'll take over memory management from here.
}
#[doc(hidden)]
-fn entangle_buffer<T: send, Tstart: send>(
+fn entangle_buffer<T: Send, Tstart: Send>(
+buffer: ~Buffer<T>,
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
}
#[doc(hidden)]
-unsafe fn get_buffer<T: send>(p: *PacketHeader) -> ~Buffer<T> {
+unsafe fn get_buffer<T: Send>(p: *PacketHeader) -> ~Buffer<T> {
transmute((*p).buf_header())
}
// This could probably be done with SharedMutableState to avoid move_it!().
-struct BufferResource<T: send> {
+struct BufferResource<T: Send> {
buffer: ~Buffer<T>,
drop unsafe {
}
}
-fn BufferResource<T: send>(+b: ~Buffer<T>) -> BufferResource<T> {
+fn BufferResource<T: Send>(+b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//error!("take %?", p);
atomic_add_acq(&mut b.header.ref_count, 1);
}
#[doc(hidden)]
-fn send<T: send, Tbuffer: send>(+p: SendPacketBuffered<T, Tbuffer>,
+fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
+payload: T) -> bool {
let header = p.header();
let p_ = p.unwrap();
Fails if the sender closes the connection.
*/
-fn recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>) -> T {
+fn recv<T: Send, Tbuffer: Send>(+p: RecvPacketBuffered<T, Tbuffer>) -> T {
option::unwrap_expect(try_recv(p), "connection closed")
}
a message, or `Some(T)` if a message was received.
*/
-fn try_recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>)
+fn try_recv<T: Send, Tbuffer: Send>(+p: RecvPacketBuffered<T, Tbuffer>)
-> Option<T>
{
let p_ = p.unwrap();
}
/// Returns true if messages are available.
-pure fn peek<T: send, Tb: send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
+pure fn peek<T: Send, Tb: Send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
match unsafe {(*p.header()).state} {
Empty => false,
Blocked => fail ~"peeking on blocked packet",
}
}
-impl<T: send, Tb: send> RecvPacketBuffered<T, Tb> {
+impl<T: Send, Tb: Send> RecvPacketBuffered<T, Tb> {
pure fn peek() -> bool {
peek(&self)
}
}
#[doc(hidden)]
-fn sender_terminate<T: send>(p: *Packet<T>) {
+fn sender_terminate<T: Send>(p: *Packet<T>) {
let p = unsafe { &*p };
match swap_state_rel(&mut p.header.state, Terminated) {
Empty => {
}
#[doc(hidden)]
-fn receiver_terminate<T: send>(p: *Packet<T>) {
+fn receiver_terminate<T: Send>(p: *Packet<T>) {
let p = unsafe { &*p };
match swap_state_rel(&mut p.header.state, Terminated) {
Empty => {
this case, `select2` may return either `left` or `right`.
*/
-fn select2<A: send, Ab: send, B: send, Bb: send>(
+fn select2<A: Send, Ab: Send, B: Send, Bb: Send>(
+a: RecvPacketBuffered<A, Ab>,
+b: RecvPacketBuffered<B, Bb>)
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
list of the remaining endpoints.
*/
-fn select<T: send, Tb: send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
+fn select<T: Send, Tb: Send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
{
let ready = wait_many(endpoints.map(|p| p.header()));
message.
*/
-type SendPacket<T: send> = SendPacketBuffered<T, Packet<T>>;
+type SendPacket<T: Send> = SendPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
-fn SendPacket<T: send>(p: *Packet<T>) -> SendPacket<T> {
+fn SendPacket<T: Send>(p: *Packet<T>) -> SendPacket<T> {
SendPacketBuffered(p)
}
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
-type send_packet<T: send> = SendPacket<T>;
+type send_packet<T: Send> = SendPacket<T>;
// XXX remove me
#[cfg(stage0)]
-fn send_packet<T: send>(p: *packet<T>) -> SendPacket<T> {
+fn send_packet<T: Send>(p: *packet<T>) -> SendPacket<T> {
SendPacket(p)
}
-struct SendPacketBuffered<T: send, Tbuffer: send> {
+struct SendPacketBuffered<T: Send, Tbuffer: Send> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
}
}
-fn SendPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
+fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
SendPacketBuffered {
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
-type send_packet_buffered<T: send, Tbuffer: send> =
+type send_packet_buffered<T: Send, Tbuffer: Send> =
SendPacketBuffered<T, Tbuffer>;
/// Represents the receive end of a pipe. It can receive exactly one
/// message.
-type RecvPacket<T: send> = RecvPacketBuffered<T, Packet<T>>;
+type RecvPacket<T: Send> = RecvPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
-fn RecvPacket<T: send>(p: *Packet<T>) -> RecvPacket<T> {
+fn RecvPacket<T: Send>(p: *Packet<T>) -> RecvPacket<T> {
RecvPacketBuffered(p)
}
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
-type recv_packet<T: send> = RecvPacket<T>;
+type recv_packet<T: Send> = RecvPacket<T>;
// XXX remove me
#[cfg(stage0)]
-fn recv_packet<T: send>(p: *packet<T>) -> RecvPacket<T> {
+fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
RecvPacket(p)
}
-struct RecvPacketBuffered<T: send, Tbuffer: send> : Selectable {
+struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
}
}
-fn RecvPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
+fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
-> RecvPacketBuffered<T, Tbuffer> {
//debug!("take recv %?", p);
RecvPacketBuffered {
// XXX remove me
#[cfg(stage0)]
#[allow(non_camel_case_types)]
-type recv_packet_buffered<T: send, Tbuffer: send> =
+type recv_packet_buffered<T: Send, Tbuffer: Send> =
RecvPacketBuffered<T, Tbuffer>;
#[doc(hidden)]
-fn entangle<T: send>() -> (SendPacket<T>, RecvPacket<T>) {
+fn entangle<T: Send>() -> (SendPacket<T>, RecvPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
}
endpoint is passed to the new task.
*/
-fn spawn_service<T: send, Tb: send>(
+fn spawn_service<T: Send, Tb: Send>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
+service: fn~(+RecvPacketBuffered<T, Tb>))
receive state.
*/
-fn spawn_service_recv<T: send, Tb: send>(
+fn spawn_service_recv<T: Send, Tb: Send>(
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
+service: fn~(+SendPacketBuffered<T, Tb>))
// Streams - Make pipes a little easier in general.
proto! streamp (
- Open:send<T: send> {
+ Open:send<T: Send> {
data(T) -> Open<T>
}
)
/// A trait for things that can send multiple messages.
-trait Channel<T: send> {
+trait Channel<T: Send> {
// It'd be nice to call this send, but it'd conflict with the
// built in send kind.
}
/// A trait for things that can receive multiple messages.
-trait Recv<T: send> {
+trait Recv<T: Send> {
/// Receives a message, or fails if the connection closes.
fn recv() -> T;
}
#[doc(hidden)]
-type Chan_<T:send> = { mut endp: Option<streamp::client::Open<T>> };
+type Chan_<T:Send> = { mut endp: Option<streamp::client::Open<T>> };
/// An endpoint that can send many messages.
-enum Chan<T:send> {
+enum Chan<T:Send> {
Chan_(Chan_<T>)
}
#[doc(hidden)]
-type Port_<T:send> = { mut endp: Option<streamp::server::Open<T>> };
+type Port_<T:Send> = { mut endp: Option<streamp::server::Open<T>> };
/// An endpoint that can receive many messages.
-enum Port<T:send> {
+enum Port<T:Send> {
Port_(Port_<T>)
}
These allow sending or receiving an unlimited number of messages.
*/
-fn stream<T:send>() -> (Chan<T>, Port<T>) {
+fn stream<T:Send>() -> (Chan<T>, Port<T>) {
let (c, s) = streamp::init();
(Chan_({ mut endp: Some(c) }), Port_({ mut endp: Some(s) }))
}
-impl<T: send> Chan<T>: Channel<T> {
+impl<T: Send> Chan<T>: Channel<T> {
fn send(+x: T) {
let mut endp = None;
endp <-> self.endp;
}
}
-impl<T: send> Port<T>: Recv<T> {
+impl<T: Send> Port<T>: Recv<T> {
fn recv() -> T {
let mut endp = None;
endp <-> self.endp;
}
/// Treat many ports as one.
-struct PortSet<T: send> : Recv<T> {
+struct PortSet<T: Send> : Recv<T> {
mut ports: ~[pipes::Port<T>],
fn add(+port: pipes::Port<T>) {
}
}
-fn PortSet<T: send>() -> PortSet<T>{
+fn PortSet<T: Send>() -> PortSet<T>{
PortSet {
ports: ~[]
}
}
-impl<T: send> Port<T>: Selectable {
+impl<T: Send> Port<T>: Selectable {
pure fn header() -> *PacketHeader unchecked {
match self.endp {
Some(endp) => endp.header(),
}
/// A channel that can be shared between many senders.
-type SharedChan<T: send> = unsafe::Exclusive<Chan<T>>;
+type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;
-impl<T: send> SharedChan<T>: Channel<T> {
+impl<T: Send> SharedChan<T>: Channel<T> {
fn send(+x: T) {
let mut xx = Some(x);
do self.with |chan| {
}
/// Converts a `chan` into a `shared_chan`.
-fn SharedChan<T:send>(+c: Chan<T>) -> SharedChan<T> {
+fn SharedChan<T:Send>(+c: Chan<T>) -> SharedChan<T> {
unsafe::exclusive(c)
}
/// Receive a message from one of two endpoints.
-trait Select2<T: send, U: send> {
+trait Select2<T: Send, U: Send> {
/// Receive a message or return `none` if a connection closes.
fn try_select() -> Either<Option<T>, Option<U>>;
/// Receive a message or fail if a connection closes.
fn select() -> Either<T, U>;
}
-impl<T: send, U: send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
+impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
(Left, Right): Select2<T, U> {
fn select() -> Either<T, U> {
}
proto! oneshot (
- Oneshot:send<T:send> {
+ Oneshot:send<T:Send> {
send(T) -> !
}
)
/// The send end of a oneshot pipe.
-type ChanOne<T: send> = oneshot::client::Oneshot<T>;
+type ChanOne<T: Send> = oneshot::client::Oneshot<T>;
/// The receive end of a oneshot pipe.
-type PortOne<T: send> = oneshot::server::Oneshot<T>;
+type PortOne<T: Send> = oneshot::server::Oneshot<T>;
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
-fn oneshot<T: send>() -> (ChanOne<T>, PortOne<T>) {
+fn oneshot<T: Send>() -> (ChanOne<T>, PortOne<T>) {
oneshot::init()
}
* Receive a message from a oneshot pipe, failing if the connection was
* closed.
*/
-fn recv_one<T: send>(+port: PortOne<T>) -> T {
+fn recv_one<T: Send>(+port: PortOne<T>) -> T {
let oneshot::send(message) = recv(port);
message
}
/// Receive a message from a oneshot pipe unless the connection was closed.
-fn try_recv_one<T: send> (+port: PortOne<T>) -> Option<T> {
+fn try_recv_one<T: Send> (+port: PortOne<T>) -> Option<T> {
let message = try_recv(port);
if message.is_none() { None }
}
/// Send a message on a oneshot pipe, failing if the connection was closed.
-fn send_one<T: send>(+chan: ChanOne<T>, +data: T) {
+fn send_one<T: Send>(+chan: ChanOne<T>, +data: T) {
oneshot::client::send(chan, data);
}
* Send a message on a oneshot pipe, or return false if the connection was
* closed.
*/
-fn try_send_one<T: send>(+chan: ChanOne<T>, +data: T)
+fn try_send_one<T: Send>(+chan: ChanOne<T>, +data: T)
-> bool {
oneshot::client::try_send(chan, data).is_some()
}
* or, if no channel exists creates and installs a new channel and sets up a
* new task to receive from it.
*/
-unsafe fn chan_from_global_ptr<T: send>(
+unsafe fn chan_from_global_ptr<T: Send>(
global: GlobalPtr,
task_fn: fn() -> task::TaskBuilder,
+f: fn~(comm::Port<T>)
}
/// Choose an item randomly, failing if values is empty
- fn choose<T:copy>(values: &[T]) -> T {
+ fn choose<T:Copy>(values: &[T]) -> T {
self.choose_option(values).get()
}
/// Choose Some(item) randomly, returning None if values is empty
- fn choose_option<T:copy>(values: &[T]) -> Option<T> {
+ fn choose_option<T:Copy>(values: &[T]) -> Option<T> {
if values.is_empty() {
None
} else {
* Choose an item respecting the relative weights, failing if the sum of
* the weights is 0
*/
- fn choose_weighted<T: copy>(v : &[Weighted<T>]) -> T {
+ fn choose_weighted<T: Copy>(v : &[Weighted<T>]) -> T {
self.choose_weighted_option(v).get()
}
* Choose Some(item) respecting the relative weights, returning none if
* the sum of the weights is 0
*/
- fn choose_weighted_option<T:copy>(v: &[Weighted<T>]) -> Option<T> {
+ fn choose_weighted_option<T:Copy>(v: &[Weighted<T>]) -> Option<T> {
let mut total = 0u;
for v.each |item| {
total += item.weight;
* Return a vec containing copies of the items, in order, where
* the weight of the item determines how many copies there are
*/
- fn weighted_vec<T:copy>(v: &[Weighted<T>]) -> ~[T] {
+ fn weighted_vec<T:Copy>(v: &[Weighted<T>]) -> ~[T] {
let mut r = ~[];
for v.each |item| {
for uint::range(0u, item.weight) |_i| {
}
/// Shuffle a vec
- fn shuffle<T:copy>(values: &[T]) -> ~[T] {
+ fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
let mut m = vec::from_slice(values);
self.shuffle_mut(m);
return m;
*
* If the result is an error
*/
-pure fn get<T: copy, U>(res: Result<T, U>) -> T {
+pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
match res {
Ok(t) => t,
Err(the_err) => unchecked {
*
* If the result is not an error
*/
-pure fn get_err<T, U: copy>(res: Result<T, U>) -> U {
+pure fn get_err<T, U: Copy>(res: Result<T, U>) -> U {
match res {
Err(u) => u,
Ok(_) => fail ~"get_err called on ok result"
* `ok` result variants are converted to `either::right` variants, `err`
* result variants are converted to `either::left`.
*/
-pure fn to_either<T: copy, U: copy>(res: Result<U, T>) -> Either<T, U> {
+pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> {
match res {
Ok(res) => either::Right(res),
Err(fail_) => either::Left(fail_)
* ok(parse_buf(buf))
* }
*/
-fn chain<T, U: copy, V: copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
+fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
-> Result<U, V> {
match res {
Ok(t) => op(t),
* immediately returned. This function can be used to pass through a
* successful result while handling an error.
*/
-fn chain_err<T: copy, U: copy, V: copy>(
+fn chain_err<T: Copy, U: Copy, V: Copy>(
res: Result<T, V>,
op: fn(V) -> Result<T, U>)
-> Result<T, U> {
* parse_buf(buf)
* }
*/
-fn map<T, E: copy, U: copy>(res: Result<T, E>, op: fn(T) -> U)
+fn map<T, E: Copy, U: Copy>(res: Result<T, E>, op: fn(T) -> U)
-> Result<U, E> {
match res {
Ok(t) => Ok(op(t)),
* is immediately returned. This function can be used to pass through a
* successful result while handling an error.
*/
-fn map_err<T: copy, E, F: copy>(res: Result<T, E>, op: fn(E) -> F)
+fn map_err<T: Copy, E, F: Copy>(res: Result<T, E>, op: fn(E) -> F)
-> Result<T, F> {
match res {
Ok(t) => Ok(t),
}
}
-impl<T: copy, E> Result<T, E> {
+impl<T: Copy, E> Result<T, E> {
fn get() -> T { get(self) }
- fn map_err<F:copy>(op: fn(E) -> F) -> Result<T,F> {
+ fn map_err<F:Copy>(op: fn(E) -> F) -> Result<T,F> {
match self {
Ok(t) => Ok(t),
Err(e) => Err(op(e))
}
}
-impl<T, E: copy> Result<T, E> {
+impl<T, E: Copy> Result<T, E> {
fn get_err() -> E { get_err(self) }
- fn map<U:copy>(op: fn(T) -> U) -> Result<U,E> {
+ fn map<U:Copy>(op: fn(T) -> U) -> Result<U,E> {
match self {
Ok(t) => Ok(op(t)),
Err(e) => Err(e)
}
}
-impl<T: copy, E: copy> Result<T, E> {
- fn chain<U:copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
+impl<T: Copy, E: Copy> Result<T, E> {
+ fn chain<U:Copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
chain(self, op)
}
- fn chain_err<F:copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
+ fn chain_err<F:Copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
chain_err(self, op)
}
}
* assert incd == ~[2u, 3u, 4u];
* }
*/
-fn map_vec<T,U:copy,V:copy>(
+fn map_vec<T,U:Copy,V:Copy>(
ts: &[T], op: fn(T) -> Result<V,U>) -> Result<~[V],U> {
let mut vs: ~[V] = ~[];
return Ok(vs);
}
-fn map_opt<T,U:copy,V:copy>(
+fn map_opt<T,U:Copy,V:Copy>(
o_t: Option<T>, op: fn(T) -> Result<V,U>) -> Result<Option<V>,U> {
match o_t {
* used in 'careful' code contexts where it is both appropriate and easy
* to accommodate an error like the vectors being of different lengths.
*/
-fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T],
+fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
op: fn(S,T) -> Result<V,U>) -> Result<~[V],U> {
assert vec::same_length(ss, ts);
* error. This could be implemented using `map2()` but it is more efficient
* on its own as no result vector is built.
*/
-fn iter_vec2<S,T,U:copy>(ss: &[S], ts: &[T],
+fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
op: fn(S,T) -> Result<(),U>) -> Result<(),U> {
assert vec::same_length(ss, ts);
use hash::Hash;
use to_bytes::IterBytes;
-trait SendMap<K:Eq Hash, V: copy> {
+trait SendMap<K:Eq Hash, V: Copy> {
// FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy
fn insert(&mut self, +k: K, +v: V) -> bool;
}
}
- impl<K:Hash IterBytes Eq, V: copy> LinearMap<K,V> {
+ impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
fn find(&const self, k: &K) -> Option<V> {
match self.bucket_for_key(self.buckets, k) {
FoundEntry(idx) => {
}
- impl<K: Hash IterBytes Eq copy, V: copy> LinearMap<K,V> {
+ impl<K: Hash IterBytes Eq Copy, V: Copy> LinearMap<K,V> {
fn each(&self, blk: fn(+K,+V) -> bool) {
self.each_ref(|k,v| blk(copy *k, copy *v));
}
}
- impl<K: Hash IterBytes Eq copy, V> LinearMap<K,V> {
+ impl<K: Hash IterBytes Eq Copy, V> LinearMap<K,V> {
fn each_key(&self, blk: fn(+K) -> bool) {
self.each_key_ref(|k| blk(copy *k));
}
}
- impl<K: Hash IterBytes Eq, V: copy> LinearMap<K,V> {
+ impl<K: Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
fn each_value(&self, blk: fn(+V) -> bool) {
self.each_value_ref(|v| blk(copy *v));
}
spawn_raw(x.opts, x.gen_body(f));
}
/// Runs a task, while transfering ownership of one argument to the child.
- fn spawn_with<A: send>(+arg: A, +f: fn~(+A)) {
+ fn spawn_with<A: Send>(+arg: A, +f: fn~(+A)) {
let arg = ~mut Some(arg);
do self.spawn {
f(option::swap_unwrap(arg))
* otherwise be required to establish communication from the parent
* to the child.
*/
- fn spawn_listener<A: send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
+ fn spawn_listener<A: Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
let setup_po = comm::Port();
let setup_ch = comm::Chan(setup_po);
do self.spawn {
/**
* Runs a new task, setting up communication in both directions
*/
- fn spawn_conversation<A: send, B: send>
+ fn spawn_conversation<A: Send, B: Send>
(+f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::Port<B>, comm::Chan<A>) {
let from_child = comm::Port();
* # Failure
* Fails if a future_result was already set for this task.
*/
- fn try<T: send>(+f: fn~() -> T) -> Result<T,()> {
+ fn try<T: Send>(+f: fn~() -> T) -> Result<T,()> {
let po = comm::Port();
let ch = comm::Chan(po);
let mut result = None;
task().supervised().spawn(f)
}
-fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
+fn spawn_with<A:Send>(+arg: A, +f: fn~(+A)) {
/*!
* Runs a task, while transfering ownership of one argument to the
* child.
task().spawn_with(arg, f)
}
-fn spawn_listener<A:send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
+fn spawn_listener<A:Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
/*!
* Runs a new task while providing a channel from the parent to the child
*
task().spawn_listener(f)
}
-fn spawn_conversation<A: send, B: send>
+fn spawn_conversation<A: Send, B: Send>
(+f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::Port<B>, comm::Chan<A>) {
/*!
task().sched_mode(mode).spawn(f)
}
-fn try<T:send>(+f: fn~() -> T) -> Result<T,()> {
+fn try<T:Send>(+f: fn~() -> T) -> Result<T,()> {
/*!
* Execute a function in another task and return either the return value
* of the function or result::err.
*
* These two cases aside, the interface is safe.
*/
-type LocalDataKey<T: owned> = &fn(+@T);
+type LocalDataKey<T: Owned> = &fn(+@T);
trait LocalData { }
-impl<T: owned> @T: LocalData { }
+impl<T: Owned> @T: LocalData { }
impl LocalData: Eq {
pure fn eq(&&other: LocalData) -> bool unsafe {
}
}
-unsafe fn key_to_key_value<T: owned>(
+unsafe fn key_to_key_value<T: Owned>(
key: LocalDataKey<T>) -> *libc::c_void {
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
}
// If returning Some(..), returns with @T with the map's reference. Careful!
-unsafe fn local_data_lookup<T: owned>(
+unsafe fn local_data_lookup<T: Owned>(
map: TaskLocalMap, key: LocalDataKey<T>)
-> Option<(uint, *libc::c_void)> {
}
}
-unsafe fn local_get_helper<T: owned>(
+unsafe fn local_get_helper<T: Owned>(
task: *rust_task, key: LocalDataKey<T>,
do_pop: bool) -> Option<@T> {
}
}
-unsafe fn local_pop<T: owned>(
+unsafe fn local_pop<T: Owned>(
task: *rust_task,
key: LocalDataKey<T>) -> Option<@T> {
local_get_helper(task, key, true)
}
-unsafe fn local_get<T: owned>(
+unsafe fn local_get<T: Owned>(
task: *rust_task,
key: LocalDataKey<T>) -> Option<@T> {
local_get_helper(task, key, false)
}
-unsafe fn local_set<T: owned>(
+unsafe fn local_set<T: Owned>(
task: *rust_task, key: LocalDataKey<T>, +data: @T) {
let map = get_task_local_map(task);
}
}
-unsafe fn local_modify<T: owned>(
+unsafe fn local_modify<T: Owned>(
task: *rust_task, key: LocalDataKey<T>,
modify_fn: fn(Option<@T>) -> Option<@T>) {
* Remove a task-local data value from the table, returning the
* reference that was originally created to insert it.
*/
-unsafe fn local_data_pop<T: owned>(
+unsafe fn local_data_pop<T: Owned>(
key: LocalDataKey<T>) -> Option<@T> {
local_pop(rustrt::rust_get_task(), key)
* Retrieve a task-local data value. It will also be kept alive in the
* table until explicitly removed.
*/
-unsafe fn local_data_get<T: owned>(
+unsafe fn local_data_get<T: Owned>(
key: LocalDataKey<T>) -> Option<@T> {
local_get(rustrt::rust_get_task(), key)
* Store a value in task-local data. If this key already has a value,
* that value is overwritten (and its destructor is run).
*/
-unsafe fn local_data_set<T: owned>(
+unsafe fn local_data_set<T: Owned>(
key: LocalDataKey<T>, +data: @T) {
local_set(rustrt::rust_get_task(), key, data)
* Modify a task-local data value. If the function returns 'none', the
* data is removed (and its reference dropped).
*/
-unsafe fn local_data_modify<T: owned>(
+unsafe fn local_data_modify<T: Owned>(
key: LocalDataKey<T>,
modify_fn: fn(Option<@T>) -> Option<@T>) {
fn to_str() -> ~str { str::from_slice(self) }
}
-impl<A: ToStr copy, B: ToStr copy> (A, B): ToStr {
+impl<A: ToStr Copy, B: ToStr Copy> (A, B): ToStr {
fn to_str() -> ~str {
let (a, b) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
}
}
-impl<A: ToStr copy, B: ToStr copy, C: ToStr copy> (A, B, C): ToStr {
+impl<A: ToStr Copy, B: ToStr Copy, C: ToStr Copy> (A, B, C): ToStr {
fn to_str() -> ~str {
let (a, b, c) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
pure fn swap() -> (U, T);
}
-impl<T: copy, U: copy> (T, U): TupleOps<T,U> {
+impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> {
/// Return the first element of self
pure fn first() -> T {
fn map<C>(f: fn(A, B) -> C) -> ~[C];
}
-impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
+impl<A: Copy, B: Copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
fn zip() -> ~[(A, B)] {
let (a, b) = self;
}
}
-impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
+impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
fn zip() -> ~[(A, B)] {
// XXX: Bad copy
}
}
-unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
+unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
-> T {
struct DeathThroes<T> {
mut ptr: Option<~ArcData<T>>,
* Data races between tasks can result in crashes and, with sufficient
* cleverness, arbitrary type coercion.
*/
-type SharedMutableState<T: send> = ArcDestruct<T>;
+type SharedMutableState<T: Send> = ArcDestruct<T>;
-unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
+unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> {
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
unsafe {
let ptr = unsafe::transmute(data);
}
#[inline(always)]
-unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
+unsafe fn get_shared_mutable_state<T: Send>(rc: &a/SharedMutableState<T>)
-> &a/mut T {
unsafe {
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
}
}
#[inline(always)]
-unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
+unsafe fn get_shared_immutable_state<T: Send>(rc: &a/SharedMutableState<T>)
-> &a/T {
unsafe {
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
}
}
-unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
+unsafe fn clone_shared_mutable_state<T: Send>(rc: &SharedMutableState<T>)
-> SharedMutableState<T> {
unsafe {
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
}
}
-struct ExData<T: send> { lock: LittleLock, mut failed: bool, mut data: T, }
+struct ExData<T: Send> { lock: LittleLock, mut failed: bool, mut data: T, }
/**
* An arc over mutable data that is protected by a lock. For library use only.
*/
-struct Exclusive<T: send> { x: SharedMutableState<ExData<T>> }
+struct Exclusive<T: Send> { x: SharedMutableState<ExData<T>> }
-fn exclusive<T:send >(+user_data: T) -> Exclusive<T> {
+fn exclusive<T:Send >(+user_data: T) -> Exclusive<T> {
let data = ExData {
lock: LittleLock(), mut failed: false, mut data: user_data
};
Exclusive { x: unsafe { shared_mutable_state(data) } }
}
-impl<T: send> Exclusive<T> {
+impl<T: Send> Exclusive<T> {
// Duplicate an exclusive ARC, as std::arc::clone.
fn clone() -> Exclusive<T> {
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
}
// FIXME(#2585) make this a by-move method on the exclusive
-fn unwrap_exclusive<T: send>(+arc: Exclusive<T>) -> T {
+fn unwrap_exclusive<T: Send>(+arc: Exclusive<T>) -> T {
let Exclusive { x: x } = arc;
let inner = unsafe { unwrap_shared_mutable_state(x) };
let ExData { data: data, _ } = inner;
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
/// original value of `*ptr`.
#[inline(always)]
-fn with<T: copy, R>(
+fn with<T: Copy, R>(
ptr: &mut T,
+new_value: T,
op: &fn() -> R) -> R
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
-pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
+pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T] {
let mut v = ~[];
unchecked{reserve(v, n_elts)}
let mut i: uint = 0u;
}
/// Creates a new unique vector with the same contents as the slice
-pure fn from_slice<T: copy>(t: &[T]) -> ~[T] {
+pure fn from_slice<T: Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}
// Accessors
/// Returns the first element of a vector
-pure fn head<T: copy>(v: &[const T]) -> T { v[0] }
+pure fn head<T: Copy>(v: &[const T]) -> T { v[0] }
/// Returns a vector containing all but the first element of a slice
-pure fn tail<T: copy>(v: &[const T]) -> ~[T] {
+pure fn tail<T: Copy>(v: &[const T]) -> ~[T] {
return slice(v, 1u, len(v));
}
* Returns a vector containing all but the first `n` \
* elements of a slice
*/
-pure fn tailn<T: copy>(v: &[const T], n: uint) -> ~[T] {
+pure fn tailn<T: Copy>(v: &[const T], n: uint) -> ~[T] {
slice(v, n, len(v))
}
/// Returns a vector containing all but the last element of a slice
-pure fn init<T: copy>(v: &[const T]) -> ~[T] {
+pure fn init<T: Copy>(v: &[const T]) -> ~[T] {
assert len(v) != 0u;
slice(v, 0u, len(v) - 1u)
}
/// Returns the last element of the slice `v`, failing if the slice is empty.
-pure fn last<T: copy>(v: &[const T]) -> T {
+pure fn last<T: Copy>(v: &[const T]) -> T {
if len(v) == 0u { fail ~"last_unsafe: empty vector" }
v[len(v) - 1u]
}
* Returns `Some(x)` where `x` is the last element of the slice `v`,
* or `none` if the vector is empty.
*/
-pure fn last_opt<T: copy>(v: &[const T]) -> Option<T> {
+pure fn last_opt<T: Copy>(v: &[const T]) -> Option<T> {
if len(v) == 0u { return None; }
Some(v[len(v) - 1u])
}
/// Returns a copy of the elements from [`start`..`end`) from `v`.
-pure fn slice<T: copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
+pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
assert (start <= end);
assert (end <= len(v));
let mut result = ~[];
}
/// Split the vector `v` by applying each element against the predicate `f`.
-fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
+fn split<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
* Split the vector `v` by applying each element against the predicate `f` up
* to `n` times.
*/
-fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
+fn splitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
* Reverse split the vector `v` by applying each element against the predicate
* `f`.
*/
-fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
+fn rsplit<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
* Reverse split the vector `v` by applying each element against the predicate
* `f` up to `n times.
*/
-fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
+fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
}
#[inline(always)]
-fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
+fn push_all<T: Copy>(&v: ~[const T], rhs: &[const T]) {
reserve(v, v.len() + rhs.len());
for uint::range(0u, rhs.len()) |i| {
// Appending
#[inline(always)]
-pure fn append<T: copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
+pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
let mut v <- lhs;
unchecked {
push_all(v, rhs);
}
#[inline(always)]
-pure fn append_mut<T: copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
+pure fn append_mut<T: Copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
let mut v = ~[mut];
let mut i = 0u;
while i < lhs.len() {
* * n - The number of elements to add
* * initval - The value for the new elements
*/
-fn grow<T: copy>(&v: ~[const T], n: uint, initval: T) {
+fn grow<T: Copy>(&v: ~[const T], n: uint, initval: T) {
reserve_at_least(v, len(v) + n);
let mut i: uint = 0u;
* of the vector, expands the vector by replicating `initval` to fill the
* intervening space.
*/
-fn grow_set<T: copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
+fn grow_set<T: Copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
v[index] = val;
}
}
/// Apply a function to each pair of elements and return the results
-pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
+pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U],
f: fn(T, U) -> V) -> ~[V] {
let v0_len = len(v0);
if v0_len != len(v1) { fail; }
* If function `f` returns `none` then that element is excluded from
* the resulting vector.
*/
-pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> Option<U>)
+pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
-> ~[U] {
let mut result = ~[];
for each(v) |elem| {
* Apply function `f` to each element of `v` and return a vector containing
* only those elements for which `f` returned true.
*/
-pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
+pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) |elem| {
if f(elem) { unsafe { push(result, elem); } }
*
* Flattens a vector of vectors of T into a single vector of T.
*/
-pure fn concat<T: copy>(v: &[~[T]]) -> ~[T] {
+pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] {
let mut r = ~[];
for each(v) |inner| { unsafe { push_all(r, inner); } }
return r;
}
/// Concatenate a vector of vectors, placing a given separator between each
-pure fn connect<T: copy>(v: &[~[T]], sep: T) -> ~[T] {
+pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
let mut r: ~[T] = ~[];
let mut first = true;
for each(v) |inner| {
}
/// Reduce a vector from left to right
-pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
+pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
let mut accum = z;
do iter(v) |elt| {
accum = p(accum, elt);
}
/// Reduce a vector from right to left
-pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
+pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
let mut accum = z;
do riter(v) |elt| {
accum = p(elt, accum);
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
-pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
+pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
find_between(v, 0u, len(v), f)
}
* [`start`, `end`). When function `f` returns true then an option containing
* the element is returned. If `f` matches no elements then none is returned.
*/
-pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
+pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
f: fn(T) -> bool) -> Option<T> {
option::map(position_between(v, start, end, f), |i| v[i])
}
* `f` returns true then an option containing the element is returned. If `f`
* matches no elements then none is returned.
*/
-pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
+pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
rfind_between(v, 0u, len(v), f)
}
* [`start`, `end`). When function `f` returns true then an option containing
* the element is returned. If `f` matches no elements then none is returned.
*/
-pure fn rfind_between<T: copy>(v: &[T], start: uint, end: uint,
+pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint,
f: fn(T) -> bool) -> Option<T> {
option::map(rposition_between(v, start, end, f), |i| v[i])
}
/**
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
*/
-pure fn unzip_slice<T: copy, U: copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
+pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
let mut as = ~[], bs = ~[];
for each(v) |p| {
let (a, b) = p;
/**
* Convert two vectors to a vector of pairs, by reference. As zip().
*/
-pure fn zip_slice<T: copy, U: copy>(v: &[const T], u: &[const U])
+pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U])
-> ~[(T, U)] {
let mut zipped = ~[];
let sz = len(v);
/// Returns a vector with the order of elements reversed
-pure fn reversed<T: copy>(v: &[const T]) -> ~[T] {
+pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
let mut rs: ~[T] = ~[];
let mut i = len::<T>(v);
if i == 0u { return rs; } else { i -= 1u; }
* The total number of permutations produced is `len(v)!`. If `v` contains
* repeated elements, then some permutations are repeated.
*/
-pure fn permute<T: copy>(v: &[const T], put: fn(~[T])) {
+pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) {
let ln = len(v);
if ln == 0u {
put(~[]);
}
}
-pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
+pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
let mut ww = ~[];
assert 1u <= nn;
vec::iteri (xx, |ii, _x| {
}
#[cfg(notest)]
-impl<T: copy> ~[T]: Add<&[const T],~[T]> {
+impl<T: Copy> ~[T]: Add<&[const T],~[T]> {
#[inline(always)]
pure fn add(rhs: &[const T]) -> ~[T] {
append(copy self, rhs)
}
}
-impl<T: copy> ~[mut T]: Add<&[const T],~[mut T]> {
+impl<T: Copy> ~[mut T]: Add<&[const T],~[mut T]> {
#[inline(always)]
pure fn add(rhs: &[const T]) -> ~[mut T] {
append_mut(self, rhs)
}
/// Extension methods for vectors
-impl<T: copy> &[const T]: CopyableVector<T> {
+impl<T: Copy> &[const T]: CopyableVector<T> {
/// Returns the first element of a vector
#[inline]
pure fn head() -> T { head(self) }
}
trait ImmutableVector<T> {
- pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U;
+ pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
pure fn iter(f: fn(T));
pure fn iteri(f: fn(uint, T));
pure fn riter(f: fn(T));
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
pure fn alli(f: fn(uint, T) -> bool) -> bool;
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U];
- pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U];
+ pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U];
}
trait ImmutableEqVector<T: Eq> {
impl<T> &[T]: ImmutableVector<T> {
/// Reduce a vector from right to left
#[inline]
- pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
+ pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
/**
* Iterates over a vector
*
* the resulting vector.
*/
#[inline]
- pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U] {
+ pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U] {
filter_map(self, f)
}
}
}
/// Extension methods for vectors
-impl<T: copy> &[T]: ImmutableCopyableVector<T> {
+impl<T: Copy> &[T]: ImmutableCopyableVector<T> {
/**
* Construct a new vector from the elements of a vector for which some
* predicate holds.
* Unchecked vector indexing.
*/
#[inline(always)]
- unsafe fn get<T: copy>(v: &[const T], i: uint) -> T {
+ unsafe fn get<T: Copy>(v: &[const T], i: uint) -> T {
as_buf(v, |p, _len| *ptr::offset(p, i))
}
}
}
-impl<A: copy> &[A]: iter::CopyableIter<A> {
+impl<A: Copy> &[A]: iter::CopyableIter<A> {
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
}
-impl<A: copy Ord> &[A]: iter::CopyableOrderedIter<A> {
+impl<A: Copy Ord> &[A]: iter::CopyableOrderedIter<A> {
pure fn min() -> A { iter::min(self) }
pure fn max() -> A { iter::max(self) }
}
****************************************************************************/
/// An atomically reference counted wrapper for shared immutable state.
-struct ARC<T: const send> { x: SharedMutableState<T> }
+struct ARC<T: Const Send> { x: SharedMutableState<T> }
/// Create an atomically reference counted wrapper.
-fn ARC<T: const send>(+data: T) -> ARC<T> {
+fn ARC<T: Const Send>(+data: T) -> ARC<T> {
ARC { x: unsafe { shared_mutable_state(data) } }
}
* Access the underlying data in an atomically reference counted
* wrapper.
*/
-fn get<T: const send>(rc: &a/ARC<T>) -> &a/T {
+fn get<T: Const Send>(rc: &a/ARC<T>) -> &a/T {
unsafe { get_shared_immutable_state(&rc.x) }
}
* object. However, one of the `arc` objects can be sent to another task,
* allowing them to share the underlying data.
*/
-fn clone<T: const send>(rc: &ARC<T>) -> ARC<T> {
+fn clone<T: Const Send>(rc: &ARC<T>) -> ARC<T> {
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
}
* unwrap from a task that holds another reference to the same ARC; it is
* guaranteed to deadlock.
*/
-fn unwrap<T: const send>(+rc: ARC<T>) -> T {
+fn unwrap<T: Const Send>(+rc: ARC<T>) -> T {
let ARC { x: x } = rc;
unsafe { unwrap_shared_mutable_state(x) }
}
****************************************************************************/
#[doc(hidden)]
-struct MutexARCInner<T: send> { lock: Mutex, failed: bool, data: T }
+struct MutexARCInner<T: Send> { lock: Mutex, failed: bool, data: T }
/// An ARC with mutable data protected by a blocking mutex.
-struct MutexARC<T: send> { x: SharedMutableState<MutexARCInner<T>> }
+struct MutexARC<T: Send> { x: SharedMutableState<MutexARCInner<T>> }
/// Create a mutex-protected ARC with the supplied data.
-fn MutexARC<T: send>(+user_data: T) -> MutexARC<T> {
+fn MutexARC<T: Send>(+user_data: T) -> MutexARC<T> {
mutex_arc_with_condvars(user_data, 1)
}
/**
* Create a mutex-protected ARC with the supplied data and a specified number
* of condvars (as sync::mutex_with_condvars).
*/
-fn mutex_arc_with_condvars<T: send>(+user_data: T,
+fn mutex_arc_with_condvars<T: Send>(+user_data: T,
num_condvars: uint) -> MutexARC<T> {
let data =
MutexARCInner { lock: mutex_with_condvars(num_condvars),
MutexARC { x: unsafe { shared_mutable_state(data) } }
}
-impl<T: send> &MutexARC<T> {
+impl<T: Send> &MutexARC<T> {
/// Duplicate a mutex-protected ARC, as arc::clone.
fn clone() -> MutexARC<T> {
// NB: Cloning the underlying mutex is not necessary. Its reference
* Will additionally fail if another task has failed while accessing the arc.
*/
// FIXME(#2585) make this a by-move method on the arc
-fn unwrap_mutex_arc<T: send>(+arc: MutexARC<T>) -> T {
+fn unwrap_mutex_arc<T: Send>(+arc: MutexARC<T>) -> T {
let MutexARC { x: x } = arc;
let inner = unsafe { unwrap_shared_mutable_state(x) };
let MutexARCInner { failed: failed, data: data, _ } = inner;
****************************************************************************/
#[doc(hidden)]
-struct RWARCInner<T: const send> { lock: RWlock, failed: bool, data: T }
+struct RWARCInner<T: Const Send> { lock: RWlock, failed: bool, data: T }
/**
* A dual-mode ARC protected by a reader-writer lock. The data can be accessed
* mutably or immutably, and immutably-accessing tasks may run concurrently.
*
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
*/
-struct RWARC<T: const send> {
+struct RWARC<T: Const Send> {
x: SharedMutableState<RWARCInner<T>>,
mut cant_nest: ()
}
/// Create a reader/writer ARC with the supplied data.
-fn RWARC<T: const send>(+user_data: T) -> RWARC<T> {
+fn RWARC<T: Const Send>(+user_data: T) -> RWARC<T> {
rw_arc_with_condvars(user_data, 1)
}
/**
* Create a reader/writer ARC with the supplied data and a specified number
* of condvars (as sync::rwlock_with_condvars).
*/
-fn rw_arc_with_condvars<T: const send>(+user_data: T,
+fn rw_arc_with_condvars<T: Const Send>(+user_data: T,
num_condvars: uint) -> RWARC<T> {
let data =
RWARCInner { lock: rwlock_with_condvars(num_condvars),
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
}
-impl<T: const send> &RWARC<T> {
+impl<T: Const Send> &RWARC<T> {
/// Duplicate a rwlock-protected ARC, as arc::clone.
fn clone() -> RWARC<T> {
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
* in write mode.
*/
// FIXME(#2585) make this a by-move method on the arc
-fn unwrap_rw_arc<T: const send>(+arc: RWARC<T>) -> T {
+fn unwrap_rw_arc<T: Const Send>(+arc: RWARC<T>) -> T {
let RWARC { x: x, _ } = arc;
let inner = unsafe { unwrap_shared_mutable_state(x) };
let RWARCInner { failed: failed, data: data, _ } = inner;
// lock it. This wraps the unsafety, with the justification that the 'lock'
// field is never overwritten; only 'failed' and 'data'.
#[doc(hidden)]
-fn borrow_rwlock<T: const send>(state: &r/mut RWARCInner<T>) -> &r/RWlock {
+fn borrow_rwlock<T: Const Send>(state: &r/mut RWARCInner<T>) -> &r/RWlock {
unsafe { unsafe::transmute_immut(&mut state.lock) }
}
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
/// The "write permission" token used for RWARC.write_downgrade().
-enum RWWriteMode<T: const send> =
+enum RWWriteMode<T: Const Send> =
(&mut T, sync::RWlockWriteMode, PoisonOnFail);
/// The "read permission" token used for RWARC.write_downgrade().
-enum RWReadMode<T:const send> = (&T, sync::RWlockReadMode);
+enum RWReadMode<T:Const Send> = (&T, sync::RWlockReadMode);
-impl<T: const send> &RWWriteMode<T> {
+impl<T: Const Send> &RWWriteMode<T> {
/// Access the pre-downgrade RWARC in write mode.
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
match *self {
}
}
-impl<T: const send> &RWReadMode<T> {
+impl<T: Const Send> &RWReadMode<T> {
/// Access the post-downgrade rwlock in read mode.
fn read<U>(blk: fn(x: &T) -> U) -> U {
match *self {
*
* Fails if `ofs` is greater or equal to the length of the vector
*/
-fn get<T: copy>(t: CVec<T>, ofs: uint) -> T {
+fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
assert ofs < len(t);
return unsafe { *ptr::mut_offset((*t).base, ofs) };
}
*
* Fails if `ofs` is greater or equal to the length of the vector
*/
-fn set<T: copy>(t: CVec<T>, ofs: uint, v: T) {
+fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
assert ofs < len(t);
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
}
export DuplexStream;
/// An extension of `pipes::stream` that allows both sending and receiving.
-struct DuplexStream<T: send, U: send> : Channel<T>, Recv<U>, Selectable {
+struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
priv chan: Chan<T>,
priv port: Port <U>,
}
/// Creates a bidirectional stream.
-fn DuplexStream<T: send, U: send>()
+fn DuplexStream<T: Send, U: Send>()
-> (DuplexStream<T, U>, DuplexStream<U, T>)
{
let (c2, p1) = pipes::stream();
// FIXME (#2343) eventually, a proper datatype plus an exported impl would
// be preferrable.
-fn create<T: copy>() -> Deque<T> {
+fn create<T: Copy>() -> Deque<T> {
type Cell<T> = Option<T>;
let initial_capacity: uint = 32u; // 2^5
* Grow is only called on full elts, so nelts is also len(elts), unlike
* elsewhere.
*/
- fn grow<T: copy>(nelts: uint, lo: uint, -elts: ~[mut Cell<T>]) ->
+ fn grow<T: Copy>(nelts: uint, lo: uint, -elts: ~[mut Cell<T>]) ->
~[mut Cell<T>] {
assert (nelts == vec::len(elts));
let mut rv = ~[mut];
return rv;
}
- fn get<T: copy>(elts: DVec<Cell<T>>, i: uint) -> T {
+ fn get<T: Copy>(elts: DVec<Cell<T>>, i: uint) -> T {
match elts.get_elt(i) { Some(t) => t, _ => fail }
}
mut hi: uint,
elts: DVec<Cell<T>>};
- impl <T: copy> Repr<T>: Deque<T> {
+ impl <T: Copy> Repr<T>: Deque<T> {
fn size() -> uint { return self.nelts; }
fn add_front(t: T) {
let oldlo: uint = self.lo;
type EqFn<T> = fn@(T, T) -> bool;
- fn test_parameterized<T: copy owned>(
+ fn test_parameterized<T: Copy Owned>(
e: EqFn<T>, a: T, b: T, c: T, d: T) {
let deq: deque::Deque<T> = deque::create::<T>();
fn init<K, V>() -> Treemap<K, V> { @Empty }
/// Insert a value into the map
-fn insert<K: copy Eq Ord, V: copy>(m: Treemap<K, V>, +k: K, +v: V)
+fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K, +v: V)
-> Treemap<K, V> {
@match m {
@Empty => Node(@k, @v, @Empty, @Empty),
}
/// Find a value based on the key
-fn find<K: Eq Ord, V: copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
+fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
match *m {
Empty => None,
Node(@kk, @v, left, right) => {
}
/// Visit all pairs in the map in order.
-fn traverse<K, V: copy>(m: Treemap<K, V>, f: fn(K, V)) {
+fn traverse<K, V: Copy>(m: Treemap<K, V>, f: fn(K, V)) {
match *m {
Empty => (),
/*
fn to_json() -> Json { List(@self.map(|elt| elt.to_json())) }
}
-impl <A: ToJson copy> hashmap<~str, A>: ToJson {
+impl <A: ToJson Copy> hashmap<~str, A>: ToJson {
fn to_json() -> Json {
let d = map::str_hash();
for self.each() |key, value| {
}
/// Cregate a list from a vector
-fn from_vec<T: copy>(v: &[T]) -> @List<T> {
+fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
vec::foldr(v, @Nil::<T>, |h, t| @Cons(h, t))
}
* * z - The initial value
* * f - The function to apply
*/
-fn foldl<T: copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
+fn foldl<T: Copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
let mut accum: T = z;
do iter(ls) |elt| { accum = f(&accum, &elt);}
accum
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
-fn find<T: copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
+fn find<T: Copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
}
/// Returns true if a list contains an element with the given value
-fn has<T: copy Eq>(ls: @List<T>, +elt: T) -> bool {
+fn has<T: Copy Eq>(ls: @List<T>, +elt: T) -> bool {
for each(ls) |e| {
if e == elt { return true; }
}
}
/// Returns true if the list is empty
-pure fn is_empty<T: copy>(ls: @List<T>) -> bool {
+pure fn is_empty<T: Copy>(ls: @List<T>) -> bool {
match *ls {
Nil => true,
_ => false
}
/// Returns true if the list is not empty
-pure fn is_not_empty<T: copy>(ls: @List<T>) -> bool {
+pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
return !is_empty(ls);
}
}
/// Returns all but the first element of a list
-pure fn tail<T: copy>(ls: @List<T>) -> @List<T> {
+pure fn tail<T: Copy>(ls: @List<T>) -> @List<T> {
match *ls {
Cons(_, tl) => return tl,
Nil => fail ~"list empty"
}
/// Returns the first element of a list
-pure fn head<T: copy>(ls: @List<T>) -> T {
+pure fn head<T: Copy>(ls: @List<T>) -> T {
match *ls {
Cons(hd, _) => hd,
// makes me sad
}
/// Appends one list to another
-pure fn append<T: copy>(l: @List<T>, m: @List<T>) -> @List<T> {
+pure fn append<T: Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l {
Nil => return m,
Cons(x, xs) => {
/*
/// Push one element into the front of a list, returning a new list
/// THIS VERSION DOESN'T ACTUALLY WORK
-pure fn push<T: copy>(ll: &mut @list<T>, +vv: T) {
+pure fn push<T: Copy>(ll: &mut @list<T>, +vv: T) {
ll = &mut @cons(vv, *ll)
}
*/
type hashmap<K:Eq IterBytes Hash, V> = chained::t<K, V>;
-trait map<K:Eq IterBytes Hash copy, V: copy> {
+trait map<K:Eq IterBytes Hash Copy, V: Copy> {
/// Return the number of elements in the map
pure fn size() -> uint;
found_after(@entry<K,V>, @entry<K,V>)
}
- priv impl<K:Eq IterBytes Hash, V: copy> t<K, V> {
+ priv impl<K:Eq IterBytes Hash, V: Copy> t<K, V> {
pure fn search_rem(k: &K, h: uint, idx: uint,
e_root: @entry<K,V>) -> search_result<K,V> {
let mut e0 = e_root;
}
}
- impl<K:Eq IterBytes Hash copy, V: copy> t<K, V>: map<K, V> {
+ impl<K:Eq IterBytes Hash Copy, V: Copy> t<K, V>: map<K, V> {
pure fn size() -> uint { self.count }
fn contains_key(+k: K) -> bool {
}
}
- impl<K:Eq IterBytes Hash copy ToStr, V: ToStr copy> t<K, V>: ToStr {
+ impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> t<K, V>: ToStr {
fn to_writer(wr: io::Writer) {
if self.count == 0u {
wr.write_str(~"{}");
}
}
- impl<K:Eq IterBytes Hash copy, V: copy> t<K, V>: ops::Index<K, V> {
+ impl<K:Eq IterBytes Hash Copy, V: Copy> t<K, V>: ops::Index<K, V> {
pure fn index(&&k: K) -> V {
unchecked {
self.get(k)
vec::to_mut(vec::from_elem(nchains, None))
}
- fn mk<K:Eq IterBytes Hash, V: copy>() -> t<K,V> {
+ fn mk<K:Eq IterBytes Hash, V: Copy>() -> t<K,V> {
let slf: t<K, V> = @hashmap_ {count: 0u,
chains: chains(initial_capacity)};
slf
Construct a hashmap.
*/
-fn hashmap<K:Eq IterBytes Hash const, V: copy>()
+fn hashmap<K:Eq IterBytes Hash Const, V: Copy>()
-> hashmap<K, V> {
chained::mk()
}
/// Construct a hashmap for string-slice keys
-fn str_slice_hash<V: copy>() -> hashmap<&str, V> {
+fn str_slice_hash<V: Copy>() -> hashmap<&str, V> {
return hashmap();
}
/// Construct a hashmap for string keys
-fn str_hash<V: copy>() -> hashmap<~str, V> {
+fn str_hash<V: Copy>() -> hashmap<~str, V> {
return hashmap();
}
/// Construct a hashmap for boxed string keys
-fn box_str_hash<V: copy>() -> hashmap<@~str, V> {
+fn box_str_hash<V: Copy>() -> hashmap<@~str, V> {
hashmap()
}
/// Construct a hashmap for byte string keys
-fn bytes_hash<V: copy>() -> hashmap<~[u8], V> {
+fn bytes_hash<V: Copy>() -> hashmap<~[u8], V> {
return hashmap();
}
/// Construct a hashmap for int keys
-fn int_hash<V: copy>() -> hashmap<int, V> {
+fn int_hash<V: Copy>() -> hashmap<int, V> {
return hashmap();
}
/// Construct a hashmap for uint keys
-fn uint_hash<V: copy>() -> hashmap<uint, V> {
+fn uint_hash<V: Copy>() -> hashmap<uint, V> {
return hashmap();
}
/// Convenience function for adding keys to a hashmap with nil type keys
-fn set_add<K:Eq IterBytes Hash const copy>(set: set<K>, +key: K) -> bool {
+fn set_add<K:Eq IterBytes Hash Const Copy>(set: set<K>, +key: K) -> bool {
set.insert(key, ())
}
/// Convert a set into a vector.
-fn vec_from_set<T:Eq IterBytes Hash copy>(s: set<T>) -> ~[T] {
+fn vec_from_set<T:Eq IterBytes Hash Copy>(s: set<T>) -> ~[T] {
let mut v = ~[];
vec::reserve(v, s.size());
do s.each_key() |k| {
}
/// Construct a hashmap from a vector
-fn hash_from_vec<K: Eq IterBytes Hash const copy, V: copy>(
+fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
items: &[(K, V)]) -> hashmap<K, V> {
let map = hashmap();
do vec::iter(items) |item| {
}
/// Construct a hashmap from a vector with string keys
-fn hash_from_strs<V: copy>(items: &[(~str, V)]) -> hashmap<~str, V> {
+fn hash_from_strs<V: Copy>(items: &[(~str, V)]) -> hashmap<~str, V> {
hash_from_vec(items)
}
/// Construct a hashmap from a vector with byte keys
-fn hash_from_bytes<V: copy>(items: &[(~[u8], V)]) -> hashmap<~[u8], V> {
+fn hash_from_bytes<V: Copy>(items: &[(~[u8], V)]) -> hashmap<~[u8], V> {
hash_from_vec(items)
}
/// Construct a hashmap from a vector with int keys
-fn hash_from_ints<V: copy>(items: &[(int, V)]) -> hashmap<int, V> {
+fn hash_from_ints<V: Copy>(items: &[(int, V)]) -> hashmap<int, V> {
hash_from_vec(items)
}
/// Construct a hashmap from a vector with uint keys
-fn hash_from_uints<V: copy>(items: &[(uint, V)]) -> hashmap<uint, V> {
+fn hash_from_uints<V: Copy>(items: &[(uint, V)]) -> hashmap<uint, V> {
hash_from_vec(items)
}
// XXX Transitional
-impl<K: Eq IterBytes Hash copy, V: copy> Managed<LinearMap<K, V>>:
+impl<K: Eq IterBytes Hash Copy, V: Copy> Managed<LinearMap<K, V>>:
map<K, V> {
pure fn size() -> uint {
unchecked {
* This is used to build most of the other parallel vector functions,
* like map or alli.
*/
-fn map_slices<A: copy send, B: copy send>(
+fn map_slices<A: Copy Send, B: Copy Send>(
xs: &[A],
f: fn() -> fn~(uint, v: &[A]) -> B)
-> ~[B] {
}
/// A parallel version of map.
-fn map<A: copy send, B: copy send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
+fn map<A: Copy Send, B: Copy Send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
vec::concat(map_slices(xs, || {
fn~(_base: uint, slice : &[A], copy f) -> ~[B] {
vec::map(slice, |x| f(x))
}
/// A parallel version of mapi.
-fn mapi<A: copy send, B: copy send>(xs: ~[A],
+fn mapi<A: Copy Send, B: Copy Send>(xs: ~[A],
f: fn~(uint, A) -> B) -> ~[B] {
let slices = map_slices(xs, || {
fn~(base: uint, slice : &[A], copy f) -> ~[B] {
* In this case, f is a function that creates functions to run over the
* inner elements. This is to skirt the need for copy constructors.
*/
-fn mapi_factory<A: copy send, B: copy send>(
+fn mapi_factory<A: Copy Send, B: Copy Send>(
xs: &[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] {
let slices = map_slices(xs, || {
let f = f();
}
/// Returns true if the function holds for all elements in the vector.
-fn alli<A: copy send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool {
+fn alli<A: Copy Send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool {
do vec::all(map_slices(xs, || {
fn~(base: uint, slice : &[A], copy f) -> bool {
vec::alli(slice, |i, x| {
}
/// Returns true if the function holds for any elements in the vector.
-fn any<A: copy send>(xs: ~[A], f: fn~(A) -> bool) -> bool {
+fn any<A: Copy Send>(xs: ~[A], f: fn~(A) -> bool) -> bool {
do vec::any(map_slices(xs, || {
fn~(_base : uint, slice: &[A], copy f) -> bool {
vec::any(slice, |x| f(x))
}
}
-fn read_to_vec<D: deserializer, T: copy>(d: D, f: fn() -> T) -> ~[T] {
+fn read_to_vec<D: deserializer, T: Copy>(d: D, f: fn() -> T) -> ~[T] {
do d.read_vec |len| {
do vec::from_fn(len) |i| {
d.read_vec_elt(i, || f())
}
trait deserializer_helpers {
- fn read_to_vec<T: copy>(f: fn() -> T) -> ~[T];
+ fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T];
}
impl<D: deserializer> D: deserializer_helpers {
- fn read_to_vec<T: copy>(f: fn() -> T) -> ~[T] {
+ fn read_to_vec<T: Copy>(f: fn() -> T) -> ~[T] {
read_to_vec(self, f)
}
}
}
}
-fn deserialize_Option<D: deserializer,T: copy>(d: D, st: fn() -> T)
+fn deserialize_Option<D: deserializer,T: Copy>(d: D, st: fn() -> T)
-> Option<T> {
do d.read_enum(~"option") {
do d.read_enum_variant |i| {
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
// requires this to be.
-type SmallIntMap_<T: copy> = {v: DVec<Option<T>>};
+type SmallIntMap_<T: Copy> = {v: DVec<Option<T>>};
-enum SmallIntMap<T:copy> {
+enum SmallIntMap<T:Copy> {
SmallIntMap_(@SmallIntMap_<T>)
}
/// Create a smallintmap
-fn mk<T: copy>() -> SmallIntMap<T> {
+fn mk<T: Copy>() -> SmallIntMap<T> {
let v = DVec();
return SmallIntMap_(@{v: v});
}
* the specified key then the original value is replaced.
*/
#[inline(always)]
-fn insert<T: copy>(self: SmallIntMap<T>, key: uint, +val: T) {
+fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, +val: T) {
//io::println(fmt!("%?", key));
self.v.grow_set_elt(key, None, Some(val));
}
* Get the value for the specified key. If the key does not exist
* in the map then returns none
*/
-pure fn find<T: copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
+pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
if key < self.v.len() { return self.v.get_elt(key); }
return None::<T>;
}
*
* If the key does not exist in the map
*/
-pure fn get<T: copy>(self: SmallIntMap<T>, key: uint) -> T {
+pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T {
match find(self, key) {
None => {
error!("smallintmap::get(): key not present");
}
/// Returns true if the map contains a value for the specified key
-fn contains_key<T: copy>(self: SmallIntMap<T>, key: uint) -> bool {
+fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool {
return !option::is_none(find(self, key));
}
/// Implements the map::map interface for smallintmap
-impl<V: copy> SmallIntMap<V>: map::map<uint, V> {
+impl<V: Copy> SmallIntMap<V>: map::map<uint, V> {
pure fn size() -> uint {
let mut sz = 0u;
for self.v.each |item| {
}
}
-impl<V: copy> SmallIntMap<V>: ops::Index<uint, V> {
+impl<V: Copy> SmallIntMap<V>: ops::Index<uint, V> {
pure fn index(&&key: uint) -> V {
unchecked {
get(self, key)
}
/// Cast the given smallintmap to a map::map
-fn as_map<V: copy>(s: SmallIntMap<V>) -> map::map<uint, V> {
+fn as_map<V: Copy>(s: SmallIntMap<V>) -> map::map<uint, V> {
s as map::map::<uint, V>
}
* Has worst case O(n log n) performance, best case O(n), but
* is not space efficient. This is a stable sort.
*/
-fn merge_sort<T: copy>(le: Le<T>, v: &[const T]) -> ~[T] {
+fn merge_sort<T: Copy>(le: Le<T>, v: &[const T]) -> ~[T] {
type Slice = (uint, uint);
return merge_sort_(le, v, (0u, len(v)));
- fn merge_sort_<T: copy>(le: Le<T>, v: &[const T], slice: Slice)
+ fn merge_sort_<T: Copy>(le: Le<T>, v: &[const T], slice: Slice)
-> ~[T] {
let begin = slice.first();
let end = slice.second();
return merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b));
}
- fn merge<T: copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
+ fn merge<T: Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
let mut rs = ~[];
vec::reserve(rs, len(a) + len(b));
let a_len = len(a);
}
}
-fn part<T: copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
+fn part<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
right: uint, pivot: uint) -> uint {
let pivot_value = arr[pivot];
arr[pivot] <-> arr[right];
return storage_index;
}
-fn qsort<T: copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
+fn qsort<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
right: uint) {
if right > left {
let pivot = (left + right) / 2u;
* Has worst case O(n^2) performance, average case O(n log n).
* This is an unstable sort.
*/
-fn quick_sort<T: copy>(compare_func: Le<T>, arr: &[mut T]) {
+fn quick_sort<T: Copy>(compare_func: Le<T>, arr: &[mut T]) {
if len::<T>(arr) == 0u { return; }
qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u);
}
-fn qsort3<T: copy Ord Eq>(arr: &[mut T], left: int, right: int) {
+fn qsort3<T: Copy Ord Eq>(arr: &[mut T], left: int, right: int) {
if right <= left { return; }
let v: T = arr[right];
let mut i: int = left - 1;
*
* This is an unstable sort.
*/
-fn quick_sort3<T: copy Ord Eq>(arr: &[mut T]) {
+fn quick_sort3<T: Copy Ord Eq>(arr: &[mut T]) {
if arr.len() <= 1 { return; }
qsort3(arr, 0, (arr.len() - 1) as int);
}
fn qsort(self);
}
-impl<T: copy Ord Eq> &[mut T] : Sort {
+impl<T: Copy Ord Eq> &[mut T] : Sort {
fn qsort(self) { quick_sort3(self); }
}
blocked: Q
}
#[doc(hidden)]
-enum Sem<Q: send> = Exclusive<SemInner<Q>>;
+enum Sem<Q: Send> = Exclusive<SemInner<Q>>;
#[doc(hidden)]
-fn new_sem<Q: send>(count: int, +q: Q) -> Sem<Q> {
+fn new_sem<Q: Send>(count: int, +q: Q) -> Sem<Q> {
Sem(exclusive(SemInner {
mut count: count, waiters: new_waitqueue(), blocked: q }))
}
}
#[doc(hidden)]
-impl<Q: send> &Sem<Q> {
+impl<Q: Send> &Sem<Q> {
fn acquire() {
let mut waiter_nobe = None;
unsafe {
* * ch - a channel of type T to send a `val` on
* * val - a value of type T to send over the provided `ch`
*/
-fn delayed_send<T: copy send>(iotask: IoTask,
+fn delayed_send<T: Copy Send>(iotask: IoTask,
msecs: uint, ch: comm::Chan<T>, +val: T) {
unsafe {
let timer_done_po = core::comm::Port::<()>();
* on the provided port in the allotted timeout period, then the result will
* be a `some(T)`. If not, then `none` will be returned.
*/
-fn recv_timeout<T: copy send>(iotask: IoTask,
+fn recv_timeout<T: Copy Send>(iotask: IoTask,
msecs: uint,
wait_po: comm::Port<T>) -> Option<T> {
let timeout_po = comm::Port::<()>();
fn TreeMap<K, V>() -> TreeMap<K, V> { @mut None }
/// Insert a value into the map
-fn insert<K: copy Eq Ord, V: copy>(m: &mut TreeEdge<K, V>, +k: K, +v: V) {
+fn insert<K: Copy Eq Ord, V: Copy>(m: &mut TreeEdge<K, V>, +k: K, +v: V) {
match copy *m {
None => {
*m = Some(@TreeNode({key: k,
}
/// Find a value based on the key
-fn find<K: copy Eq Ord, V: copy>(m: &const TreeEdge<K, V>, +k: K)
+fn find<K: Copy Eq Ord, V: Copy>(m: &const TreeEdge<K, V>, +k: K)
-> Option<V> {
match copy *m {
None => None,
}
/// Visit all pairs in the map in order.
-fn traverse<K, V: copy>(m: &const TreeEdge<K, V>, f: fn(K, V)) {
+fn traverse<K, V: Copy>(m: &const TreeEdge<K, V>, f: fn(K, V)) {
match copy *m {
None => (),
Some(node) => {
}
}
-fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
+fn new_def_hash<V: Copy>() -> std::map::hashmap<ast::def_id, V> {
return std::map::hashmap::<ast::def_id, V>();
}
}
}
-fn expect<T: copy>(diag: span_handler,
+fn expect<T: Copy>(diag: span_handler,
opt: Option<T>, msg: fn() -> ~str) -> T {
match opt {
Some(t) => t,
}
}
-fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> Option<U>, v: ~[T]) ->
+fn option_flatten_map<T: Copy, U: Copy>(f: fn@(T) -> Option<U>, v: ~[T]) ->
Option<~[U]> {
let mut res = ~[];
for v.each |elem| {
fn check_restricted_keywords();
fn check_restricted_keywords_(w: ~str);
fn expect_gt();
- fn parse_seq_to_before_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> ~[T];
- fn parse_seq_to_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_to_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> ~[T];
- fn parse_seq_lt_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_lt_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> spanned<~[T]>;
- fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep,
+ fn parse_seq_to_end<T: Copy>(ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> ~[T];
- fn parse_seq_to_before_end<T: copy>(ket: token::token, sep: seq_sep,
+ fn parse_seq_to_before_end<T: Copy>(ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> ~[T];
- fn parse_unspanned_seq<T: copy>(bra: token::token,
+ fn parse_unspanned_seq<T: Copy>(bra: token::token,
ket: token::token,
sep: seq_sep,
f: fn(parser) -> T) -> ~[T];
- fn parse_seq<T: copy>(bra: token::token, ket: token::token, sep: seq_sep,
+ fn parse_seq<T: Copy>(bra: token::token, ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> spanned<~[T]>;
}
}
}
- fn parse_seq_to_before_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> ~[T] {
let mut first = true;
let mut v = ~[];
return v;
}
- fn parse_seq_to_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_to_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> ~[T] {
let v = self.parse_seq_to_before_gt(sep, f);
self.expect_gt();
return v;
}
- fn parse_seq_lt_gt<T: copy>(sep: Option<token::token>,
+ fn parse_seq_lt_gt<T: Copy>(sep: Option<token::token>,
f: fn(parser) -> T) -> spanned<~[T]> {
let lo = self.span.lo;
self.expect(token::LT);
return spanned(lo, hi, result);
}
- fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep,
+ fn parse_seq_to_end<T: Copy>(ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> ~[T] {
let val = self.parse_seq_to_before_end(ket, sep, f);
self.bump();
}
- fn parse_seq_to_before_end<T: copy>(ket: token::token, sep: seq_sep,
+ fn parse_seq_to_before_end<T: Copy>(ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> ~[T] {
let mut first: bool = true;
let mut v: ~[T] = ~[];
return v;
}
- fn parse_unspanned_seq<T: copy>(bra: token::token,
+ fn parse_unspanned_seq<T: Copy>(bra: token::token,
ket: token::token,
sep: seq_sep,
f: fn(parser) -> T) -> ~[T] {
// NB: Do not use this function unless you actually plan to place the
// spanned list in the AST.
- fn parse_seq<T: copy>(bra: token::token, ket: token::token, sep: seq_sep,
+ fn parse_seq<T: Copy>(bra: token::token, ket: token::token, sep: seq_sep,
f: fn(parser) -> T) -> spanned<~[T]> {
let lo = self.span.lo;
self.expect(bra);
let mut bounds = ~[];
if self.eat(token::COLON) {
while is_ident(self.token) {
- if self.eat_keyword(~"send") {
- push(bounds, bound_send); }
- else if self.eat_keyword(~"copy") {
- push(bounds, bound_copy) }
- else if self.eat_keyword(~"const") {
- push(bounds, bound_const);
- } else if self.eat_keyword(~"owned") {
- push(bounds, bound_owned);
- } else if is_ident(self.token) {
+ if is_ident(self.token) {
// XXX: temporary until kinds become traits
let maybe_bound = match self.token {
token::IDENT(sid, _) => {
~"else",
~"move",
~"priv", ~"pub",
- ~"self", ~"send", ~"static",
+ ~"self", ~"static",
~"use"
];
for keys.each |word| {
~"if", ~"impl", ~"import",
~"let", ~"log", ~"loop",
~"match", ~"mod", ~"move", ~"mut",
- ~"owned",
~"pure",
~"ref", ~"return",
~"struct",
for vec::each(*bounds) |bound| {
nbsp(s);
match bound {
- ast::bound_copy => word(s.s, ~"copy"),
- ast::bound_send => word(s.s, ~"send"),
- ast::bound_const => word(s.s, ~"const"),
- ast::bound_owned => word(s.s, ~"owned"),
+ ast::bound_copy => word(s.s, ~"Copy"),
+ ast::bound_send => word(s.s, ~"Send"),
+ ast::bound_const => word(s.s, ~"Const"),
+ ast::bound_owned => word(s.s, ~"Owned"),
ast::bound_trait(t) => print_type(s, t)
}
}
use hash::Hash;
use to_bytes::IterBytes;
-type hash_interner<T: const> =
+type hash_interner<T: Const> =
{map: hashmap<T, uint>,
vect: DVec<T>};
-fn mk<T:Eq IterBytes Hash const copy>() -> interner<T> {
+fn mk<T:Eq IterBytes Hash Const Copy>() -> interner<T> {
let m = map::hashmap::<T, uint>();
let hi: hash_interner<T> =
{map: m, vect: DVec()};
return hi as interner::<T>;
}
-fn mk_prefill<T:Eq IterBytes Hash const copy>(init: ~[T]) -> interner<T> {
+fn mk_prefill<T:Eq IterBytes Hash Const Copy>(init: ~[T]) -> interner<T> {
let rv = mk();
for init.each() |v| { rv.intern(v); }
return rv;
/* when traits can extend traits, we should extend index<uint,T> to get [] */
-trait interner<T:Eq IterBytes Hash const copy> {
+trait interner<T:Eq IterBytes Hash Const Copy> {
fn intern(T) -> uint;
fn gensym(T) -> uint;
pure fn get(uint) -> T;
fn len() -> uint;
}
-impl <T:Eq IterBytes Hash const copy> hash_interner<T>: interner<T> {
+impl <T:Eq IterBytes Hash Const Copy> hash_interner<T>: interner<T> {
fn intern(val: T) -> uint {
match self.map.find(val) {
Some(idx) => return idx,
}
// Seems out of place, but it uses session, so I'm putting it here
-fn expect<T: copy>(sess: session, opt: Option<T>, msg: fn() -> ~str) -> T {
+fn expect<T: Copy>(sess: session, opt: Option<T>, msg: fn() -> ~str) -> T {
diagnostic::expect(sess.diagnostic(), opt, msg)
}
fn inject_libcore_ref(sess: session,
crate: @ast::crate) -> @ast::crate {
- fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
+ fn spanned<T: Copy>(x: T) -> @ast::spanned<T> {
return @{node: x,
span: dummy_sp()};
}
return @item;
}
-fn nospan<T: copy>(t: T) -> ast::spanned<T> {
+fn nospan<T: Copy>(t: T) -> ast::spanned<T> {
return {node: t, span: dummy_sp()};
}
// Path and definition ID indexing
-fn create_index<T: copy>(index: ~[entry<T>], hash_fn: fn@(T) -> uint) ->
+fn create_index<T: Copy>(index: ~[entry<T>], hash_fn: fn@(T) -> uint) ->
~[@~[entry<T>]] {
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); };
target_triple: str::from_slice(target_triple)} as filesearch
}
-fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> Option<T> {
+fn search<T: Copy>(filesearch: filesearch, pick: pick<T>) -> Option<T> {
let mut rslt = None;
for filesearch.lib_search_paths().each |lib_search_path| {
debug!("searching %s", lib_search_path.to_str());
pure_map: hashmap<ast::node_id, bckerr>
};
-fn save_and_restore<T:copy,U>(&save_and_restore_t: T, f: fn() -> U) -> U {
+fn save_and_restore<T:Copy,U>(&save_and_restore_t: T, f: fn() -> U) -> U {
let old_save_and_restore_t = save_and_restore_t;
let u <- f();
save_and_restore_t = old_save_and_restore_t;
}
/// Creates a hash table of atoms.
-fn atom_hashmap<V:copy>() -> hashmap<Atom,V> {
+fn atom_hashmap<V:Copy>() -> hashmap<Atom,V> {
hashmap::<Atom,V>()
}
retval_metadata(@metadata<retval_md>),
}
-fn cast_safely<T: copy, U>(val: T) -> U unsafe {
+fn cast_safely<T: Copy, U>(val: T) -> U unsafe {
let val2 = val;
return unsafe::transmute(val2);
}
}
}
-fn cached_metadata<T: copy>(cache: metadata_cache, mdtag: int,
+fn cached_metadata<T: Copy>(cache: metadata_cache, mdtag: int,
eq: fn(md: T) -> bool) -> Option<T> unsafe {
if cache.contains_key(mdtag) {
let items = cache.get(mdtag);
@{did: did, parent_id: parent_id, tps: tps_norm}
}
-fn new_nominal_id_hash<T: copy>() -> hashmap<nominal_id, T> {
+fn new_nominal_id_hash<T: Copy>() -> hashmap<nominal_id, T> {
return hashmap();
}
return map::hashmap();
}
-fn new_ty_hash<V: copy>() -> map::hashmap<t, V> {
+fn new_ty_hash<V: Copy>() -> map::hashmap<t, V> {
map::hashmap()
}
}
}
-fn br_hashmap<V:copy>() -> hashmap<bound_region, V> {
+fn br_hashmap<V:Copy>() -> hashmap<bound_region, V> {
map::hashmap()
}
// Maintains a little union-set tree for inferred modes. `canon()` returns
// the current head value for `m0`.
-fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>,
+fn canon<T:Copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>,
+m0: ast::inferable<T>) -> ast::inferable<T> {
match m0 {
ast::infer(id) => match tbl.find(id) {
}
}
-fn ast_region_to_region<AC: ast_conv, RS: region_scope copy owned>(
+fn ast_region_to_region<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region {
let res = match a_r.node {
get_region_reporting_err(self.tcx(), span, res)
}
-fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope copy owned>(
+fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, did: ast::def_id,
path: @ast::path) -> ty_param_substs_and_ty {
{substs: substs, ty: ty::subst(tcx, &substs, decl_ty)}
}
-fn ast_path_to_ty<AC: ast_conv, RS: region_scope copy owned>(
+fn ast_path_to_ty<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC,
rscope: RS,
did: ast::def_id,
// Parses the programmer's textual representation of a type into our
// internal notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID:
-fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>(
+fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, &&ast_ty: @ast::ty) -> ty::t {
- fn ast_mt_to_mt<AC: ast_conv, RS: region_scope copy owned>(
+ fn ast_mt_to_mt<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, mt: ast::mt) -> ty::mt {
return {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl};
// Handle @, ~, and & being able to mean estrs and evecs.
// If a_seq_ty is a str or a vec, make it an estr/evec.
// Also handle function sigils and first-class trait types.
- fn mk_maybe_vstore<AC: ast_conv, RS: region_scope copy owned>(
+ fn mk_maybe_vstore<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, a_seq_ty: ast::mt, vst: ty::vstore,
span: span, constr: fn(ty::mt) -> ty::t) -> ty::t {
return typ;
}
-fn ty_of_arg<AC: ast_conv, RS: region_scope copy owned>(
+fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, a: ast::arg,
expected_ty: Option<ty::arg>) -> ty::arg {
{mode: mode, ty: ty}
}
-fn ast_proto_to_proto<AC: ast_conv, RS: region_scope copy owned>(
+fn ast_proto_to_proto<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS, span: span, ast_proto: ast::proto) -> ty::fn_proto {
match ast_proto {
ast::proto_bare =>
type expected_tys = Option<{inputs: ~[ty::arg],
output: ty::t}>;
-fn ty_of_fn_decl<AC: ast_conv, RS: region_scope copy owned>(
+fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Owned>(
self: AC, rscope: RS,
ast_proto: ast::proto,
purity: ast::purity,
// through the `unpack` function. It there is no expected type or
// resolution is not possible (e.g., no constraints yet present), just
// returns `none`.
- fn unpack_expected<O: copy>(fcx: @fn_ctxt, expected: Option<ty::t>,
+ fn unpack_expected<O: Copy>(fcx: @fn_ctxt, expected: Option<ty::t>,
unpack: fn(ty::sty) -> Option<O>)
-> Option<O> {
match expected {
}
impl @crate_ctxt {
- fn to_ty<RS: region_scope copy owned>(
+ fn to_ty<RS: region_scope Copy Owned>(
rs: RS, ast_ty: @ast::ty) -> ty::t {
ast_ty_to_ty(self, rs, ast_ty)
export root, to_str;
export int_ty_set_all;
-type bound<T:copy> = Option<T>;
-type bounds<T:copy> = {lb: bound<T>, ub: bound<T>};
+type bound<T:Copy> = Option<T>;
+type bounds<T:Copy> = {lb: bound<T>, ub: bound<T>};
type cres<T> = Result<T,ty::type_err>; // "combine result"
type ures = cres<()>; // "unify result"
}
}
-fn new_vals_and_bindings<V:copy, T:copy>() -> vals_and_bindings<V, T> {
+fn new_vals_and_bindings<V:Copy, T:Copy>() -> vals_and_bindings<V, T> {
vals_and_bindings {
vals: smallintmap::mk(),
mut bindings: ~[]
*/
trait then {
- fn then<T:copy>(f: fn() -> Result<T,ty::type_err>)
+ fn then<T:Copy>(f: fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err>;
}
impl ures: then {
- fn then<T:copy>(f: fn() -> Result<T,ty::type_err>)
+ fn then<T:Copy>(f: fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err> {
self.chain(|_i| f())
}
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T>;
}
-impl<T:copy Eq> cres<T>: cres_helpers<T> {
+impl<T:Copy Eq> cres<T>: cres_helpers<T> {
fn to_ures() -> ures {
match self {
Ok(_v) => Ok(()),
Ok(())
}
-fn rollback_to<V:copy vid, T:copy>(
+fn rollback_to<V:Copy vid, T:Copy>(
vb: &vals_and_bindings<V, T>, len: uint) {
while vb.bindings.len() != len {
}
}
-impl<V:copy to_str> bound<V>: to_str {
+impl<V:Copy to_str> bound<V>: to_str {
fn to_str(cx: infer_ctxt) -> ~str {
match self {
Some(v) => v.to_str(cx),
}
}
-impl<T:copy to_str> bounds<T>: to_str {
+impl<T:Copy to_str> bounds<T>: to_str {
fn to_str(cx: infer_ctxt) -> ~str {
fmt!("{%s <: %s}",
self.lb.to_str(cx),
}
}
-impl<V:copy vid, T:copy to_str> var_value<V, T>: to_str {
+impl<V:Copy vid, T:Copy to_str> var_value<V, T>: to_str {
fn to_str(cx: infer_ctxt) -> ~str {
match self {
redirect(vid) => fmt!("redirect(%s)", vid.to_str()),
use to_str::to_str;
use std::smallintmap::SmallIntMap;
-enum var_value<V:copy, T:copy> {
+enum var_value<V:Copy, T:Copy> {
redirect(V),
root(T, uint),
}
-struct vals_and_bindings<V:copy, T:copy> {
+struct vals_and_bindings<V:Copy, T:Copy> {
vals: SmallIntMap<var_value<V, T>>,
mut bindings: ~[(V, var_value<V, T>)],
}
-struct node<V:copy, T:copy> {
+struct node<V:Copy, T:Copy> {
root: V,
possible_types: T,
rank: uint,
}
impl infer_ctxt {
- fn get<V:copy vid, T:copy>(
+ fn get<V:Copy vid, T:Copy>(
vb: &vals_and_bindings<V, T>, vid: V) -> node<V, T> {
let vid_u = vid.to_uint();
}
}
- fn set<V:copy vid, T:copy to_str>(
+ fn set<V:Copy vid, T:Copy to_str>(
vb: &vals_and_bindings<V, T>, vid: V,
+new_v: var_value<V, T>) {
}
enum anon_rscope = {anon: ty::region, base: region_scope};
-fn in_anon_rscope<RS: region_scope copy owned>(self: RS, r: ty::region)
+fn in_anon_rscope<RS: region_scope Copy Owned>(self: RS, r: ty::region)
-> @anon_rscope {
@anon_rscope({anon: r, base: self as region_scope})
}
base: region_scope,
mut anon_bindings: uint,
}
-fn in_binding_rscope<RS: region_scope copy owned>(self: RS)
+fn in_binding_rscope<RS: region_scope Copy Owned>(self: RS)
-> @binding_rscope {
let base = self as region_scope;
@binding_rscope { base: base, anon_bindings: 0 }
}
}
-fn exec<T:send>(
+fn exec<T:Send>(
srv: srv,
+f: fn~(ctxt: ctxt) -> T
) -> T {
}
}
-fn parse_item_attrs<T:send>(
+fn parse_item_attrs<T:Send>(
srv: astsrv::srv,
id: doc::ast_id,
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
// This exists because fn types don't infer correctly as record
// initializers, but they do as function arguments
-fn mk_fold<T:copy>(
+fn mk_fold<T:Copy>(
ctxt: T,
+fold_doc: fold_doc<T>,
+fold_crate: fold_crate<T>,
})
}
-fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
+fn default_any_fold<T:Send Copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
|f, d| default_seq_fold_doc(f, d),
)
}
-fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
+fn default_seq_fold<T:Copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
|f, d| default_seq_fold_doc(f, d),
)
}
-fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
+fn default_par_fold<T:Send Copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
|f, d| default_seq_fold_doc(f, d),
doc
}
-fn default_any_fold_mod<T:send copy>(
+fn default_any_fold_mod<T:Send Copy>(
fold: fold<T>,
doc: doc::moddoc
) -> doc::moddoc {
})
}
-fn default_par_fold_mod<T:send copy>(
+fn default_par_fold_mod<T:Send Copy>(
fold: fold<T>,
doc: doc::moddoc
) -> doc::moddoc {
})
}
-fn default_any_fold_nmod<T:send copy>(
+fn default_any_fold_nmod<T:Send Copy>(
fold: fold<T>,
doc: doc::nmoddoc
) -> doc::nmoddoc {
}
}
-fn default_par_fold_nmod<T:send copy>(
+fn default_par_fold_nmod<T:Send Copy>(
fold: fold<T>,
doc: doc::nmoddoc
) -> doc::nmoddoc {
use comm::*;
-fn foo<T: send copy>(x: T) -> Port<T> {
+fn foo<T: Send Copy>(x: T) -> Port<T> {
let p = Port();
let c = Chan(p);
do task::spawn() |copy c, copy x| {
type entry<A,B> = {key: A, value: B};
type alist<A,B> = { eq_fn: fn@(A,A) -> bool, data: DVec<entry<A,B>> };
-fn alist_add<A: copy, B: copy>(lst: alist<A,B>, k: A, v: B) {
+fn alist_add<A: Copy, B: Copy>(lst: alist<A,B>, k: A, v: B) {
lst.data.push({key:k, value:v});
}
-fn alist_get<A: copy, B: copy>(lst: alist<A,B>, k: A) -> B {
+fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {
let eq_fn = lst.eq_fn;
for lst.data.each |entry| {
if eq_fn(entry.key, k) { return entry.value; }
}
#[inline]
-fn new_int_alist<B: copy>() -> alist<int, B> {
+fn new_int_alist<B: Copy>() -> alist<int, B> {
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
return {eq_fn: eq_int, data: DVec()};
}
#[inline]
-fn new_int_alist_2<B: copy>() -> alist<int, B> {
+fn new_int_alist_2<B: Copy>() -> alist<int, B> {
#[inline]
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
return {eq_fn: eq_int, data: DVec()};
export context;
-struct arc_destruct<T:const> {
+struct arc_destruct<T:Const> {
_data: int,
drop {}
}
-fn arc_destruct<T: const>(data: int) -> arc_destruct<T> {
+fn arc_destruct<T: Const>(data: int) -> arc_destruct<T> {
arc_destruct {
_data: data
}
}
-fn arc<T: const>(_data: T) -> arc_destruct<T> {
+fn arc<T: Const>(_data: T) -> arc_destruct<T> {
arc_destruct(0)
}
type header_map = hashmap<~str, @DVec<@~str>>;
// the unused ty param is necessary so this gets monomorphized
-fn request<T: copy>(req: header_map) {
+fn request<T: Copy>(req: header_map) {
let _x = *(*req.get(~"METHOD"))[0u];
}
}
}
-fn read<T: read copy>(s: ~str) -> T {
+fn read<T: read Copy>(s: ~str) -> T {
match readMaybe(s) {
Some(x) => x,
_ => fail ~"read failed!"
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
-enum port<T: send> {
+enum port<T: Send> {
port_t(@port_ptr<T>)
}
/// Constructs a port
-fn port<T: send>() -> port<T> {
+fn port<T: Send>() -> port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}
-struct port_ptr<T:send> {
+struct port_ptr<T:Send> {
po: *rust_port,
drop unsafe {
debug!("in the port_ptr destructor");
}
}
-fn port_ptr<T: send>(po: *rust_port) -> port_ptr<T> {
+fn port_ptr<T: Send>(po: *rust_port) -> port_ptr<T> {
debug!("in the port_ptr constructor");
port_ptr {
po: po
* Receive from a port. If no data is available on the port then the
* task will block until data becomes available.
*/
-fn recv<T: send>(p: port<T>) -> T { recv_((**p).po) }
+fn recv<T: Send>(p: port<T>) -> T { recv_((**p).po) }
/// Receive on a raw port pointer
-fn recv_<T: send>(p: *rust_port) -> T {
+fn recv_<T: Send>(p: *rust_port) -> T {
let yield = 0u;
let yieldp = ptr::addr_of(yield);
let mut res;
)
)
-fn switch<T: send, Tb: send, U>(+endp: pipes::RecvPacketBuffered<T, Tb>,
+fn switch<T: Send, Tb: Send, U>(+endp: pipes::RecvPacketBuffered<T, Tb>,
f: fn(+Option<T>) -> U) -> U {
f(pipes::try_recv(endp))
}
return (xx as float) * 100f / (yy as float);
}
- pure fn le_by_val<TT: copy, UU: copy>(kv0: &(TT,UU),
+ pure fn le_by_val<TT: Copy, UU: Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool {
let (_, v0) = *kv0;
let (_, v1) = *kv1;
return v0 >= v1;
}
- pure fn le_by_key<TT: copy, UU: copy>(kv0: &(TT,UU),
+ pure fn le_by_key<TT: Copy, UU: Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool {
let (k0, _) = *kv0;
let (k1, _) = *kv1;
}
// sort by key, then by value
- fn sortKV<TT: copy, UU: copy>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
+ fn sortKV<TT: Copy, UU: Copy>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
return sort::merge_sort(le_by_val, sort::merge_sort(le_by_key, orig));
}
return (xx as float) * 100f / (yy as float);
}
- pure fn le_by_val<TT: copy, UU: copy>(kv0: &(TT,UU),
+ pure fn le_by_val<TT: Copy, UU: Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool {
let (_, v0) = *kv0;
let (_, v1) = *kv1;
return v0 >= v1;
}
- pure fn le_by_key<TT: copy, UU: copy>(kv0: &(TT,UU),
+ pure fn le_by_key<TT: Copy, UU: Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool {
let (k0, _) = *kv0;
let (k1, _) = *kv1;
}
// sort by key, then by value
- fn sortKV<TT: copy, UU: copy>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
+ fn sortKV<TT: Copy, UU: Copy>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
return sort::merge_sort(le_by_val, sort::merge_sort(le_by_key, orig));
}
pure fn eq(&&k: self) -> bool;
}
-fn mk_hash<K: const hash_key, V: copy>() -> map::hashmap<K, V> {
- pure fn hashfn<K: const hash_key>(k: &K) -> uint { k.hash() }
- pure fn hasheq<K: const hash_key>(k1: &K, k2: &K) -> bool { k1.eq(*k2) }
+fn mk_hash<K: Const hash_key, V: Copy>() -> map::hashmap<K, V> {
+ pure fn hashfn<K: Const hash_key>(k: &K) -> uint { k.hash() }
+ pure fn hasheq<K: Const hash_key>(k1: &K, k2: &K) -> bool { k1.eq(*k2) }
map::hashmap(hashfn, hasheq)
}
export reducer;
export map_reduce;
- type putter<K: send, V: send> = fn(K, V);
+ type putter<K: Send, V: Send> = fn(K, V);
- type mapper<K1: send, K2: send, V: send> = fn~(K1, putter<K2, V>);
+ type mapper<K1: Send, K2: Send, V: Send> = fn~(K1, putter<K2, V>);
- type getter<V: send> = fn() -> Option<V>;
+ type getter<V: Send> = fn() -> Option<V>;
- type reducer<K: copy send, V: copy send> = fn~(K, getter<V>);
+ type reducer<K: Copy Send, V: Copy Send> = fn~(K, getter<V>);
- enum ctrl_proto<K: copy send, V: copy send> {
+ enum ctrl_proto<K: Copy Send, V: Copy Send> {
find_reducer(K, Chan<Chan<reduce_proto<V>>>),
mapper_done
}
proto! ctrl_proto (
- open: send<K: copy send, V: copy send> {
+ open: send<K: Copy Send, V: Copy Send> {
find_reducer(K) -> reducer_response<K, V>,
mapper_done -> !
}
- reducer_response: recv<K: copy send, V: copy send> {
+ reducer_response: recv<K: Copy Send, V: Copy Send> {
reducer(Chan<reduce_proto<V>>) -> open<K, V>
}
)
- enum reduce_proto<V: copy send> { emit_val(V), done, addref, release }
+ enum reduce_proto<V: Copy Send> { emit_val(V), done, addref, release }
- fn start_mappers<K1: copy send, K2: const copy send hash_key,
- V: copy send>(
+ fn start_mappers<K1: Copy Send, K2: Const Copy Send hash_key,
+ V: Copy Send>(
map: mapper<K1, K2, V>,
&ctrls: ~[ctrl_proto::server::open<K2, V>],
inputs: ~[K1])
return tasks;
}
- fn map_task<K1: copy send, K2: const copy send hash_key, V: copy send>(
+ fn map_task<K1: Copy Send, K2: Const Copy Send hash_key, V: Copy Send>(
map: mapper<K1, K2, V>,
ctrl: box<ctrl_proto::client::open<K2, V>>,
input: K1)
send(c.get(), emit_val(val));
}
- fn finish<K: copy send, V: copy send>(_k: K, v: Chan<reduce_proto<V>>)
+ fn finish<K: Copy Send, V: Copy Send>(_k: K, v: Chan<reduce_proto<V>>)
{
send(v, release);
}
ctrl_proto::client::mapper_done(ctrl.unwrap());
}
- fn reduce_task<K: copy send, V: copy send>(
+ fn reduce_task<K: Copy Send, V: Copy Send>(
reduce: reducer<K, V>,
key: K,
out: Chan<Chan<reduce_proto<V>>>)
let mut ref_count = 0;
let mut is_done = false;
- fn get<V: copy send>(p: Port<reduce_proto<V>>,
+ fn get<V: Copy Send>(p: Port<reduce_proto<V>>,
&ref_count: int, &is_done: bool)
-> Option<V> {
while !is_done || ref_count > 0 {
reduce(key, || get(p, ref_count, is_done) );
}
- fn map_reduce<K1: copy send, K2: const copy send hash_key, V: copy send>(
+ fn map_reduce<K1: Copy Send, K2: Const Copy Send hash_key, V: Copy Send>(
map: mapper<K1, K2, V>,
reduce: reducer<K2, V>,
inputs: ~[K1])
}
trait bar {
- fn bar<T:copy>();
+ fn bar<T:Copy>();
}
impl uint: bar {
- fn bar<T:copy>() {
+ fn bar<T:Copy>() {
}
}
-fn reproduce<T:copy>(t: T) -> fn@() -> T {
+fn reproduce<T:Copy>(t: T) -> fn@() -> T {
fn@() -> T { t }
}
-fn mk_identity<T:copy>() -> fn@(T) -> T {
+fn mk_identity<T:Copy>() -> fn@(T) -> T {
fn@(t: T) -> T { t }
}
}
}
-impl<T:copy> Option<T>: to_opt {
+impl<T:Copy> Option<T>: to_opt {
fn to_option() -> Option<Option<T>> {
Some(self)
}
-fn foo<T: copy>(+_t: T) { fail; }
+fn foo<T: Copy>(+_t: T) { fail; }
fn bar<T>(+_t: T) { fail; }
import iter::BaseIter;
trait A {
- fn b<C:copy const, D>(x: C) -> C;
+ fn b<C:Copy Const, D>(x: C) -> C;
}
struct E {
}
impl E: A {
- fn b<F:copy, G>(_x: F) -> F { fail } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
+ fn b<F:Copy, G>(_x: F) -> F { fail } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
}
fn main() {}
\ No newline at end of file
import iter::BaseIter;
trait A {
- fn b<C:copy, D>(x: C) -> C;
+ fn b<C:Copy, D>(x: C) -> C;
}
struct E {
}
impl E: A {
- fn b<F:copy const, G>(_x: F) -> F { fail } //~ ERROR in method `b`, type parameter 0 has 2 bounds, but
+ fn b<F:Copy Const, G>(_x: F) -> F { fail } //~ ERROR in method `b`, type parameter 0 has 2 bounds, but
}
fn main() {}
\ No newline at end of file
import iter::BaseIter;
trait A {
- fn b<C:copy, D>(x: C) -> C;
+ fn b<C:Copy, D>(x: C) -> C;
}
struct E {
impl E: A {
// n.b. The error message is awful -- see #3404
- fn b<F:copy, G>(_x: G) -> G { fail } //~ ERROR method `b` has an incompatible type
+ fn b<F:Copy, G>(_x: G) -> G { fail } //~ ERROR method `b` has an incompatible type
}
fn main() {}
\ No newline at end of file
-struct send_packet<T: copy> {
+struct send_packet<T: Copy> {
p: T
}
mod stream {
- enum stream<T: send> { send(T, server::stream<T>), }
+ enum stream<T: Send> { send(T, server::stream<T>), }
mod server {
- impl<T: send> stream<T> {
+ impl<T: Send> stream<T> {
fn recv() -> extern fn(+stream<T>) -> stream::stream<T> {
// resolve really should report just one error here.
// Change the test case when it changes.
recv
}
}
- type stream<T: send> = pipes::RecvPacket<stream::stream<T>>;
+ type stream<T: Send> = pipes::RecvPacket<stream::stream<T>>;
}
}
trait repeat<A> { fn get() -> A; }
-impl<A:copy> @A: repeat<A> {
+impl<A:Copy> @A: repeat<A> {
fn get() -> A { *self }
}
-fn repeater<A:copy>(v: @A) -> repeat<A> {
+fn repeater<A:Copy>(v: @A) -> repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
v as repeat::<A> // No
}
fn foo(i: &self/int) -> int;
}
-impl<T:copy> T: foo {
+impl<T:Copy> T: foo {
fn foo(i: &self/int) -> int {*i}
}
-fn to_foo<T:copy>(t: T) {
+fn to_foo<T:Copy>(t: T) {
// This version is ok because, although T may contain borrowed
// pointers, it never escapes the fn body. We know this because
// the type of foo includes a region which will be resolved to
assert x.foo(v) == 3;
}
-fn to_foo_2<T:copy>(t: T) -> foo {
+fn to_foo_2<T:Copy>(t: T) -> foo {
// Not OK---T may contain borrowed ptrs and it is going to escape
// as part of the returned foo value
{f:t} as foo //~ ERROR value may contain borrowed pointers; use `owned` bound
}
-fn to_foo_3<T:copy owned>(t: T) -> foo {
+fn to_foo_3<T:Copy Owned>(t: T) -> foo {
// OK---T may escape as part of the returned foo value, but it is
// owned and hence does not contain borrowed ptrs
{f:t} as foo
trait foo { fn foo(); }
-fn to_foo<T: copy foo>(t: T) -> foo {
+fn to_foo<T: Copy foo>(t: T) -> foo {
t as foo //~ ERROR value may contain borrowed pointers; use `owned` bound
}
-fn to_foo2<T: copy foo owned>(t: T) -> foo {
+fn to_foo2<T: Copy foo Owned>(t: T) -> foo {
t as foo
}
-fn copy1<T: copy>(t: T) -> fn@() -> T {
+fn copy1<T: Copy>(t: T) -> fn@() -> T {
fn@() -> T { t } //~ ERROR value may contain borrowed pointers
}
-fn copy2<T: copy owned>(t: T) -> fn@() -> T {
+fn copy2<T: Copy Owned>(t: T) -> fn@() -> T {
fn@() -> T { t }
}
-fn send<T: send>(ch: _chan<T>, -data: T) {
+fn send<T: Send>(ch: _chan<T>, -data: T) {
log(debug, ch);
log(debug, data);
fail;
// Test that various non const things are rejected.
-fn foo<T: const>(_x: T) { }
+fn foo<T: Const>(_x: T) { }
struct r {
x:int,
use core;
-fn last<T: copy>(v: ~[const T]) -> core::Option<T> {
+fn last<T: Copy>(v: ~[const T]) -> core::Option<T> {
fail;
}
mut f: T
};
-impl<T:copy> box_impl<T>: box_trait<T> {
+impl<T:Copy> box_impl<T>: box_trait<T> {
fn get() -> T { return self.f; }
fn set(t: T) { self.f = t; }
}
-fn f<T: send>(_i: T) {
+fn f<T: Send>(_i: T) {
}
fn main() {
-fn concat<T: copy>(v: ~[const ~[const T]]) -> ~[T] {
+fn concat<T: Copy>(v: ~[const ~[const T]]) -> ~[T] {
let mut r = ~[];
// Earlier versions of our type checker accepted this:
type task_id = int;
type port_id = int;
-enum chan_t<T: send> = {task: task_id, port: port_id};
+enum chan_t<T: Send> = {task: task_id, port: port_id};
-fn send<T: send>(ch: chan_t<T>, data: T) { fail; }
+fn send<T: Send>(ch: chan_t<T>, data: T) { fail; }
fn main() { fail ~"quux"; }
use std;
use std::arc;
-enum e<T: const send> { e(arc::ARC<T>) }
+enum e<T: Const Send> { e(arc::ARC<T>) }
fn foo() -> e<int> {fail;}
use comm::send;
use comm::recv;
-fn echo<T: send>(c: Chan<T>, oc: Chan<Chan<T>>) {
+fn echo<T: Send>(c: Chan<T>, oc: Chan<Chan<T>>) {
// Tests that the type argument in port gets
// visited
let p = Port::<T>();
a: A, b: B
};
-fn f<A:copy owned>(a: A, b: u16) -> fn@() -> (A, u16) {
+fn f<A:Copy Owned>(a: A, b: u16) -> fn@() -> (A, u16) {
fn@() -> (A, u16) { (a, b) }
}
mut rec: Option<@rec<A>>
};
-fn make_cycle<A:copy>(a: A) {
+fn make_cycle<A:Copy>(a: A) {
let g: @rec<A> = @rec({val: a, mut rec: None});
g.rec = Some(g);
}
-fn f<A:send copy, B:send copy>(a: A, b: B) -> fn@() -> (A, B) {
+fn f<A:Send Copy, B:Send Copy>(a: A, b: B) -> fn@() -> (A, B) {
fn@() -> (A, B) { (a, b) }
}
// -*- rust -*-
-fn f<T: copy, U: copy>(x: T, y: U) -> {a: T, b: U} { return {a: x, b: y}; }
+fn f<T: Copy, U: Copy>(x: T, y: U) -> {a: T, b: U} { return {a: x, b: y}; }
fn main() {
log(debug, f({x: 3, y: 4, z: 5}, 4).a.x);
-fn f<T: copy>(x: ~[T]) -> T { return x[0]; }
+fn f<T: Copy>(x: ~[T]) -> T { return x[0]; }
fn g(act: fn(~[int]) -> int) -> int { return act(~[1, 2, 3]); }
fn ignore<T>(_x: T) {}
fn main() {
- let f: fn@:send() = ||();
+ let f: fn@:Send() = ||();
ignore(f);
}
-type box<T: copy> = {c: @T};
+type box<T: Copy> = {c: @T};
-fn unbox<T: copy>(b: box<T>) -> T { return *b.c; }
+fn unbox<T: Copy>(b: box<T>) -> T { return *b.c; }
fn main() {
let foo: int = 17;
// for any int value that's less than the meows field
// ok: T should be in scope when resolving the trait ref for map
-struct cat<T: copy> : map<int, T> {
+struct cat<T: Copy> : map<int, T> {
priv {
// Yes, you can have negative meows
mut meows : int,
fn clear() { }
}
-fn cat<T: copy>(in_x : int, in_y : int, in_name: T) -> cat<T> {
+fn cat<T: Copy>(in_x : int, in_y : int, in_name: T) -> cat<T> {
cat {
meows: in_x,
how_hungry: in_y,
use std;
use std::map::{map, hashmap, int_hash};
-class keys<K: copy, V: copy, M: copy map<K,V>>
+class keys<K: Copy, V: Copy, M: Copy map<K,V>>
: iter::base_iter<K> {
let map: M;
a: A, b: B
};
-fn f<A:copy owned>(a: A, b: u16) -> fn@() -> (A, u16) {
+fn f<A:Copy Owned>(a: A, b: u16) -> fn@() -> (A, u16) {
fn@() -> (A, u16) { (a, b) }
}
// are const.
-fn foo<T: copy const>(x: T) -> T { x }
+fn foo<T: Copy Const>(x: T) -> T { x }
fn main() {
foo(1);
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail ~"wat" };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(~T, ~T) -> bool;
-fn test_generic<T: copy>(expected: ~T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = match true { true => { expected }, _ => fail ~"wat" };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => expected, _ => fail ~"wat" };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail ~"wat" };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(~T, ~T) -> bool;
-fn test_generic<T: copy>(expected: ~T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = { expected };
assert (eq(expected, actual));
}
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
// Tests for standalone blocks as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
}
fn test_generic() {
- fn f<T: copy>(t: T) -> T { t }
+ fn f<T: Copy>(t: T) -> T { t }
assert (f(10) == 10);
}
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, not_expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
// Tests for if as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;
-fn test_generic<T: copy>(expected: T, not_expected: T, eq: compare<T>) {
+fn test_generic<T: Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
-fn fix_help<A: owned, B: send>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
+fn fix_help<A: Owned, B: Send>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
return f({|a|fix_help(f, a)}, x);
}
-fn fix<A: owned, B: send>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
+fn fix<A: Owned, B: Send>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
return {|a|fix_help(f, a)};
}
// This is what the signature to spawn should look like with bare functions
-fn spawn<T: send>(val: T, f: extern fn(T)) {
+fn spawn<T: Send>(val: T, f: extern fn(T)) {
f(val);
}
-fn id<T: copy>(t: T) -> T { return t; }
+fn id<T: Copy>(t: T) -> T { return t; }
fn main() {
let expected = @100;
-fn id<T: copy send>(t: T) -> T { return t; }
+fn id<T: Copy Send>(t: T) -> T { return t; }
fn main() {
let expected = ~100;
-fn box<T: copy>(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { return @x; }
+fn box<T: Copy>(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { return @x; }
fn main() {
let x: @{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
-fn g<X: copy>(x: X) -> X { return x; }
+fn g<X: Copy>(x: X) -> X { return x; }
-fn f<T: copy>(t: T) -> {a: T, b: T} {
+fn f<T: Copy>(t: T) -> {a: T, b: T} {
type pair = {a: T, b: T};
let x: pair = {a: t, b: t};
-fn f<T: copy>(t: T) { let t1: T = t; }
+fn f<T: Copy>(t: T) { let t1: T = t; }
fn main() { let x = {x: @10, y: @12}; f(x); }
-type recbox<T: copy> = {x: @T};
+type recbox<T: Copy> = {x: @T};
-fn reclift<T: copy>(t: T) -> recbox<T> { return {x: @t}; }
+fn reclift<T: Copy>(t: T) -> recbox<T> { return {x: @t}; }
fn main() {
let foo: int = 17;
-type recbox<T: copy> = {x: ~T};
+type recbox<T: Copy> = {x: ~T};
-fn reclift<T: copy>(t: T) -> recbox<T> { return {x: ~t}; }
+fn reclift<T: Copy>(t: T) -> recbox<T> { return {x: ~t}; }
fn main() {
let foo: int = 17;
// -*- rust -*-
// Issue #45: infer type parameters in function applications
-fn id<T: copy>(x: T) -> T { return x; }
+fn id<T: Copy>(x: T) -> T { return x; }
fn main() { let x: int = 42; let y: int = id(x); assert (x == y); }
-fn f<T: copy>(x: ~T) -> ~T { return x; }
+fn f<T: Copy>(x: ~T) -> ~T { return x; }
fn main() { let x = f(~3); log(debug, *x); }
// -*- rust -*-
-fn id<T: copy>(x: T) -> T { return x; }
+fn id<T: Copy>(x: T) -> T { return x; }
type triple = {x: int, y: int, z: int};
-fn get_third<T: copy>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; }
+fn get_third<T: Copy>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; }
fn main() {
log(debug, get_third((1, 2, 3)));
-fn box<T: copy>(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { return ~x; }
+fn box<T: Copy>(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { return ~x; }
fn main() {
let x: ~{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
-trait clam<A: copy> {
+trait clam<A: Copy> {
fn chowder(y: A);
}
-struct foo<A: copy> : clam<A> {
+struct foo<A: Copy> : clam<A> {
x: A,
fn chowder(y: A) {
}
}
-fn foo<A: copy>(b: A) -> foo<A> {
+fn foo<A: Copy>(b: A) -> foo<A> {
foo {
x: b
}
}
-fn f<A: copy>(x: clam<A>, a: A) {
+fn f<A: Copy>(x: clam<A>, a: A) {
x.chowder(a);
}
-trait clam<A: copy> { }
-struct foo<A: copy> {
+trait clam<A: Copy> { }
+struct foo<A: Copy> {
x: A,
fn bar<B,C:clam<A>>(c: C) -> B {
fail;
}
}
-fn foo<A: copy>(b: A) -> foo<A> {
+fn foo<A: Copy>(b: A) -> foo<A> {
foo {
x: b
}
-struct c1<T: copy> {
+struct c1<T: Copy> {
x: T,
fn f1(x: int) {
}
}
-fn c1<T: copy>(x: T) -> c1<T> {
+fn c1<T: Copy>(x: T) -> c1<T> {
c1 {
x: x
}
}
-impl<T: copy> c1<T> {
+impl<T: Copy> c1<T> {
fn f2(x: int) {
}
}
use dvec::DVec;
-struct c1<T: copy> {
+struct c1<T: Copy> {
x: T,
fn f1(x: T) {}
}
-fn c1<T: copy>(x: T) -> c1<T> {
+fn c1<T: Copy>(x: T) -> c1<T> {
c1 {
x: x
}
}
-impl<T: copy> c1<T> {
+impl<T: Copy> c1<T> {
fn f2(x: T) {}
}
}
}
-fn f<T:copy>(_x: T) {
+fn f<T:Copy>(_x: T) {
}
#[deny(non_implicitly_copyable_typarams)]
use iter::BaseIter;
trait FlatMapToVec<A> {
- fn flat_map_to_vec<B:copy, IB:BaseIter<B>>(op: fn(A) -> IB) -> ~[B];
+ fn flat_map_to_vec<B:Copy, IB:BaseIter<B>>(op: fn(A) -> IB) -> ~[B];
}
-impl<A:copy> BaseIter<A>: FlatMapToVec<A> {
- fn flat_map_to_vec<B:copy, IB:BaseIter<B>>(op: fn(A) -> IB) -> ~[B] {
+impl<A:Copy> BaseIter<A>: FlatMapToVec<A> {
+ fn flat_map_to_vec<B:Copy, IB:BaseIter<B>>(op: fn(A) -> IB) -> ~[B] {
iter::flat_map_to_vec(self, op)
}
}
pure fn ne(&&other: state) -> bool { !self.eq(other) }
}
- type packet<T: send> = {
+ type packet<T: Send> = {
mut state: state,
mut blocked_task: Option<task::Task>,
mut payload: Option<T>
};
- fn packet<T: send>() -> *packet<T> unsafe {
+ fn packet<T: Send>() -> *packet<T> unsafe {
let p: *packet<T> = unsafe::transmute(~{
mut state: empty,
mut blocked_task: None::<task::Task>,
}
}
- fn send<T: send>(-p: send_packet<T>, -payload: T) {
+ fn send<T: Send>(-p: send_packet<T>, -payload: T) {
let p = p.unwrap();
let p = unsafe { uniquify(p) };
assert (*p).payload.is_none();
}
}
- fn recv<T: send>(-p: recv_packet<T>) -> Option<T> {
+ fn recv<T: Send>(-p: recv_packet<T>) -> Option<T> {
let p = p.unwrap();
let p = unsafe { uniquify(p) };
loop {
}
}
- fn sender_terminate<T: send>(p: *packet<T>) {
+ fn sender_terminate<T: Send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty | blocked => {
}
}
- fn receiver_terminate<T: send>(p: *packet<T>) {
+ fn receiver_terminate<T: Send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty => {
}
}
- struct send_packet<T: send> {
+ struct send_packet<T: Send> {
mut p: Option<*packet<T>>,
drop {
if self.p != None {
}
}
- fn send_packet<T: send>(p: *packet<T>) -> send_packet<T> {
+ fn send_packet<T: Send>(p: *packet<T>) -> send_packet<T> {
send_packet {
p: Some(p)
}
}
- struct recv_packet<T: send> {
+ struct recv_packet<T: Send> {
mut p: Option<*packet<T>>,
drop {
if self.p != None {
}
}
- fn recv_packet<T: send>(p: *packet<T>) -> recv_packet<T> {
+ fn recv_packet<T: Send>(p: *packet<T>) -> recv_packet<T> {
recv_packet {
p: Some(p)
}
}
- fn entangle<T: send>() -> (send_packet<T>, recv_packet<T>) {
+ fn entangle<T: Send>() -> (send_packet<T>, recv_packet<T>) {
let p = packet();
(send_packet(p), recv_packet(p))
}
trait hax { }
impl <A> A: hax { }
-fn perform_hax<T: owned>(x: @T) -> hax {
+fn perform_hax<T: Owned>(x: @T) -> hax {
x as hax
}
trait hax { }
impl <A> A: hax { }
-fn perform_hax<T: owned>(x: @T) -> hax {
+fn perform_hax<T: Owned>(x: @T) -> hax {
x as hax
}
}
}
-fn read_board_grid<rdr: owned io::Reader>(+in: rdr) -> ~[~[square]] {
+fn read_board_grid<rdr: Owned io::Reader>(+in: rdr) -> ~[~[square]] {
let in = in as io::Reader;
let mut grid = ~[];
for in.each_line |line| {
proto! stream (
- stream:send<T:send> {
+ stream:send<T:Send> {
send(T) -> stream<T>
}
)
-pure fn Matrix4<T:copy Num>(m11: T, m12: T, m13: T, m14: T,
+pure fn Matrix4<T:Copy Num>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T)
}
}
-struct Matrix4<T:copy Num> {
+struct Matrix4<T:Copy Num> {
m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
-fn quux<T: copy>(x: T) -> T { let f = id::<T>; return f(x); }
+fn quux<T: Copy>(x: T) -> T { let f = id::<T>; return f(x); }
-fn id<T: copy>(x: T) -> T { return x; }
+fn id<T: Copy>(x: T) -> T { return x; }
fn main() { assert (quux(10) == 10); }
-fn double<T: copy>(a: T) -> ~[T] { return ~[a] + ~[a]; }
+fn double<T: Copy>(a: T) -> ~[T] { return ~[a] + ~[a]; }
fn double_int(a: int) -> ~[int] { return ~[a] + ~[a]; }
trait repeat<A> { fn get() -> A; }
-impl<A:copy> @A: repeat<A> {
+impl<A:Copy> @A: repeat<A> {
fn get() -> A { *self }
}
-fn repeater<A:copy>(v: @A) -> repeat<A> {
+fn repeater<A:Copy>(v: @A) -> repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
v as repeat::<A> // No
}
trait vec_monad<A> {
- fn bind<B: copy>(f: fn(A) -> ~[B]) -> ~[B];
+ fn bind<B: Copy>(f: fn(A) -> ~[B]) -> ~[B];
}
impl<A> ~[A]: vec_monad<A> {
- fn bind<B: copy>(f: fn(A) -> ~[B]) -> ~[B] {
+ fn bind<B: Copy>(f: fn(A) -> ~[B]) -> ~[B] {
let mut r = ~[];
for self.each |elt| { r += f(elt); }
r
enum myvec<X> = ~[X];
-fn myvec_deref<X: copy>(mv: myvec<X>) -> ~[X] { return *mv; }
+fn myvec_deref<X: Copy>(mv: myvec<X>) -> ~[X] { return *mv; }
-fn myvec_elt<X: copy>(mv: myvec<X>) -> X { return mv[0]; }
+fn myvec_elt<X: Copy>(mv: myvec<X>) -> X { return mv[0]; }
fn main() {
let mv = myvec(~[1, 2, 3]);
use std::list::*;
-pure fn pure_length_go<T: copy>(ls: @List<T>, acc: uint) -> uint {
+pure fn pure_length_go<T: Copy>(ls: @List<T>, acc: uint) -> uint {
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
}
-pure fn pure_length<T: copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
+pure fn pure_length<T: Copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
-pure fn nonempty_list<T: copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
+pure fn nonempty_list<T: Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
-fn safe_head<T: copy>(ls: @List<T>) -> T {
+fn safe_head<T: Copy>(ls: @List<T>) -> T {
assert is_not_empty(ls);
return head(ls);
}
{ $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
)
-fn switch<T: send, U>(+endp: pipes::RecvPacket<T>,
+fn switch<T: Send, U>(+endp: pipes::RecvPacket<T>,
f: fn(+Option<T>) -> U) -> U {
f(pipes::try_recv(endp))
}
)
proto! stream (
- stream:send<T:send> {
+ stream:send<T:Send> {
send(T) -> stream<T>
}
)
-struct finish<T: copy> {
+struct finish<T: Copy> {
arg: {val: T, fin: extern fn(T)},
drop { self.arg.fin(self.arg.val); }
}
-fn finish<T: copy>(arg: {val: T, fin: extern fn(T)}) -> finish<T> {
+fn finish<T: Copy>(arg: {val: T, fin: extern fn(T)}) -> finish<T> {
finish {
arg: arg
}
enum option<T> { none, some(T), }
-fn f<T: copy>() -> option<T> { return none; }
+fn f<T: Copy>() -> option<T> { return none; }
fn main() { f::<int>(); }
use comm::Port;
// tests that ctrl's type gets inferred properly
-type command<K: send, V: send> = {key: K, val: V};
+type command<K: Send, V: Send> = {key: K, val: V};
-fn cache_server<K: send, V: send>(c: Chan<Chan<command<K, V>>>) {
+fn cache_server<K: Send, V: Send>(c: Chan<Chan<command<K, V>>>) {
let ctrl = Port();
send(c, Chan(ctrl));
}
fn main() { test05(); }
-fn mk_counter<A:copy>() -> fn~(A) -> (A,uint) {
+fn mk_counter<A:Copy>() -> fn~(A) -> (A,uint) {
// The only reason that the counter is generic is so that it closes
// over both a type descriptor and some data.
let v = ~[mut 0u];
type pair<A,B> = { a: A, b: B };
-fn make_generic_record<A: copy, B: copy>(a: A, b: B) -> pair<A,B> {
+fn make_generic_record<A: Copy, B: Copy>(a: A, b: B) -> pair<A,B> {
return {a: a, b: b};
}
assert q.b == ~"Ho";
}
-fn spawn<A: copy, B: copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
+fn spawn<A: Copy, B: Copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
let arg = fn~(a: A, b: B) -> pair<A,B> {
return make_generic_record(a, b);
};
trait vec_utils<T> {
fn length_() -> uint;
fn iter_(f: fn(T));
- fn map_<U: copy>(f: fn(T) -> U) -> ~[U];
+ fn map_<U: Copy>(f: fn(T) -> U) -> ~[U];
}
impl<T> ~[T]: vec_utils<T> {
fn length_() -> uint { vec::len(self) }
fn iter_(f: fn(T)) { for self.each |x| { f(x); } }
- fn map_<U: copy>(f: fn(T) -> U) -> ~[U] {
+ fn map_<U: Copy>(f: fn(T) -> U) -> ~[U] {
let mut r = ~[];
for self.each |elt| { r += ~[f(elt)]; }
r
static fn select<A>(b: self, +x1: A, +x2: A) -> A;
}
-fn andand<T: bool_like copy>(x1: T, x2: T) -> T {
+fn andand<T: bool_like Copy>(x1: T, x2: T) -> T {
select(x1, x2, x1)
}
}
trait map<T> {
- fn map<U: copy>(f: fn(T) -> U) -> ~[U];
+ fn map<U: Copy>(f: fn(T) -> U) -> ~[U];
}
impl<T> ~[T]: map<T> {
- fn map<U: copy>(f: fn(T) -> U) -> ~[U] {
+ fn map<U: Copy>(f: fn(T) -> U) -> ~[U] {
let mut r = ~[];
for self.each |x| { r += ~[f(x)]; }
r
fn p_foo<T>(pinned: T) { }
-fn s_foo<T: copy>(shared: T) { }
-fn u_foo<T: send>(unique: T) { }
+fn s_foo<T: Copy>(shared: T) { }
+fn u_foo<T: Send>(unique: T) { }
struct r {
i: int,
d : fn~() -> uint,
};
-fn make_uniq_closure<A:send copy>(a: A) -> fn~() -> uint {
+fn make_uniq_closure<A:Send Copy>(a: A) -> fn~() -> uint {
fn~() -> uint { ptr::addr_of(a) as uint }
}
-fn f<T: copy>(t: T) -> T {
+fn f<T: Copy>(t: T) -> T {
let t1 = t;
t1
}
// Issue #976
-fn f<T: copy>(x: ~T) {
+fn f<T: Copy>(x: ~T) {
let _x2 = x;
}
fn main() { }
fn sendable() {
- fn f<T: send Eq>(i: T, j: T) {
+ fn f<T: Send Eq>(i: T, j: T) {
assert i == j;
}
- fn g<T: send Eq>(i: T, j: T) {
+ fn g<T: Send Eq>(i: T, j: T) {
assert i != j;
}
fn copyable() {
- fn f<T: copy Eq>(i: T, j: T) {
+ fn f<T: Copy Eq>(i: T, j: T) {
assert i == j;
}
- fn g<T: copy Eq>(i: T, j: T) {
+ fn g<T: Copy Eq>(i: T, j: T) {
assert i != j;
}