mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-11 01:17:39 +00:00
Convert all kind bounds to camel case. Remove send, owned keywords.
This commit is contained in:
parent
07fe5611ad
commit
3bd1f32cd9
10
doc/rust.md
10
doc/rust.md
@ -449,7 +449,7 @@ Two examples of paths with type arguments:
|
|||||||
~~~~
|
~~~~
|
||||||
# use std::map;
|
# use std::map;
|
||||||
# fn f() {
|
# 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
|
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
|
let x = id::<int>(10); // Type arguments used in a call expression
|
||||||
# }
|
# }
|
||||||
@ -1056,7 +1056,7 @@ An example of a pure function that uses an unchecked block:
|
|||||||
~~~~
|
~~~~
|
||||||
# use std::list::*;
|
# 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 {
|
match ls {
|
||||||
Nil => u,
|
Nil => u,
|
||||||
Cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
|
Cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
|
||||||
@ -1110,7 +1110,7 @@ type can always be moved, but they can only be copied when the
|
|||||||
parameter is given a [`copy` bound](#type-kinds).
|
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
|
Similarly, [trait](#traits) bounds can be specified for type
|
||||||
@ -2638,7 +2638,7 @@ Every struct item defines a type.
|
|||||||
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
|
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 ~[]; }
|
if xs.len() == 0 { return ~[]; }
|
||||||
let first: B = f(xs[0]);
|
let first: B = f(xs[0]);
|
||||||
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
|
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
|
||||||
@ -2706,7 +2706,7 @@ Putting `x` into a shared box involves copying, and the `T` parameter
|
|||||||
is assumed to be noncopyable. To change that, a bound is declared:
|
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
|
Calling this second version of `box` on a noncopyable type is not
|
||||||
|
@ -1583,20 +1583,20 @@ unless you explicitly declare that type parameter to have copyable
|
|||||||
// This does not compile
|
// This does not compile
|
||||||
fn head_bad<T>(v: ~[T]) -> T { v[0] }
|
fn head_bad<T>(v: ~[T]) -> T { v[0] }
|
||||||
// This does
|
// 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
|
When instantiating a generic function, you can only instantiate it
|
||||||
with types that fit its kinds. So you could not apply `head` to a
|
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:
|
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
|
are classes with destructors or otherwise contain
|
||||||
classes with destructors.
|
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
|
contain shared boxes, closures, or other local-heap-allocated
|
||||||
types.
|
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.
|
mutable fields nor shared boxes.
|
||||||
|
|
||||||
> ***Note:*** Rust type kinds are syntactically very similar to
|
> ***Note:*** Rust type kinds are syntactically very similar to
|
||||||
@ -2002,7 +2002,7 @@ and one for values. This means that this code is valid:
|
|||||||
~~~~
|
~~~~
|
||||||
mod buffalo {
|
mod buffalo {
|
||||||
type buffalo = int;
|
type buffalo = int;
|
||||||
fn buffalo<buffalo: copy>(buffalo: buffalo) -> buffalo { buffalo }
|
fn buffalo<buffalo>(+buffalo: buffalo) -> buffalo { buffalo }
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let buffalo: buffalo::buffalo = 1;
|
let buffalo: buffalo::buffalo = 1;
|
||||||
|
@ -239,7 +239,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
|
|||||||
pprust::ty_to_str, replace_ty_in_crate, cx);
|
pprust::ty_to_str, replace_ty_in_crate, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_variants_T<T: copy>(
|
fn check_variants_T<T: Copy>(
|
||||||
crate: ast::crate,
|
crate: ast::crate,
|
||||||
codemap: codemap::codemap,
|
codemap: codemap::codemap,
|
||||||
filename: &Path,
|
filename: &Path,
|
||||||
|
@ -89,7 +89,7 @@ pure fn build_sized_opt<A>(size: Option<uint>,
|
|||||||
|
|
||||||
// Appending
|
// Appending
|
||||||
#[inline(always)]
|
#[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| {
|
do build_sized(lhs.len() + rhs.len()) |push| {
|
||||||
for vec::each(lhs) |x| { push(x); }
|
for vec::each(lhs) |x| { push(x); }
|
||||||
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
|
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
|
||||||
@ -125,7 +125,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
|
|||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value `t`.
|
* 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| {
|
do build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(t); i += 1u; }
|
while i < n_elts { push(t); i += 1u; }
|
||||||
@ -133,7 +133,7 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> @[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T: copy> @[T]: Add<&[const T],@[T]> {
|
impl<T: Copy> @[T]: Add<&[const T],@[T]> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(rhs: &[const T]) -> @[T] {
|
pure fn add(rhs: &[const T]) -> @[T] {
|
||||||
append(self, rhs)
|
append(self, rhs)
|
||||||
|
@ -48,7 +48,7 @@ export listen;
|
|||||||
* transmitted. If a port value is copied, both copies refer to the same
|
* transmitted. If a port value is copied, both copies refer to the same
|
||||||
* port. Ports may be associated with multiple `chan`s.
|
* port. Ports may be associated with multiple `chan`s.
|
||||||
*/
|
*/
|
||||||
enum Port<T: send> {
|
enum Port<T: Send> {
|
||||||
Port_(@PortPtr<T>)
|
Port_(@PortPtr<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,16 +64,16 @@ enum Port<T: send> {
|
|||||||
* data will be silently dropped. Channels may be duplicated and
|
* data will be silently dropped. Channels may be duplicated and
|
||||||
* themselves transmitted over other channels.
|
* themselves transmitted over other channels.
|
||||||
*/
|
*/
|
||||||
enum Chan<T: send> {
|
enum Chan<T: Send> {
|
||||||
Chan_(port_id)
|
Chan_(port_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a port
|
/// 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)))
|
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 chan() -> Chan<T> { Chan(self) }
|
||||||
fn send(+v: T) { self.chan().send(v) }
|
fn send(+v: T) { self.chan().send(v) }
|
||||||
@ -82,7 +82,7 @@ impl<T: send> Port<T> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: send> Chan<T> {
|
impl<T: Send> Chan<T> {
|
||||||
|
|
||||||
fn chan() -> Chan<T> { self }
|
fn chan() -> Chan<T> { self }
|
||||||
fn send(+v: T) { send(self, v) }
|
fn send(+v: T) { send(self, v) }
|
||||||
@ -92,12 +92,12 @@ impl<T: send> Chan<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Open a new receiving channel for the duration of a function
|
/// 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();
|
let po = Port();
|
||||||
f(po.chan())
|
f(po.chan())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PortPtr<T:send> {
|
struct PortPtr<T:Send> {
|
||||||
po: *rust_port,
|
po: *rust_port,
|
||||||
drop unsafe {
|
drop unsafe {
|
||||||
do task::unkillable {
|
do task::unkillable {
|
||||||
@ -121,7 +121,7 @@ struct PortPtr<T:send> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PortPtr<T: send>(po: *rust_port) -> PortPtr<T> {
|
fn PortPtr<T: Send>(po: *rust_port) -> PortPtr<T> {
|
||||||
PortPtr {
|
PortPtr {
|
||||||
po: po
|
po: po
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ fn PortPtr<T: send>(po: *rust_port) -> PortPtr<T> {
|
|||||||
* Fails if the port is detached or dead. Fails if the port
|
* Fails if the port is detached or dead. Fails if the port
|
||||||
* is owned by a different task.
|
* 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 {
|
struct PortRef {
|
||||||
p: *rust_port,
|
p: *rust_port,
|
||||||
@ -167,7 +167,7 @@ fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
|
|||||||
* Constructs a channel. The channel is bound to the port used to
|
* Constructs a channel. The channel is bound to the port used to
|
||||||
* construct it.
|
* 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))
|
Chan_(rustrt::get_port_id((**p).po))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ fn Chan<T: send>(p: Port<T>) -> Chan<T> {
|
|||||||
* Sends data over a channel. The sent data is moved into the channel,
|
* Sends data over a channel. The sent data is moved into the channel,
|
||||||
* whereupon the caller loses access to it.
|
* 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 Chan_(p) = ch;
|
||||||
let data_ptr = ptr::addr_of(data) as *();
|
let data_ptr = ptr::addr_of(data) as *();
|
||||||
let res = rustrt::rust_port_id_send(p, data_ptr);
|
let res = rustrt::rust_port_id_send(p, data_ptr);
|
||||||
@ -190,22 +190,22 @@ fn send<T: send>(ch: Chan<T>, +data: T) {
|
|||||||
* Receive from a port. If no data is available on the port then the
|
* Receive from a port. If no data is available on the port then the
|
||||||
* task will block until data becomes available.
|
* 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
|
/// 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)]
|
#[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))
|
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))
|
as_raw_port(ch, |x|peek_(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive on a raw port pointer
|
/// 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 yield = 0u;
|
||||||
let yieldp = ptr::addr_of(yield);
|
let yieldp = ptr::addr_of(yield);
|
||||||
let mut res;
|
let mut res;
|
||||||
@ -231,7 +231,7 @@ fn peek_(p: *rust_port) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Receive on one of two ports
|
/// 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> {
|
-> Either<A, B> {
|
||||||
let ports = ~[(**p_a).po, (**p_b).po];
|
let ports = ~[(**p_a).po, (**p_b).po];
|
||||||
let yield = 0u, yieldp = ptr::addr_of(yield);
|
let yield = 0u, yieldp = ptr::addr_of(yield);
|
||||||
|
@ -96,7 +96,7 @@ pure fn from_elem<T>(+data: T) -> DList<T> {
|
|||||||
list
|
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| {
|
do vec::foldl(DList(), vec) |list,data| {
|
||||||
list.push(data); // Iterating left-to-right -- add newly to the tail.
|
list.push(data); // Iterating left-to-right -- add newly to the tail.
|
||||||
list
|
list
|
||||||
@ -417,7 +417,7 @@ impl<T> DList<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: copy> DList<T> {
|
impl<T: Copy> DList<T> {
|
||||||
/// Remove data from the head of the list. O(1).
|
/// Remove data from the head of the list. O(1).
|
||||||
fn pop() -> Option<T> { self.pop_n().map (|nobe| nobe.data) }
|
fn pop() -> Option<T> { self.pop_n().map (|nobe| nobe.data) }
|
||||||
/// Remove data from the tail of the list. O(1).
|
/// Remove data from the tail of the list. O(1).
|
||||||
|
@ -210,7 +210,7 @@ impl<A> DVec<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: copy> DVec<A> {
|
impl<A: Copy> DVec<A> {
|
||||||
/**
|
/**
|
||||||
* Append all elements of a vector to the end of the list
|
* Append all elements of a vector to the end of the list
|
||||||
*
|
*
|
||||||
@ -327,7 +327,7 @@ impl<A: copy> DVec<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:copy> DVec<A>: Index<uint,A> {
|
impl<A:Copy> DVec<A>: Index<uint,A> {
|
||||||
pure fn index(&&idx: uint) -> A {
|
pure fn index(&&idx: uint) -> A {
|
||||||
self.get_elt(idx)
|
self.get_elt(idx)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ fn either<T, U, V>(f_left: fn((&T)) -> V,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
//! Extracts from a vector of either all the left values
|
||||||
|
|
||||||
let mut result: ~[T] = ~[];
|
let mut result: ~[T] = ~[];
|
||||||
@ -42,7 +42,7 @@ fn lefts<T: copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
|
|||||||
return result;
|
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
|
//! Extracts from a vector of either all the right values
|
||||||
|
|
||||||
let mut result: ~[U] = ~[];
|
let mut result: ~[U] = ~[];
|
||||||
@ -55,7 +55,7 @@ fn rights<T, U: copy>(eithers: &[Either<T, U>]) -> ~[U] {
|
|||||||
return result;
|
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]} {
|
-> {lefts: ~[T], rights: ~[U]} {
|
||||||
/*!
|
/*!
|
||||||
* Extracts from a vector of either all the left values and right values
|
* Extracts from a vector of either all the left values and right values
|
||||||
@ -75,7 +75,7 @@ fn partition<T: copy, U: copy>(eithers: &[Either<T, U>])
|
|||||||
return {lefts: lefts, rights: rights};
|
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
|
//! Flips between left and right of a given either
|
||||||
|
|
||||||
match *eith {
|
match *eith {
|
||||||
@ -84,7 +84,7 @@ pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* Converts either::t to a result::t
|
||||||
*
|
*
|
||||||
|
@ -43,7 +43,7 @@ priv enum FutureState<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Methods on the `future` type
|
/// Methods on the `future` type
|
||||||
impl<A:copy> Future<A> {
|
impl<A:Copy> Future<A> {
|
||||||
fn get() -> A {
|
fn get() -> A {
|
||||||
//! Get the value of the future
|
//! Get the value of the future
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ fn from_value<A>(+val: A) -> Future<A> {
|
|||||||
Future {state: Forced(val)}
|
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
|
* Create a future from a port
|
||||||
*
|
*
|
||||||
@ -105,7 +105,7 @@ fn from_fn<A>(+f: @fn() -> A) -> Future<A> {
|
|||||||
Future {state: Pending(f)}
|
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.
|
* Create a future from a unique closure.
|
||||||
*
|
*
|
||||||
@ -156,7 +156,7 @@ fn get_ref<A>(future: &r/Future<A>) -> &r/A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get<A:copy>(future: &Future<A>) -> A {
|
fn get<A:Copy>(future: &Future<A>) -> A {
|
||||||
//! Get the value of the future
|
//! Get the value of the future
|
||||||
|
|
||||||
*get_ref(future)
|
*get_ref(future)
|
||||||
@ -169,7 +169,7 @@ fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proto! future_pipe (
|
proto! future_pipe (
|
||||||
waiting:recv<T:send> {
|
waiting:recv<T:Send> {
|
||||||
completed(T) -> !
|
completed(T) -> !
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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] {
|
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> {
|
|||||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
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 min() -> A { iter::min(self) }
|
||||||
pure fn max() -> A { iter::max(self) }
|
pure fn max() -> A { iter::max(self) }
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,14 @@ trait TimesIx{
|
|||||||
pure fn timesi(it: fn(uint) -> bool);
|
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 filter_to_vec(pred: fn(A) -> bool) -> ~[A];
|
||||||
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
|
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
|
||||||
pure fn to_vec() -> ~[A];
|
pure fn to_vec() -> ~[A];
|
||||||
pure fn find(p: fn(A) -> bool) -> Option<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 min() -> A;
|
||||||
pure fn max() -> A;
|
pure fn max() -> A;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ pure fn any<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
|
|||||||
return false;
|
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] {
|
prd: fn(A) -> bool) -> ~[A] {
|
||||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
@ -91,7 +91,7 @@ pure fn filter_to_vec<A:copy,IA:BaseIter<A>>(self: IA,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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] {
|
-> ~[B] {
|
||||||
do vec::build_sized_opt(self.size_hint()) |push| {
|
do vec::build_sized_opt(self.size_hint()) |push| {
|
||||||
for self.each |a| {
|
for self.each |a| {
|
||||||
@ -100,7 +100,7 @@ pure fn map_to_vec<A:copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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] {
|
self: IA, op: fn(A) -> IB) -> ~[B] {
|
||||||
|
|
||||||
do vec::build |push| {
|
do vec::build |push| {
|
||||||
@ -120,7 +120,7 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
|
|||||||
return b;
|
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]))
|
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ pure fn repeat(times: uint, blk: fn() -> bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
Some(a_) if a_ < b => {
|
Some(a_) if a_ < b => {
|
||||||
@ -179,7 +179,7 @@ pure fn min<A:copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
Some(a_) if a_ > b => {
|
Some(a_) if a_ > b => {
|
||||||
@ -195,7 +195,7 @@ pure fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
p: fn(A) -> bool) -> Option<A> {
|
||||||
for self.each |i| {
|
for self.each |i| {
|
||||||
if p(i) { return Some(i) }
|
if p(i) { return Some(i) }
|
||||||
@ -271,7 +271,7 @@ pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
|
|||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value `t`.
|
* 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| {
|
do build_sized(n_elts) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(t); i += 1u; }
|
while i < n_elts { push(t); i += 1u; }
|
||||||
@ -280,7 +280,7 @@ pure fn from_elem<T: copy,BT: Buildable<T>>(n_elts: uint, t: T) -> BT {
|
|||||||
|
|
||||||
/// Appending two generic sequences
|
/// Appending two generic sequences
|
||||||
#[inline(always)]
|
#[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 {
|
lhs: IT, rhs: IT) -> BT {
|
||||||
let size_opt = lhs.size_hint().chain(
|
let size_opt = lhs.size_hint().chain(
|
||||||
|sz1| rhs.size_hint().map(|sz2| sz1+sz2));
|
|sz1| rhs.size_hint().map(|sz2| sz1+sz2));
|
||||||
@ -293,7 +293,7 @@ pure fn append<T: copy,IT: BaseIter<T>,BT: Buildable<T>>(
|
|||||||
/// Copies a generic sequence, possibly converting it to a different
|
/// Copies a generic sequence, possibly converting it to a different
|
||||||
/// type of sequence.
|
/// type of sequence.
|
||||||
#[inline(always)]
|
#[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 {
|
v: IT) -> BT {
|
||||||
do build_sized_opt(v.size_hint()) |push| {
|
do build_sized_opt(v.size_hint()) |push| {
|
||||||
for v.each |x| { push(x); }
|
for v.each |x| { push(x); }
|
||||||
|
@ -16,7 +16,7 @@ enum Option<T> {
|
|||||||
Some(T),
|
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
|
* Gets the value out of an option
|
||||||
*
|
*
|
||||||
@ -45,7 +45,7 @@ pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* Gets the value out of an option, printing a specified message on
|
||||||
* failure
|
* failure
|
||||||
@ -128,7 +128,7 @@ pure fn is_some<T>(opt: Option<T>) -> bool {
|
|||||||
!is_none(opt)
|
!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
|
//! Returns the contained value or a default
|
||||||
|
|
||||||
match opt { Some(x) => x, None => def }
|
match opt { Some(x) => x, None => def }
|
||||||
@ -226,7 +226,7 @@ impl<T> &Option<T> {
|
|||||||
pure fn get_ref() -> &self/T { get_ref(self) }
|
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
|
* Gets the value out of an option
|
||||||
*
|
*
|
||||||
|
@ -152,7 +152,7 @@ fn buffer_header() -> BufferHeader { BufferHeader() }
|
|||||||
|
|
||||||
// This is for protocols to associate extra data to thread around.
|
// This is for protocols to associate extra data to thread around.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
type Buffer<T: send> = {
|
type Buffer<T: Send> = {
|
||||||
header: BufferHeader,
|
header: BufferHeader,
|
||||||
data: T,
|
data: T,
|
||||||
};
|
};
|
||||||
@ -191,7 +191,7 @@ struct PacketHeader {
|
|||||||
reinterpret_cast(&self.buffer)
|
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);
|
self.buffer = reinterpret_cast(&b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ fn PacketHeader() -> PacketHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
type Packet<T: send> = {
|
type Packet<T: Send> = {
|
||||||
header: PacketHeader,
|
header: PacketHeader,
|
||||||
mut payload: Option<T>,
|
mut payload: Option<T>,
|
||||||
};
|
};
|
||||||
@ -213,7 +213,7 @@ type Packet<T: send> = {
|
|||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
type packet<T: send> = Packet<T>;
|
type packet<T: Send> = Packet<T>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
trait HasBuffer {
|
trait HasBuffer {
|
||||||
@ -221,7 +221,7 @@ trait HasBuffer {
|
|||||||
fn set_buffer_(b: *libc::c_void);
|
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) {
|
fn set_buffer_(b: *libc::c_void) {
|
||||||
self.header.buffer = b;
|
self.header.buffer = b;
|
||||||
}
|
}
|
||||||
@ -235,14 +235,14 @@ trait has_buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(stage0)] // XXX remove me
|
#[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) {
|
fn set_buffer(b: *libc::c_void) {
|
||||||
self.header.buffer = b;
|
self.header.buffer = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn mk_packet<T: send>() -> Packet<T> {
|
fn mk_packet<T: Send>() -> Packet<T> {
|
||||||
{
|
{
|
||||||
header: PacketHeader(),
|
header: PacketHeader(),
|
||||||
mut payload: None
|
mut payload: None
|
||||||
@ -250,7 +250,7 @@ fn mk_packet<T: send>() -> Packet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
|
fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
|
||||||
let b = ~{
|
let b = ~{
|
||||||
header: BufferHeader(),
|
header: BufferHeader(),
|
||||||
data: {
|
data: {
|
||||||
@ -267,7 +267,7 @@ fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn packet<T: send>() -> *Packet<T> {
|
fn packet<T: Send>() -> *Packet<T> {
|
||||||
let b = unibuffer();
|
let b = unibuffer();
|
||||||
let p = ptr::addr_of(b.data);
|
let p = ptr::addr_of(b.data);
|
||||||
// We'll take over memory management from here.
|
// We'll take over memory management from here.
|
||||||
@ -276,7 +276,7 @@ fn packet<T: send>() -> *Packet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn entangle_buffer<T: send, Tstart: send>(
|
fn entangle_buffer<T: Send, Tstart: Send>(
|
||||||
+buffer: ~Buffer<T>,
|
+buffer: ~Buffer<T>,
|
||||||
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
||||||
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
||||||
@ -368,12 +368,12 @@ fn swap_state_rel(+dst: &mut State, src: State) -> State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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())
|
transmute((*p).buf_header())
|
||||||
}
|
}
|
||||||
|
|
||||||
// This could probably be done with SharedMutableState to avoid move_it!().
|
// This could probably be done with SharedMutableState to avoid move_it!().
|
||||||
struct BufferResource<T: send> {
|
struct BufferResource<T: Send> {
|
||||||
buffer: ~Buffer<T>,
|
buffer: ~Buffer<T>,
|
||||||
|
|
||||||
drop unsafe {
|
drop unsafe {
|
||||||
@ -393,7 +393,7 @@ struct BufferResource<T: send> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn BufferResource<T: send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
fn BufferResource<T: Send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
||||||
//let p = ptr::addr_of(*b);
|
//let p = ptr::addr_of(*b);
|
||||||
//error!("take %?", p);
|
//error!("take %?", p);
|
||||||
atomic_add_acq(&mut b.header.ref_count, 1);
|
atomic_add_acq(&mut b.header.ref_count, 1);
|
||||||
@ -404,7 +404,7 @@ fn BufferResource<T: send>(+b: ~Buffer<T>) -> BufferResource<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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 {
|
+payload: T) -> bool {
|
||||||
let header = p.header();
|
let header = p.header();
|
||||||
let p_ = p.unwrap();
|
let p_ = p.unwrap();
|
||||||
@ -448,7 +448,7 @@ fn send<T: send, Tbuffer: send>(+p: SendPacketBuffered<T, Tbuffer>,
|
|||||||
Fails if the sender closes the connection.
|
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")
|
option::unwrap_expect(try_recv(p), "connection closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ Returns `none` if the sender has closed the connection without sending
|
|||||||
a message, or `Some(T)` if a message was received.
|
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>
|
-> Option<T>
|
||||||
{
|
{
|
||||||
let p_ = p.unwrap();
|
let p_ = p.unwrap();
|
||||||
@ -552,7 +552,7 @@ fn try_recv<T: send, Tbuffer: send>(+p: RecvPacketBuffered<T, Tbuffer>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if messages are available.
|
/// 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} {
|
match unsafe {(*p.header()).state} {
|
||||||
Empty => false,
|
Empty => false,
|
||||||
Blocked => fail ~"peeking on blocked packet",
|
Blocked => fail ~"peeking on blocked packet",
|
||||||
@ -560,14 +560,14 @@ pure fn peek<T: send, Tb: send>(p: &RecvPacketBuffered<T, Tb>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: send, Tb: send> RecvPacketBuffered<T, Tb> {
|
impl<T: Send, Tb: Send> RecvPacketBuffered<T, Tb> {
|
||||||
pure fn peek() -> bool {
|
pure fn peek() -> bool {
|
||||||
peek(&self)
|
peek(&self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn sender_terminate<T: send>(p: *Packet<T>) {
|
fn sender_terminate<T: Send>(p: *Packet<T>) {
|
||||||
let p = unsafe { &*p };
|
let p = unsafe { &*p };
|
||||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||||
Empty => {
|
Empty => {
|
||||||
@ -596,7 +596,7 @@ fn sender_terminate<T: send>(p: *Packet<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn receiver_terminate<T: send>(p: *Packet<T>) {
|
fn receiver_terminate<T: Send>(p: *Packet<T>) {
|
||||||
let p = unsafe { &*p };
|
let p = unsafe { &*p };
|
||||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||||
Empty => {
|
Empty => {
|
||||||
@ -704,7 +704,7 @@ Sometimes messages will be available on both endpoints at once. In
|
|||||||
this case, `select2` may return either `left` or `right`.
|
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>,
|
+a: RecvPacketBuffered<A, Ab>,
|
||||||
+b: RecvPacketBuffered<B, Bb>)
|
+b: RecvPacketBuffered<B, Bb>)
|
||||||
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
|
-> Either<(Option<A>, RecvPacketBuffered<B, Bb>),
|
||||||
@ -746,7 +746,7 @@ fn select2i<A: Selectable, B: Selectable>(a: &A, b: &B) -> Either<(), ()> {
|
|||||||
list of the remaining endpoints.
|
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>])
|
-> (uint, Option<T>, ~[RecvPacketBuffered<T, Tb>])
|
||||||
{
|
{
|
||||||
let ready = wait_many(endpoints.map(|p| p.header()));
|
let ready = wait_many(endpoints.map(|p| p.header()));
|
||||||
@ -760,25 +760,25 @@ fn select<T: send, Tb: send>(+endpoints: ~[RecvPacketBuffered<T, Tb>])
|
|||||||
message.
|
message.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
type SendPacket<T: send> = SendPacketBuffered<T, Packet<T>>;
|
type SendPacket<T: Send> = SendPacketBuffered<T, Packet<T>>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn SendPacket<T: send>(p: *Packet<T>) -> SendPacket<T> {
|
fn SendPacket<T: Send>(p: *Packet<T>) -> SendPacket<T> {
|
||||||
SendPacketBuffered(p)
|
SendPacketBuffered(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
type send_packet<T: send> = SendPacket<T>;
|
type send_packet<T: Send> = SendPacket<T>;
|
||||||
|
|
||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
fn send_packet<T: send>(p: *packet<T>) -> SendPacket<T> {
|
fn send_packet<T: Send>(p: *packet<T>) -> SendPacket<T> {
|
||||||
SendPacket(p)
|
SendPacket(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SendPacketBuffered<T: send, Tbuffer: send> {
|
struct SendPacketBuffered<T: Send, Tbuffer: Send> {
|
||||||
mut p: Option<*Packet<T>>,
|
mut p: Option<*Packet<T>>,
|
||||||
mut buffer: Option<BufferResource<Tbuffer>>,
|
mut buffer: Option<BufferResource<Tbuffer>>,
|
||||||
drop {
|
drop {
|
||||||
@ -821,7 +821,7 @@ struct SendPacketBuffered<T: send, Tbuffer: send> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SendPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
||||||
-> SendPacketBuffered<T, Tbuffer> {
|
-> SendPacketBuffered<T, Tbuffer> {
|
||||||
//debug!("take send %?", p);
|
//debug!("take send %?", p);
|
||||||
SendPacketBuffered {
|
SendPacketBuffered {
|
||||||
@ -836,30 +836,30 @@ fn SendPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
|||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
type send_packet_buffered<T: send, Tbuffer: send> =
|
type send_packet_buffered<T: Send, Tbuffer: Send> =
|
||||||
SendPacketBuffered<T, Tbuffer>;
|
SendPacketBuffered<T, Tbuffer>;
|
||||||
|
|
||||||
/// Represents the receive end of a pipe. It can receive exactly one
|
/// Represents the receive end of a pipe. It can receive exactly one
|
||||||
/// message.
|
/// message.
|
||||||
type RecvPacket<T: send> = RecvPacketBuffered<T, Packet<T>>;
|
type RecvPacket<T: Send> = RecvPacketBuffered<T, Packet<T>>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn RecvPacket<T: send>(p: *Packet<T>) -> RecvPacket<T> {
|
fn RecvPacket<T: Send>(p: *Packet<T>) -> RecvPacket<T> {
|
||||||
RecvPacketBuffered(p)
|
RecvPacketBuffered(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
type recv_packet<T: send> = RecvPacket<T>;
|
type recv_packet<T: Send> = RecvPacket<T>;
|
||||||
|
|
||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
fn recv_packet<T: send>(p: *packet<T>) -> RecvPacket<T> {
|
fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
|
||||||
RecvPacket(p)
|
RecvPacket(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RecvPacketBuffered<T: send, Tbuffer: send> : Selectable {
|
struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
|
||||||
mut p: Option<*Packet<T>>,
|
mut p: Option<*Packet<T>>,
|
||||||
mut buffer: Option<BufferResource<Tbuffer>>,
|
mut buffer: Option<BufferResource<Tbuffer>>,
|
||||||
drop {
|
drop {
|
||||||
@ -902,7 +902,7 @@ struct RecvPacketBuffered<T: send, Tbuffer: send> : Selectable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn RecvPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
||||||
-> RecvPacketBuffered<T, Tbuffer> {
|
-> RecvPacketBuffered<T, Tbuffer> {
|
||||||
//debug!("take recv %?", p);
|
//debug!("take recv %?", p);
|
||||||
RecvPacketBuffered {
|
RecvPacketBuffered {
|
||||||
@ -917,11 +917,11 @@ fn RecvPacketBuffered<T: send, Tbuffer: send>(p: *Packet<T>)
|
|||||||
// XXX remove me
|
// XXX remove me
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
type recv_packet_buffered<T: send, Tbuffer: send> =
|
type recv_packet_buffered<T: Send, Tbuffer: Send> =
|
||||||
RecvPacketBuffered<T, Tbuffer>;
|
RecvPacketBuffered<T, Tbuffer>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn entangle<T: send>() -> (SendPacket<T>, RecvPacket<T>) {
|
fn entangle<T: Send>() -> (SendPacket<T>, RecvPacket<T>) {
|
||||||
let p = packet();
|
let p = packet();
|
||||||
(SendPacket(p), RecvPacket(p))
|
(SendPacket(p), RecvPacket(p))
|
||||||
}
|
}
|
||||||
@ -933,7 +933,7 @@ endpoint. The send endpoint is returned to the caller and the receive
|
|||||||
endpoint is passed to the new task.
|
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>,
|
init: extern fn() -> (SendPacketBuffered<T, Tb>,
|
||||||
RecvPacketBuffered<T, Tb>),
|
RecvPacketBuffered<T, Tb>),
|
||||||
+service: fn~(+RecvPacketBuffered<T, Tb>))
|
+service: fn~(+RecvPacketBuffered<T, Tb>))
|
||||||
@ -957,7 +957,7 @@ fn spawn_service<T: send, Tb: send>(
|
|||||||
receive state.
|
receive state.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
fn spawn_service_recv<T: send, Tb: send>(
|
fn spawn_service_recv<T: Send, Tb: Send>(
|
||||||
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
|
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
|
||||||
SendPacketBuffered<T, Tb>),
|
SendPacketBuffered<T, Tb>),
|
||||||
+service: fn~(+SendPacketBuffered<T, Tb>))
|
+service: fn~(+SendPacketBuffered<T, Tb>))
|
||||||
@ -980,13 +980,13 @@ fn spawn_service_recv<T: send, Tb: send>(
|
|||||||
// Streams - Make pipes a little easier in general.
|
// Streams - Make pipes a little easier in general.
|
||||||
|
|
||||||
proto! streamp (
|
proto! streamp (
|
||||||
Open:send<T: send> {
|
Open:send<T: Send> {
|
||||||
data(T) -> Open<T>
|
data(T) -> Open<T>
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
/// A trait for things that can send multiple messages.
|
/// 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
|
// It'd be nice to call this send, but it'd conflict with the
|
||||||
// built in send kind.
|
// built in send kind.
|
||||||
|
|
||||||
@ -998,7 +998,7 @@ trait Channel<T: send> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for things that can receive multiple messages.
|
/// 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.
|
/// Receives a message, or fails if the connection closes.
|
||||||
fn recv() -> T;
|
fn recv() -> T;
|
||||||
|
|
||||||
@ -1016,18 +1016,18 @@ trait Recv<T: send> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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.
|
/// An endpoint that can send many messages.
|
||||||
enum Chan<T:send> {
|
enum Chan<T:Send> {
|
||||||
Chan_(Chan_<T>)
|
Chan_(Chan_<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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.
|
/// An endpoint that can receive many messages.
|
||||||
enum Port<T:send> {
|
enum Port<T:Send> {
|
||||||
Port_(Port_<T>)
|
Port_(Port_<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1036,13 +1036,13 @@ enum Port<T:send> {
|
|||||||
These allow sending or receiving an unlimited number of messages.
|
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();
|
let (c, s) = streamp::init();
|
||||||
|
|
||||||
(Chan_({ mut endp: Some(c) }), Port_({ mut endp: Some(s) }))
|
(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) {
|
fn send(+x: T) {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
@ -1063,7 +1063,7 @@ impl<T: send> Chan<T>: Channel<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: send> Port<T>: Recv<T> {
|
impl<T: Send> Port<T>: Recv<T> {
|
||||||
fn recv() -> T {
|
fn recv() -> T {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
@ -1097,7 +1097,7 @@ impl<T: send> Port<T>: Recv<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Treat many ports as one.
|
/// Treat many ports as one.
|
||||||
struct PortSet<T: send> : Recv<T> {
|
struct PortSet<T: Send> : Recv<T> {
|
||||||
mut ports: ~[pipes::Port<T>],
|
mut ports: ~[pipes::Port<T>],
|
||||||
|
|
||||||
fn add(+port: pipes::Port<T>) {
|
fn add(+port: pipes::Port<T>) {
|
||||||
@ -1146,13 +1146,13 @@ struct PortSet<T: send> : Recv<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PortSet<T: send>() -> PortSet<T>{
|
fn PortSet<T: Send>() -> PortSet<T>{
|
||||||
PortSet {
|
PortSet {
|
||||||
ports: ~[]
|
ports: ~[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: send> Port<T>: Selectable {
|
impl<T: Send> Port<T>: Selectable {
|
||||||
pure fn header() -> *PacketHeader unchecked {
|
pure fn header() -> *PacketHeader unchecked {
|
||||||
match self.endp {
|
match self.endp {
|
||||||
Some(endp) => endp.header(),
|
Some(endp) => endp.header(),
|
||||||
@ -1162,9 +1162,9 @@ impl<T: send> Port<T>: Selectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A channel that can be shared between many senders.
|
/// 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) {
|
fn send(+x: T) {
|
||||||
let mut xx = Some(x);
|
let mut xx = Some(x);
|
||||||
do self.with |chan| {
|
do self.with |chan| {
|
||||||
@ -1185,19 +1185,19 @@ impl<T: send> SharedChan<T>: Channel<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a `chan` into a `shared_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)
|
unsafe::exclusive(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from one of two endpoints.
|
/// 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.
|
/// Receive a message or return `none` if a connection closes.
|
||||||
fn try_select() -> Either<Option<T>, Option<U>>;
|
fn try_select() -> Either<Option<T>, Option<U>>;
|
||||||
/// Receive a message or fail if a connection closes.
|
/// Receive a message or fail if a connection closes.
|
||||||
fn select() -> Either<T, U>;
|
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> {
|
(Left, Right): Select2<T, U> {
|
||||||
|
|
||||||
fn select() -> Either<T, U> {
|
fn select() -> Either<T, U> {
|
||||||
@ -1220,18 +1220,18 @@ impl<T: send, U: send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
proto! oneshot (
|
proto! oneshot (
|
||||||
Oneshot:send<T:send> {
|
Oneshot:send<T:Send> {
|
||||||
send(T) -> !
|
send(T) -> !
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
/// The send end of a oneshot pipe.
|
/// 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.
|
/// 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.
|
/// 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()
|
oneshot::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1239,13 +1239,13 @@ fn oneshot<T: send>() -> (ChanOne<T>, PortOne<T>) {
|
|||||||
* Receive a message from a oneshot pipe, failing if the connection was
|
* Receive a message from a oneshot pipe, failing if the connection was
|
||||||
* closed.
|
* 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);
|
let oneshot::send(message) = recv(port);
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message from a oneshot pipe unless the connection was closed.
|
/// 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);
|
let message = try_recv(port);
|
||||||
|
|
||||||
if message.is_none() { None }
|
if message.is_none() { None }
|
||||||
@ -1256,7 +1256,7 @@ fn try_recv_one<T: send> (+port: PortOne<T>) -> Option<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message on a oneshot pipe, failing if the connection was closed.
|
/// 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);
|
oneshot::client::send(chan, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1264,7 +1264,7 @@ fn send_one<T: send>(+chan: ChanOne<T>, +data: T) {
|
|||||||
* Send a message on a oneshot pipe, or return false if the connection was
|
* Send a message on a oneshot pipe, or return false if the connection was
|
||||||
* closed.
|
* closed.
|
||||||
*/
|
*/
|
||||||
fn try_send_one<T: send>(+chan: ChanOne<T>, +data: T)
|
fn try_send_one<T: Send>(+chan: ChanOne<T>, +data: T)
|
||||||
-> bool {
|
-> bool {
|
||||||
oneshot::client::try_send(chan, data).is_some()
|
oneshot::client::try_send(chan, data).is_some()
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ type GlobalPtr = *libc::uintptr_t;
|
|||||||
* or, if no channel exists creates and installs a new channel and sets up a
|
* or, if no channel exists creates and installs a new channel and sets up a
|
||||||
* new task to receive from it.
|
* new task to receive from it.
|
||||||
*/
|
*/
|
||||||
unsafe fn chan_from_global_ptr<T: send>(
|
unsafe fn chan_from_global_ptr<T: Send>(
|
||||||
global: GlobalPtr,
|
global: GlobalPtr,
|
||||||
task_fn: fn() -> task::TaskBuilder,
|
task_fn: fn() -> task::TaskBuilder,
|
||||||
+f: fn~(comm::Port<T>)
|
+f: fn~(comm::Port<T>)
|
||||||
|
@ -165,12 +165,12 @@ impl Rng {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Choose an item randomly, failing if values is empty
|
/// 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()
|
self.choose_option(values).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Choose Some(item) randomly, returning None if values is empty
|
/// 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() {
|
if values.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -182,7 +182,7 @@ impl Rng {
|
|||||||
* Choose an item respecting the relative weights, failing if the sum of
|
* Choose an item respecting the relative weights, failing if the sum of
|
||||||
* the weights is 0
|
* 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()
|
self.choose_weighted_option(v).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ impl Rng {
|
|||||||
* Choose Some(item) respecting the relative weights, returning none if
|
* Choose Some(item) respecting the relative weights, returning none if
|
||||||
* the sum of the weights is 0
|
* 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;
|
let mut total = 0u;
|
||||||
for v.each |item| {
|
for v.each |item| {
|
||||||
total += item.weight;
|
total += item.weight;
|
||||||
@ -213,7 +213,7 @@ impl Rng {
|
|||||||
* Return a vec containing copies of the items, in order, where
|
* Return a vec containing copies of the items, in order, where
|
||||||
* the weight of the item determines how many copies there are
|
* 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 = ~[];
|
let mut r = ~[];
|
||||||
for v.each |item| {
|
for v.each |item| {
|
||||||
for uint::range(0u, item.weight) |_i| {
|
for uint::range(0u, item.weight) |_i| {
|
||||||
@ -224,7 +224,7 @@ impl Rng {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Shuffle a vec
|
/// Shuffle a vec
|
||||||
fn shuffle<T:copy>(values: &[T]) -> ~[T] {
|
fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
|
||||||
let mut m = vec::from_slice(values);
|
let mut m = vec::from_slice(values);
|
||||||
self.shuffle_mut(m);
|
self.shuffle_mut(m);
|
||||||
return m;
|
return m;
|
||||||
|
@ -18,7 +18,7 @@ enum Result<T, U> {
|
|||||||
*
|
*
|
||||||
* If the result is an error
|
* 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 {
|
match res {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(the_err) => unchecked {
|
Err(the_err) => unchecked {
|
||||||
@ -50,7 +50,7 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
|||||||
*
|
*
|
||||||
* If the result is not an error
|
* 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 {
|
match res {
|
||||||
Err(u) => u,
|
Err(u) => u,
|
||||||
Ok(_) => fail ~"get_err called on ok result"
|
Ok(_) => fail ~"get_err called on ok result"
|
||||||
@ -76,7 +76,7 @@ pure fn is_err<T, U>(res: Result<T, U>) -> bool {
|
|||||||
* `ok` result variants are converted to `either::right` variants, `err`
|
* `ok` result variants are converted to `either::right` variants, `err`
|
||||||
* result variants are converted to `either::left`.
|
* 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 {
|
match res {
|
||||||
Ok(res) => either::Right(res),
|
Ok(res) => either::Right(res),
|
||||||
Err(fail_) => either::Left(fail_)
|
Err(fail_) => either::Left(fail_)
|
||||||
@ -97,7 +97,7 @@ pure fn to_either<T: copy, U: copy>(res: Result<U, T>) -> Either<T, U> {
|
|||||||
* ok(parse_buf(buf))
|
* 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> {
|
-> Result<U, V> {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => op(t),
|
Ok(t) => op(t),
|
||||||
@ -113,7 +113,7 @@ fn chain<T, U: copy, V: copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
|
|||||||
* immediately returned. This function can be used to pass through a
|
* immediately returned. This function can be used to pass through a
|
||||||
* successful result while handling an error.
|
* 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>,
|
res: Result<T, V>,
|
||||||
op: fn(V) -> Result<T, U>)
|
op: fn(V) -> Result<T, U>)
|
||||||
-> Result<T, U> {
|
-> Result<T, U> {
|
||||||
@ -173,7 +173,7 @@ fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
|
|||||||
* parse_buf(buf)
|
* 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> {
|
-> Result<U, E> {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => Ok(op(t)),
|
Ok(t) => Ok(op(t)),
|
||||||
@ -189,7 +189,7 @@ fn map<T, E: copy, U: copy>(res: Result<T, E>, op: fn(T) -> U)
|
|||||||
* is immediately returned. This function can be used to pass through a
|
* is immediately returned. This function can be used to pass through a
|
||||||
* successful result while handling an error.
|
* 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> {
|
-> Result<T, F> {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
@ -217,10 +217,10 @@ impl<T, E> Result<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: copy, E> Result<T, E> {
|
impl<T: Copy, E> Result<T, E> {
|
||||||
fn get() -> T { get(self) }
|
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 {
|
match self {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(e) => Err(op(e))
|
Err(e) => Err(op(e))
|
||||||
@ -228,10 +228,10 @@ impl<T: copy, E> Result<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E: copy> Result<T, E> {
|
impl<T, E: Copy> Result<T, E> {
|
||||||
fn get_err() -> E { get_err(self) }
|
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 {
|
match self {
|
||||||
Ok(t) => Ok(op(t)),
|
Ok(t) => Ok(op(t)),
|
||||||
Err(e) => Err(e)
|
Err(e) => Err(e)
|
||||||
@ -239,12 +239,12 @@ impl<T, E: copy> Result<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: copy, E: copy> Result<T, E> {
|
impl<T: Copy, E: Copy> Result<T, E> {
|
||||||
fn chain<U:copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
|
fn chain<U:Copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||||
chain(self, op)
|
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)
|
chain_err(self, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ impl<T: copy, E: copy> Result<T, E> {
|
|||||||
* assert incd == ~[2u, 3u, 4u];
|
* 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> {
|
ts: &[T], op: fn(T) -> Result<V,U>) -> Result<~[V],U> {
|
||||||
|
|
||||||
let mut vs: ~[V] = ~[];
|
let mut vs: ~[V] = ~[];
|
||||||
@ -280,7 +280,7 @@ fn map_vec<T,U:copy,V:copy>(
|
|||||||
return Ok(vs);
|
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> {
|
o_t: Option<T>, op: fn(T) -> Result<V,U>) -> Result<Option<V>,U> {
|
||||||
|
|
||||||
match o_t {
|
match o_t {
|
||||||
@ -301,7 +301,7 @@ fn map_opt<T,U:copy,V:copy>(
|
|||||||
* used in 'careful' code contexts where it is both appropriate and easy
|
* used in 'careful' code contexts where it is both appropriate and easy
|
||||||
* to accommodate an error like the vectors being of different lengths.
|
* 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> {
|
op: fn(S,T) -> Result<V,U>) -> Result<~[V],U> {
|
||||||
|
|
||||||
assert vec::same_length(ss, ts);
|
assert vec::same_length(ss, ts);
|
||||||
@ -324,7 +324,7 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T],
|
|||||||
* error. This could be implemented using `map2()` but it is more efficient
|
* error. This could be implemented using `map2()` but it is more efficient
|
||||||
* on its own as no result vector is built.
|
* 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> {
|
op: fn(S,T) -> Result<(),U>) -> Result<(),U> {
|
||||||
|
|
||||||
assert vec::same_length(ss, ts);
|
assert vec::same_length(ss, ts);
|
||||||
|
@ -8,7 +8,7 @@ use cmp::Eq;
|
|||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use to_bytes::IterBytes;
|
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
|
// FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy
|
||||||
|
|
||||||
fn insert(&mut self, +k: K, +v: V) -> bool;
|
fn insert(&mut self, +k: K, +v: V) -> bool;
|
||||||
@ -315,7 +315,7 @@ mod linear {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
fn find(&const self, k: &K) -> Option<V> {
|
||||||
match self.bucket_for_key(self.buckets, k) {
|
match self.bucket_for_key(self.buckets, k) {
|
||||||
FoundEntry(idx) => {
|
FoundEntry(idx) => {
|
||||||
@ -342,17 +342,17 @@ mod linear {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
fn each(&self, blk: fn(+K,+V) -> bool) {
|
||||||
self.each_ref(|k,v| blk(copy *k, copy *v));
|
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) {
|
fn each_key(&self, blk: fn(+K) -> bool) {
|
||||||
self.each_key_ref(|k| blk(copy *k));
|
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) {
|
fn each_value(&self, blk: fn(+V) -> bool) {
|
||||||
self.each_value_ref(|v| blk(copy *v));
|
self.each_value_ref(|v| blk(copy *v));
|
||||||
}
|
}
|
||||||
|
@ -380,7 +380,7 @@ impl TaskBuilder {
|
|||||||
spawn_raw(x.opts, x.gen_body(f));
|
spawn_raw(x.opts, x.gen_body(f));
|
||||||
}
|
}
|
||||||
/// Runs a task, while transfering ownership of one argument to the child.
|
/// 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);
|
let arg = ~mut Some(arg);
|
||||||
do self.spawn {
|
do self.spawn {
|
||||||
f(option::swap_unwrap(arg))
|
f(option::swap_unwrap(arg))
|
||||||
@ -398,7 +398,7 @@ impl TaskBuilder {
|
|||||||
* otherwise be required to establish communication from the parent
|
* otherwise be required to establish communication from the parent
|
||||||
* to the child.
|
* 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_po = comm::Port();
|
||||||
let setup_ch = comm::Chan(setup_po);
|
let setup_ch = comm::Chan(setup_po);
|
||||||
do self.spawn {
|
do self.spawn {
|
||||||
@ -413,7 +413,7 @@ impl TaskBuilder {
|
|||||||
/**
|
/**
|
||||||
* Runs a new task, setting up communication in both directions
|
* 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>))
|
(+f: fn~(comm::Port<A>, comm::Chan<B>))
|
||||||
-> (comm::Port<B>, comm::Chan<A>) {
|
-> (comm::Port<B>, comm::Chan<A>) {
|
||||||
let from_child = comm::Port();
|
let from_child = comm::Port();
|
||||||
@ -437,7 +437,7 @@ impl TaskBuilder {
|
|||||||
* # Failure
|
* # Failure
|
||||||
* Fails if a future_result was already set for this task.
|
* 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 po = comm::Port();
|
||||||
let ch = comm::Chan(po);
|
let ch = comm::Chan(po);
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
@ -504,7 +504,7 @@ fn spawn_supervised(+f: fn~()) {
|
|||||||
task().supervised().spawn(f)
|
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
|
* Runs a task, while transfering ownership of one argument to the
|
||||||
* child.
|
* child.
|
||||||
@ -518,7 +518,7 @@ fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
|
|||||||
task().spawn_with(arg, f)
|
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
|
* Runs a new task while providing a channel from the parent to the child
|
||||||
*
|
*
|
||||||
@ -528,7 +528,7 @@ fn spawn_listener<A:send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
|||||||
task().spawn_listener(f)
|
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>))
|
(+f: fn~(comm::Port<A>, comm::Chan<B>))
|
||||||
-> (comm::Port<B>, comm::Chan<A>) {
|
-> (comm::Port<B>, comm::Chan<A>) {
|
||||||
/*!
|
/*!
|
||||||
@ -557,7 +557,7 @@ fn spawn_sched(mode: SchedMode, +f: fn~()) {
|
|||||||
task().sched_mode(mode).spawn(f)
|
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
|
* Execute a function in another task and return either the return value
|
||||||
* of the function or result::err.
|
* of the function or result::err.
|
||||||
@ -1314,10 +1314,10 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||||||
*
|
*
|
||||||
* These two cases aside, the interface is safe.
|
* These two cases aside, the interface is safe.
|
||||||
*/
|
*/
|
||||||
type LocalDataKey<T: owned> = &fn(+@T);
|
type LocalDataKey<T: Owned> = &fn(+@T);
|
||||||
|
|
||||||
trait LocalData { }
|
trait LocalData { }
|
||||||
impl<T: owned> @T: LocalData { }
|
impl<T: Owned> @T: LocalData { }
|
||||||
|
|
||||||
impl LocalData: Eq {
|
impl LocalData: Eq {
|
||||||
pure fn eq(&&other: LocalData) -> bool unsafe {
|
pure fn eq(&&other: LocalData) -> bool unsafe {
|
||||||
@ -1365,7 +1365,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn key_to_key_value<T: owned>(
|
unsafe fn key_to_key_value<T: Owned>(
|
||||||
key: LocalDataKey<T>) -> *libc::c_void {
|
key: LocalDataKey<T>) -> *libc::c_void {
|
||||||
|
|
||||||
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
||||||
@ -1375,7 +1375,7 @@ unsafe fn key_to_key_value<T: owned>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If returning Some(..), returns with @T with the map's reference. Careful!
|
// 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>)
|
map: TaskLocalMap, key: LocalDataKey<T>)
|
||||||
-> Option<(uint, *libc::c_void)> {
|
-> Option<(uint, *libc::c_void)> {
|
||||||
|
|
||||||
@ -1393,7 +1393,7 @@ unsafe fn local_data_lookup<T: owned>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn local_get_helper<T: owned>(
|
unsafe fn local_get_helper<T: Owned>(
|
||||||
task: *rust_task, key: LocalDataKey<T>,
|
task: *rust_task, key: LocalDataKey<T>,
|
||||||
do_pop: bool) -> Option<@T> {
|
do_pop: bool) -> Option<@T> {
|
||||||
|
|
||||||
@ -1414,21 +1414,21 @@ unsafe fn local_get_helper<T: owned>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn local_pop<T: owned>(
|
unsafe fn local_pop<T: Owned>(
|
||||||
task: *rust_task,
|
task: *rust_task,
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get_helper(task, key, true)
|
local_get_helper(task, key, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn local_get<T: owned>(
|
unsafe fn local_get<T: Owned>(
|
||||||
task: *rust_task,
|
task: *rust_task,
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get_helper(task, key, false)
|
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) {
|
task: *rust_task, key: LocalDataKey<T>, +data: @T) {
|
||||||
|
|
||||||
let map = get_task_local_map(task);
|
let map = get_task_local_map(task);
|
||||||
@ -1460,7 +1460,7 @@ unsafe fn local_set<T: owned>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn local_modify<T: owned>(
|
unsafe fn local_modify<T: Owned>(
|
||||||
task: *rust_task, key: LocalDataKey<T>,
|
task: *rust_task, key: LocalDataKey<T>,
|
||||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||||
|
|
||||||
@ -1476,7 +1476,7 @@ unsafe fn local_modify<T: owned>(
|
|||||||
* Remove a task-local data value from the table, returning the
|
* Remove a task-local data value from the table, returning the
|
||||||
* reference that was originally created to insert it.
|
* 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> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_pop(rustrt::rust_get_task(), key)
|
local_pop(rustrt::rust_get_task(), key)
|
||||||
@ -1485,7 +1485,7 @@ unsafe fn local_data_pop<T: owned>(
|
|||||||
* Retrieve a task-local data value. It will also be kept alive in the
|
* Retrieve a task-local data value. It will also be kept alive in the
|
||||||
* table until explicitly removed.
|
* table until explicitly removed.
|
||||||
*/
|
*/
|
||||||
unsafe fn local_data_get<T: owned>(
|
unsafe fn local_data_get<T: Owned>(
|
||||||
key: LocalDataKey<T>) -> Option<@T> {
|
key: LocalDataKey<T>) -> Option<@T> {
|
||||||
|
|
||||||
local_get(rustrt::rust_get_task(), key)
|
local_get(rustrt::rust_get_task(), key)
|
||||||
@ -1494,7 +1494,7 @@ unsafe fn local_data_get<T: owned>(
|
|||||||
* Store a value in task-local data. If this key already has a value,
|
* Store a value in task-local data. If this key already has a value,
|
||||||
* that value is overwritten (and its destructor is run).
|
* 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) {
|
key: LocalDataKey<T>, +data: @T) {
|
||||||
|
|
||||||
local_set(rustrt::rust_get_task(), key, data)
|
local_set(rustrt::rust_get_task(), key, data)
|
||||||
@ -1503,7 +1503,7 @@ unsafe fn local_data_set<T: owned>(
|
|||||||
* Modify a task-local data value. If the function returns 'none', the
|
* Modify a task-local data value. If the function returns 'none', the
|
||||||
* data is removed (and its reference dropped).
|
* data is removed (and its reference dropped).
|
||||||
*/
|
*/
|
||||||
unsafe fn local_data_modify<T: owned>(
|
unsafe fn local_data_modify<T: Owned>(
|
||||||
key: LocalDataKey<T>,
|
key: LocalDataKey<T>,
|
||||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||||
|
|
||||||
|
@ -50,13 +50,13 @@ impl &str: ToStr {
|
|||||||
fn to_str() -> ~str { str::from_slice(self) }
|
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 {
|
fn to_str() -> ~str {
|
||||||
let (a, b) = self;
|
let (a, b) = self;
|
||||||
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
|
~"(" + 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 {
|
fn to_str() -> ~str {
|
||||||
let (a, b, c) = self;
|
let (a, b, c) = self;
|
||||||
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
|
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
|
||||||
|
@ -12,7 +12,7 @@ trait TupleOps<T,U> {
|
|||||||
pure fn swap() -> (U, T);
|
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
|
/// Return the first element of self
|
||||||
pure fn first() -> T {
|
pure fn first() -> T {
|
||||||
@ -39,7 +39,7 @@ trait ExtendedTupleOps<A,B> {
|
|||||||
fn map<C>(f: fn(A, B) -> C) -> ~[C];
|
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)] {
|
fn zip() -> ~[(A, B)] {
|
||||||
let (a, b) = self;
|
let (a, b) = self;
|
||||||
@ -52,7 +52,7 @@ impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
|
impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
|
||||||
|
|
||||||
fn zip() -> ~[(A, B)] {
|
fn zip() -> ~[(A, B)] {
|
||||||
// XXX: Bad copy
|
// XXX: Bad copy
|
||||||
|
@ -137,7 +137,7 @@ fn ArcDestruct<T>(data: *libc::c_void) -> ArcDestruct<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
|
||||||
-> T {
|
-> T {
|
||||||
struct DeathThroes<T> {
|
struct DeathThroes<T> {
|
||||||
mut ptr: Option<~ArcData<T>>,
|
mut ptr: Option<~ArcData<T>>,
|
||||||
@ -207,9 +207,9 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
|||||||
* Data races between tasks can result in crashes and, with sufficient
|
* Data races between tasks can result in crashes and, with sufficient
|
||||||
* cleverness, arbitrary type coercion.
|
* 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) };
|
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = unsafe::transmute(data);
|
let ptr = unsafe::transmute(data);
|
||||||
@ -218,7 +218,7 @@ unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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 {
|
-> &a/mut T {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||||
@ -230,7 +230,7 @@ unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[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 {
|
-> &a/T {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||||
@ -242,7 +242,7 @@ unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
|
unsafe fn clone_shared_mutable_state<T: Send>(rc: &SharedMutableState<T>)
|
||||||
-> SharedMutableState<T> {
|
-> SharedMutableState<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||||
@ -312,20 +312,20 @@ impl LittleLock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* 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 {
|
let data = ExData {
|
||||||
lock: LittleLock(), mut failed: false, mut data: user_data
|
lock: LittleLock(), mut failed: false, mut data: user_data
|
||||||
};
|
};
|
||||||
Exclusive { x: unsafe { shared_mutable_state(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.
|
// Duplicate an exclusive ARC, as std::arc::clone.
|
||||||
fn clone() -> Exclusive<T> {
|
fn clone() -> Exclusive<T> {
|
||||||
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
||||||
@ -353,7 +353,7 @@ impl<T: send> Exclusive<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(#2585) make this a by-move method on the exclusive
|
// 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 Exclusive { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let ExData { data: data, _ } = inner;
|
let ExData { data: data, _ } = inner;
|
||||||
|
@ -17,7 +17,7 @@ pure fn ignore<T>(+_x: T) { }
|
|||||||
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
||||||
/// original value of `*ptr`.
|
/// original value of `*ptr`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn with<T: copy, R>(
|
fn with<T: Copy, R>(
|
||||||
ptr: &mut T,
|
ptr: &mut T,
|
||||||
+new_value: T,
|
+new_value: T,
|
||||||
op: &fn() -> R) -> R
|
op: &fn() -> R) -> R
|
||||||
|
@ -199,7 +199,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
|
|||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value `t`.
|
* 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 = ~[];
|
let mut v = ~[];
|
||||||
unchecked{reserve(v, n_elts)}
|
unchecked{reserve(v, n_elts)}
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
@ -211,7 +211,7 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new unique vector with the same contents as the slice
|
/// 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])
|
from_fn(t.len(), |i| t[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,10 +281,10 @@ pure fn from_mut<T>(+v: ~[mut T]) -> ~[T] {
|
|||||||
// Accessors
|
// Accessors
|
||||||
|
|
||||||
/// Returns the first element of a vector
|
/// 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
|
/// 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));
|
return slice(v, 1u, len(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,18 +292,18 @@ pure fn tail<T: copy>(v: &[const T]) -> ~[T] {
|
|||||||
* Returns a vector containing all but the first `n` \
|
* Returns a vector containing all but the first `n` \
|
||||||
* elements of a slice
|
* 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))
|
slice(v, n, len(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a vector containing all but the last element of a slice
|
/// 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;
|
assert len(v) != 0u;
|
||||||
slice(v, 0u, len(v) - 1u)
|
slice(v, 0u, len(v) - 1u)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the last element of the slice `v`, failing if the slice is empty.
|
/// 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" }
|
if len(v) == 0u { fail ~"last_unsafe: empty vector" }
|
||||||
v[len(v) - 1u]
|
v[len(v) - 1u]
|
||||||
}
|
}
|
||||||
@ -312,13 +312,13 @@ pure fn last<T: copy>(v: &[const T]) -> T {
|
|||||||
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
||||||
* or `none` if the vector is empty.
|
* 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; }
|
if len(v) == 0u { return None; }
|
||||||
Some(v[len(v) - 1u])
|
Some(v[len(v) - 1u])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a copy of the elements from [`start`..`end`) from `v`.
|
/// 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 (start <= end);
|
||||||
assert (end <= len(v));
|
assert (end <= len(v));
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
@ -365,7 +365,7 @@ pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Split the vector `v` by applying each element against the predicate `f`.
|
/// 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);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
|||||||
* Split the vector `v` by applying each element against the predicate `f` up
|
* Split the vector `v` by applying each element against the predicate `f` up
|
||||||
* to `n` times.
|
* 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);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
|||||||
* Reverse split the vector `v` by applying each element against the predicate
|
* Reverse split the vector `v` by applying each element against the predicate
|
||||||
* `f`.
|
* `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);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
|||||||
* Reverse split the vector `v` by applying each element against the predicate
|
* Reverse split the vector `v` by applying each element against the predicate
|
||||||
* `f` up to `n times.
|
* `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);
|
let ln = len(v);
|
||||||
if (ln == 0u) { return ~[] }
|
if (ln == 0u) { return ~[] }
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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());
|
reserve(v, v.len() + rhs.len());
|
||||||
|
|
||||||
for uint::range(0u, rhs.len()) |i| {
|
for uint::range(0u, rhs.len()) |i| {
|
||||||
@ -627,7 +627,7 @@ fn truncate<T>(&v: ~[const T], newlen: uint) {
|
|||||||
|
|
||||||
// Appending
|
// Appending
|
||||||
#[inline(always)]
|
#[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;
|
let mut v <- lhs;
|
||||||
unchecked {
|
unchecked {
|
||||||
push_all(v, rhs);
|
push_all(v, rhs);
|
||||||
@ -643,7 +643,7 @@ pure fn append_one<T>(+lhs: ~[T], +x: T) -> ~[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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 v = ~[mut];
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while i < lhs.len() {
|
while i < lhs.len() {
|
||||||
@ -671,7 +671,7 @@ pure fn append_mut<T: copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
|
|||||||
* * n - The number of elements to add
|
* * n - The number of elements to add
|
||||||
* * initval - The value for the new elements
|
* * 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);
|
reserve_at_least(v, len(v) + n);
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ fn grow_fn<T>(&v: ~[const T], n: uint, op: iter::InitOp<T>) {
|
|||||||
* of the vector, expands the vector by replicating `initval` to fill the
|
* of the vector, expands the vector by replicating `initval` to fill the
|
||||||
* intervening space.
|
* 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); }
|
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
|
||||||
v[index] = val;
|
v[index] = val;
|
||||||
}
|
}
|
||||||
@ -747,7 +747,7 @@ pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a function to each pair of elements and return the results
|
/// 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] {
|
f: fn(T, U) -> V) -> ~[V] {
|
||||||
let v0_len = len(v0);
|
let v0_len = len(v0);
|
||||||
if v0_len != len(v1) { fail; }
|
if v0_len != len(v1) { fail; }
|
||||||
@ -766,7 +766,7 @@ pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
|
|||||||
* If function `f` returns `none` then that element is excluded from
|
* If function `f` returns `none` then that element is excluded from
|
||||||
* the resulting vector.
|
* 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] {
|
-> ~[U] {
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
for each(v) |elem| {
|
for each(v) |elem| {
|
||||||
@ -785,7 +785,7 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> Option<U>)
|
|||||||
* Apply function `f` to each element of `v` and return a vector containing
|
* Apply function `f` to each element of `v` and return a vector containing
|
||||||
* only those elements for which `f` returned true.
|
* 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 = ~[];
|
let mut result = ~[];
|
||||||
for each(v) |elem| {
|
for each(v) |elem| {
|
||||||
if f(elem) { unsafe { push(result, elem); } }
|
if f(elem) { unsafe { push(result, elem); } }
|
||||||
@ -798,14 +798,14 @@ pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
|
|||||||
*
|
*
|
||||||
* Flattens a vector of vectors of T into a single vector of T.
|
* 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 = ~[];
|
let mut r = ~[];
|
||||||
for each(v) |inner| { unsafe { push_all(r, inner); } }
|
for each(v) |inner| { unsafe { push_all(r, inner); } }
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Concatenate a vector of vectors, placing a given separator between each
|
/// 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 r: ~[T] = ~[];
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for each(v) |inner| {
|
for each(v) |inner| {
|
||||||
@ -816,7 +816,7 @@ pure fn connect<T: copy>(v: &[~[T]], sep: T) -> ~[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reduce a vector from left to right
|
/// 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;
|
let mut accum = z;
|
||||||
do iter(v) |elt| {
|
do iter(v) |elt| {
|
||||||
accum = p(accum, elt);
|
accum = p(accum, elt);
|
||||||
@ -825,7 +825,7 @@ pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reduce a vector from right to left
|
/// 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;
|
let mut accum = z;
|
||||||
do riter(v) |elt| {
|
do riter(v) |elt| {
|
||||||
accum = p(elt, accum);
|
accum = p(elt, accum);
|
||||||
@ -914,7 +914,7 @@ pure fn count<T: Eq>(v: &[T], x: T) -> uint {
|
|||||||
* When function `f` returns true then an option containing the element
|
* When function `f` returns true then an option containing the element
|
||||||
* is returned. If `f` matches no elements then none is returned.
|
* 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)
|
find_between(v, 0u, len(v), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,7 +925,7 @@ pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
|||||||
* [`start`, `end`). When function `f` returns true then an option containing
|
* [`start`, `end`). When function `f` returns true then an option containing
|
||||||
* the element is returned. If `f` matches no elements then none is returned.
|
* 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> {
|
f: fn(T) -> bool) -> Option<T> {
|
||||||
option::map(position_between(v, start, end, f), |i| v[i])
|
option::map(position_between(v, start, end, f), |i| v[i])
|
||||||
}
|
}
|
||||||
@ -937,7 +937,7 @@ pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
|
|||||||
* `f` returns true then an option containing the element is returned. If `f`
|
* `f` returns true then an option containing the element is returned. If `f`
|
||||||
* matches no elements then none is returned.
|
* 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)
|
rfind_between(v, 0u, len(v), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -948,7 +948,7 @@ pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
|||||||
* [`start`, `end`). When function `f` returns true then an option containing
|
* [`start`, `end`). When function `f` returns true then an option containing
|
||||||
* the element is returned. If `f` matches no elements then none is returned.
|
* 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> {
|
f: fn(T) -> bool) -> Option<T> {
|
||||||
option::map(rposition_between(v, start, end, f), |i| v[i])
|
option::map(rposition_between(v, start, end, f), |i| v[i])
|
||||||
}
|
}
|
||||||
@ -1028,7 +1028,7 @@ pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
|
|||||||
/**
|
/**
|
||||||
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
|
* 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 = ~[];
|
let mut as = ~[], bs = ~[];
|
||||||
for each(v) |p| {
|
for each(v) |p| {
|
||||||
let (a, b) = p;
|
let (a, b) = p;
|
||||||
@ -1063,7 +1063,7 @@ pure fn unzip<T,U>(+v: ~[(T, U)]) -> (~[T], ~[U]) {
|
|||||||
/**
|
/**
|
||||||
* Convert two vectors to a vector of pairs, by reference. As zip().
|
* 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)] {
|
-> ~[(T, U)] {
|
||||||
let mut zipped = ~[];
|
let mut zipped = ~[];
|
||||||
let sz = len(v);
|
let sz = len(v);
|
||||||
@ -1113,7 +1113,7 @@ fn reverse<T>(v: ~[mut T]) {
|
|||||||
|
|
||||||
|
|
||||||
/// Returns a vector with the order of elements reversed
|
/// 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 rs: ~[T] = ~[];
|
||||||
let mut i = len::<T>(v);
|
let mut i = len::<T>(v);
|
||||||
if i == 0u { return rs; } else { i -= 1u; }
|
if i == 0u { return rs; } else { i -= 1u; }
|
||||||
@ -1317,7 +1317,7 @@ pure fn riteri<T>(v: &[T], f: fn(uint, T)) {
|
|||||||
* The total number of permutations produced is `len(v)!`. If `v` contains
|
* The total number of permutations produced is `len(v)!`. If `v` contains
|
||||||
* repeated elements, then some permutations are repeated.
|
* 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);
|
let ln = len(v);
|
||||||
if ln == 0u {
|
if ln == 0u {
|
||||||
put(~[]);
|
put(~[]);
|
||||||
@ -1337,7 +1337,7 @@ pure fn permute<T: copy>(v: &[const T], put: fn(~[T])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
||||||
let mut ww = ~[];
|
let mut ww = ~[];
|
||||||
assert 1u <= nn;
|
assert 1u <= nn;
|
||||||
vec::iteri (xx, |ii, _x| {
|
vec::iteri (xx, |ii, _x| {
|
||||||
@ -1480,14 +1480,14 @@ impl<T: Ord> @[T]: Ord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(notest)]
|
#[cfg(notest)]
|
||||||
impl<T: copy> ~[T]: Add<&[const T],~[T]> {
|
impl<T: Copy> ~[T]: Add<&[const T],~[T]> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn add(rhs: &[const T]) -> ~[T] {
|
pure fn add(rhs: &[const T]) -> ~[T] {
|
||||||
append(copy self, rhs)
|
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)]
|
#[inline(always)]
|
||||||
pure fn add(rhs: &[const T]) -> ~[mut T] {
|
pure fn add(rhs: &[const T]) -> ~[mut T] {
|
||||||
append_mut(self, rhs)
|
append_mut(self, rhs)
|
||||||
@ -1522,7 +1522,7 @@ trait CopyableVector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// 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
|
/// Returns the first element of a vector
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn head() -> T { head(self) }
|
pure fn head() -> T { head(self) }
|
||||||
@ -1541,7 +1541,7 @@ impl<T: copy> &[const T]: CopyableVector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait ImmutableVector<T> {
|
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 iter(f: fn(T));
|
||||||
pure fn iteri(f: fn(uint, T));
|
pure fn iteri(f: fn(uint, T));
|
||||||
pure fn riter(f: fn(T));
|
pure fn riter(f: fn(T));
|
||||||
@ -1551,7 +1551,7 @@ trait ImmutableVector<T> {
|
|||||||
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
|
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
|
||||||
pure fn alli(f: fn(uint, T) -> bool) -> bool;
|
pure fn alli(f: fn(uint, T) -> bool) -> bool;
|
||||||
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U];
|
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> {
|
trait ImmutableEqVector<T: Eq> {
|
||||||
@ -1565,7 +1565,7 @@ trait ImmutableEqVector<T: Eq> {
|
|||||||
impl<T> &[T]: ImmutableVector<T> {
|
impl<T> &[T]: ImmutableVector<T> {
|
||||||
/// Reduce a vector from right to left
|
/// Reduce a vector from right to left
|
||||||
#[inline]
|
#[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
|
* Iterates over a vector
|
||||||
*
|
*
|
||||||
@ -1641,7 +1641,7 @@ impl<T> &[T]: ImmutableVector<T> {
|
|||||||
* the resulting vector.
|
* the resulting vector.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[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)
|
filter_map(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1679,7 +1679,7 @@ trait ImmutableCopyableVector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// 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
|
* Construct a new vector from the elements of a vector for which some
|
||||||
* predicate holds.
|
* predicate holds.
|
||||||
@ -1785,7 +1785,7 @@ mod unsafe {
|
|||||||
* Unchecked vector indexing.
|
* Unchecked vector indexing.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[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))
|
as_buf(v, |p, _len| *ptr::offset(p, i))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1938,7 +1938,7 @@ impl<A: Eq> &[A]: iter::EqIter<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: copy> &[A]: iter::CopyableIter<A> {
|
impl<A: Copy> &[A]: iter::CopyableIter<A> {
|
||||||
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
||||||
iter::filter_to_vec(self, pred)
|
iter::filter_to_vec(self, pred)
|
||||||
}
|
}
|
||||||
@ -1955,7 +1955,7 @@ impl<A: copy> &[A]: iter::CopyableIter<A> {
|
|||||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
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 min() -> A { iter::min(self) }
|
||||||
pure fn max() -> A { iter::max(self) }
|
pure fn max() -> A { iter::max(self) }
|
||||||
}
|
}
|
||||||
|
@ -69,10 +69,10 @@ impl &Condvar {
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/// An atomically reference counted wrapper for shared immutable state.
|
/// 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.
|
/// 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) } }
|
ARC { x: unsafe { shared_mutable_state(data) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ fn ARC<T: const send>(+data: T) -> ARC<T> {
|
|||||||
* Access the underlying data in an atomically reference counted
|
* Access the underlying data in an atomically reference counted
|
||||||
* wrapper.
|
* 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) }
|
unsafe { get_shared_immutable_state(&rc.x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ fn get<T: const send>(rc: &a/ARC<T>) -> &a/T {
|
|||||||
* object. However, one of the `arc` objects can be sent to another task,
|
* object. However, one of the `arc` objects can be sent to another task,
|
||||||
* allowing them to share the underlying data.
|
* 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) } }
|
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ fn clone<T: const send>(rc: &ARC<T>) -> ARC<T> {
|
|||||||
* unwrap from a task that holds another reference to the same ARC; it is
|
* unwrap from a task that holds another reference to the same ARC; it is
|
||||||
* guaranteed to deadlock.
|
* 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;
|
let ARC { x: x } = rc;
|
||||||
unsafe { unwrap_shared_mutable_state(x) }
|
unsafe { unwrap_shared_mutable_state(x) }
|
||||||
}
|
}
|
||||||
@ -114,19 +114,19 @@ fn unwrap<T: const send>(+rc: ARC<T>) -> T {
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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.
|
/// 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.
|
/// 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)
|
mutex_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a mutex-protected ARC with the supplied data and a specified number
|
* Create a mutex-protected ARC with the supplied data and a specified number
|
||||||
* of condvars (as sync::mutex_with_condvars).
|
* 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> {
|
num_condvars: uint) -> MutexARC<T> {
|
||||||
let data =
|
let data =
|
||||||
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
MutexARCInner { lock: mutex_with_condvars(num_condvars),
|
||||||
@ -134,7 +134,7 @@ fn mutex_arc_with_condvars<T: send>(+user_data: T,
|
|||||||
MutexARC { x: unsafe { shared_mutable_state(data) } }
|
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.
|
/// Duplicate a mutex-protected ARC, as arc::clone.
|
||||||
fn clone() -> MutexARC<T> {
|
fn clone() -> MutexARC<T> {
|
||||||
// NB: Cloning the underlying mutex is not necessary. Its reference
|
// NB: Cloning the underlying mutex is not necessary. Its reference
|
||||||
@ -197,7 +197,7 @@ impl<T: send> &MutexARC<T> {
|
|||||||
* Will additionally fail if another task has failed while accessing the arc.
|
* Will additionally fail if another task has failed while accessing the arc.
|
||||||
*/
|
*/
|
||||||
// FIXME(#2585) make this a by-move method on 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 MutexARC { x: x } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
||||||
@ -240,27 +240,27 @@ fn PoisonOnFail(failed: &r/mut bool) -> PoisonOnFail/&r {
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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
|
* 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.
|
* mutably or immutably, and immutably-accessing tasks may run concurrently.
|
||||||
*
|
*
|
||||||
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
|
* 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>>,
|
x: SharedMutableState<RWARCInner<T>>,
|
||||||
mut cant_nest: ()
|
mut cant_nest: ()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a reader/writer ARC with the supplied data.
|
/// 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)
|
rw_arc_with_condvars(user_data, 1)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a reader/writer ARC with the supplied data and a specified number
|
* Create a reader/writer ARC with the supplied data and a specified number
|
||||||
* of condvars (as sync::rwlock_with_condvars).
|
* 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> {
|
num_condvars: uint) -> RWARC<T> {
|
||||||
let data =
|
let data =
|
||||||
RWARCInner { lock: rwlock_with_condvars(num_condvars),
|
RWARCInner { lock: rwlock_with_condvars(num_condvars),
|
||||||
@ -268,7 +268,7 @@ fn rw_arc_with_condvars<T: const send>(+user_data: T,
|
|||||||
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
|
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.
|
/// Duplicate a rwlock-protected ARC, as arc::clone.
|
||||||
fn clone() -> RWARC<T> {
|
fn clone() -> RWARC<T> {
|
||||||
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
|
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
|
||||||
@ -375,7 +375,7 @@ impl<T: const send> &RWARC<T> {
|
|||||||
* in write mode.
|
* in write mode.
|
||||||
*/
|
*/
|
||||||
// FIXME(#2585) make this a by-move method on the arc
|
// 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 RWARC { x: x, _ } = arc;
|
||||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||||
let RWARCInner { failed: failed, data: data, _ } = inner;
|
let RWARCInner { failed: failed, data: data, _ } = inner;
|
||||||
@ -389,19 +389,19 @@ fn unwrap_rw_arc<T: const send>(+arc: RWARC<T>) -> T {
|
|||||||
// lock it. This wraps the unsafety, with the justification that the 'lock'
|
// lock it. This wraps the unsafety, with the justification that the 'lock'
|
||||||
// field is never overwritten; only 'failed' and 'data'.
|
// field is never overwritten; only 'failed' and 'data'.
|
||||||
#[doc(hidden)]
|
#[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) }
|
unsafe { unsafe::transmute_immut(&mut state.lock) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
|
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
|
||||||
|
|
||||||
/// The "write permission" token used for RWARC.write_downgrade().
|
/// The "write permission" token used for RWARC.write_downgrade().
|
||||||
enum RWWriteMode<T: const send> =
|
enum RWWriteMode<T: Const Send> =
|
||||||
(&mut T, sync::RWlockWriteMode, PoisonOnFail);
|
(&mut T, sync::RWlockWriteMode, PoisonOnFail);
|
||||||
/// The "read permission" token used for RWARC.write_downgrade().
|
/// 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.
|
/// Access the pre-downgrade RWARC in write mode.
|
||||||
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
||||||
match *self {
|
match *self {
|
||||||
@ -427,7 +427,7 @@ impl<T: const send> &RWWriteMode<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: const send> &RWReadMode<T> {
|
impl<T: Const Send> &RWReadMode<T> {
|
||||||
/// Access the post-downgrade rwlock in read mode.
|
/// Access the post-downgrade rwlock in read mode.
|
||||||
fn read<U>(blk: fn(x: &T) -> U) -> U {
|
fn read<U>(blk: fn(x: &T) -> U) -> U {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -107,7 +107,7 @@ unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
|
|||||||
*
|
*
|
||||||
* Fails if `ofs` is greater or equal to the length of the vector
|
* 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);
|
assert ofs < len(t);
|
||||||
return unsafe { *ptr::mut_offset((*t).base, ofs) };
|
return unsafe { *ptr::mut_offset((*t).base, ofs) };
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ fn get<T: copy>(t: CVec<T>, ofs: uint) -> T {
|
|||||||
*
|
*
|
||||||
* Fails if `ofs` is greater or equal to the length of the vector
|
* 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);
|
assert ofs < len(t);
|
||||||
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
|
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use pipes::{Channel, Recv, Chan, Port, Selectable};
|
|||||||
export DuplexStream;
|
export DuplexStream;
|
||||||
|
|
||||||
/// An extension of `pipes::stream` that allows both sending and receiving.
|
/// 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 chan: Chan<T>,
|
||||||
priv port: Port <U>,
|
priv port: Port <U>,
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ struct DuplexStream<T: send, U: send> : Channel<T>, Recv<U>, Selectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a bidirectional stream.
|
/// Creates a bidirectional stream.
|
||||||
fn DuplexStream<T: send, U: send>()
|
fn DuplexStream<T: Send, U: Send>()
|
||||||
-> (DuplexStream<T, U>, DuplexStream<U, T>)
|
-> (DuplexStream<T, U>, DuplexStream<U, T>)
|
||||||
{
|
{
|
||||||
let (c2, p1) = pipes::stream();
|
let (c2, p1) = pipes::stream();
|
||||||
|
@ -16,7 +16,7 @@ trait Deque<T> {
|
|||||||
|
|
||||||
// FIXME (#2343) eventually, a proper datatype plus an exported impl would
|
// FIXME (#2343) eventually, a proper datatype plus an exported impl would
|
||||||
// be preferrable.
|
// be preferrable.
|
||||||
fn create<T: copy>() -> Deque<T> {
|
fn create<T: Copy>() -> Deque<T> {
|
||||||
type Cell<T> = Option<T>;
|
type Cell<T> = Option<T>;
|
||||||
|
|
||||||
let initial_capacity: uint = 32u; // 2^5
|
let initial_capacity: uint = 32u; // 2^5
|
||||||
@ -24,7 +24,7 @@ fn create<T: copy>() -> Deque<T> {
|
|||||||
* Grow is only called on full elts, so nelts is also len(elts), unlike
|
* Grow is only called on full elts, so nelts is also len(elts), unlike
|
||||||
* elsewhere.
|
* 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>] {
|
~[mut Cell<T>] {
|
||||||
assert (nelts == vec::len(elts));
|
assert (nelts == vec::len(elts));
|
||||||
let mut rv = ~[mut];
|
let mut rv = ~[mut];
|
||||||
@ -40,7 +40,7 @@ fn create<T: copy>() -> Deque<T> {
|
|||||||
|
|
||||||
return rv;
|
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 }
|
match elts.get_elt(i) { Some(t) => t, _ => fail }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ fn create<T: copy>() -> Deque<T> {
|
|||||||
mut hi: uint,
|
mut hi: uint,
|
||||||
elts: DVec<Cell<T>>};
|
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 size() -> uint { return self.nelts; }
|
||||||
fn add_front(t: T) {
|
fn add_front(t: T) {
|
||||||
let oldlo: uint = self.lo;
|
let oldlo: uint = self.lo;
|
||||||
@ -193,7 +193,7 @@ mod tests {
|
|||||||
|
|
||||||
type EqFn<T> = fn@(T, T) -> bool;
|
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) {
|
e: EqFn<T>, a: T, b: T, c: T, d: T) {
|
||||||
|
|
||||||
let deq: deque::Deque<T> = deque::create::<T>();
|
let deq: deque::Deque<T> = deque::create::<T>();
|
||||||
|
@ -33,7 +33,7 @@ enum TreeNode<K, V> {
|
|||||||
fn init<K, V>() -> Treemap<K, V> { @Empty }
|
fn init<K, V>() -> Treemap<K, V> { @Empty }
|
||||||
|
|
||||||
/// Insert a value into the map
|
/// 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> {
|
-> Treemap<K, V> {
|
||||||
@match m {
|
@match m {
|
||||||
@Empty => Node(@k, @v, @Empty, @Empty),
|
@Empty => Node(@k, @v, @Empty, @Empty),
|
||||||
@ -48,7 +48,7 @@ fn insert<K: copy Eq Ord, V: copy>(m: Treemap<K, V>, +k: K, +v: V)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find a value based on the key
|
/// 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 {
|
match *m {
|
||||||
Empty => None,
|
Empty => None,
|
||||||
Node(@kk, @v, left, right) => {
|
Node(@kk, @v, left, right) => {
|
||||||
@ -60,7 +60,7 @@ fn find<K: Eq Ord, V: copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all pairs in the map in order.
|
/// 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 {
|
match *m {
|
||||||
Empty => (),
|
Empty => (),
|
||||||
/*
|
/*
|
||||||
|
@ -720,7 +720,7 @@ impl <A: ToJson> ~[A]: ToJson {
|
|||||||
fn to_json() -> Json { List(@self.map(|elt| elt.to_json())) }
|
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 {
|
fn to_json() -> Json {
|
||||||
let d = map::str_hash();
|
let d = map::str_hash();
|
||||||
for self.each() |key, value| {
|
for self.each() |key, value| {
|
||||||
|
@ -13,7 +13,7 @@ enum List<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cregate a list from a vector
|
/// 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))
|
vec::foldr(v, @Nil::<T>, |h, t| @Cons(h, t))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ fn from_vec<T: copy>(v: &[T]) -> @List<T> {
|
|||||||
* * z - The initial value
|
* * z - The initial value
|
||||||
* * f - The function to apply
|
* * 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;
|
let mut accum: T = z;
|
||||||
do iter(ls) |elt| { accum = f(&accum, &elt);}
|
do iter(ls) |elt| { accum = f(&accum, &elt);}
|
||||||
accum
|
accum
|
||||||
@ -43,7 +43,7 @@ fn foldl<T: copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
|
|||||||
* When function `f` returns true then an option containing the element
|
* When function `f` returns true then an option containing the element
|
||||||
* is returned. If `f` matches no elements then none is returned.
|
* 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;
|
let mut ls = ls;
|
||||||
loop {
|
loop {
|
||||||
ls = match *ls {
|
ls = match *ls {
|
||||||
@ -57,7 +57,7 @@ fn find<T: copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a list contains an element with the given value
|
/// 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| {
|
for each(ls) |e| {
|
||||||
if e == elt { return true; }
|
if e == elt { return true; }
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ fn has<T: copy Eq>(ls: @List<T>, +elt: T) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the list is empty
|
/// 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 {
|
match *ls {
|
||||||
Nil => true,
|
Nil => true,
|
||||||
_ => false
|
_ => false
|
||||||
@ -73,7 +73,7 @@ pure fn is_empty<T: copy>(ls: @List<T>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the list is not empty
|
/// 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);
|
return !is_empty(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ fn len<T>(ls: @List<T>) -> uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all but the first element of a list
|
/// 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 {
|
match *ls {
|
||||||
Cons(_, tl) => return tl,
|
Cons(_, tl) => return tl,
|
||||||
Nil => fail ~"list empty"
|
Nil => fail ~"list empty"
|
||||||
@ -93,7 +93,7 @@ pure fn tail<T: copy>(ls: @List<T>) -> @List<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the first element of a list
|
/// 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 {
|
match *ls {
|
||||||
Cons(hd, _) => hd,
|
Cons(hd, _) => hd,
|
||||||
// makes me sad
|
// makes me sad
|
||||||
@ -102,7 +102,7 @@ pure fn head<T: copy>(ls: @List<T>) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Appends one list to another
|
/// 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 {
|
match *l {
|
||||||
Nil => return m,
|
Nil => return m,
|
||||||
Cons(x, xs) => {
|
Cons(x, xs) => {
|
||||||
@ -115,7 +115,7 @@ pure fn append<T: copy>(l: @List<T>, m: @List<T>) -> @List<T> {
|
|||||||
/*
|
/*
|
||||||
/// Push one element into the front of a list, returning a new list
|
/// Push one element into the front of a list, returning a new list
|
||||||
/// THIS VERSION DOESN'T ACTUALLY WORK
|
/// 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)
|
ll = &mut @cons(vv, *ll)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,7 @@ type set<K:Eq IterBytes Hash> = hashmap<K, ()>;
|
|||||||
|
|
||||||
type hashmap<K:Eq IterBytes Hash, V> = chained::t<K, V>;
|
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
|
/// Return the number of elements in the map
|
||||||
pure fn size() -> uint;
|
pure fn size() -> uint;
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ mod chained {
|
|||||||
found_after(@entry<K,V>, @entry<K,V>)
|
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,
|
pure fn search_rem(k: &K, h: uint, idx: uint,
|
||||||
e_root: @entry<K,V>) -> search_result<K,V> {
|
e_root: @entry<K,V>) -> search_result<K,V> {
|
||||||
let mut e0 = e_root;
|
let mut e0 = e_root;
|
||||||
@ -207,7 +207,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 }
|
pure fn size() -> uint { self.count }
|
||||||
|
|
||||||
fn contains_key(+k: K) -> bool {
|
fn contains_key(+k: K) -> bool {
|
||||||
@ -330,7 +330,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
fn to_writer(wr: io::Writer) {
|
||||||
if self.count == 0u {
|
if self.count == 0u {
|
||||||
wr.write_str(~"{}");
|
wr.write_str(~"{}");
|
||||||
@ -356,7 +356,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
pure fn index(&&k: K) -> V {
|
||||||
unchecked {
|
unchecked {
|
||||||
self.get(k)
|
self.get(k)
|
||||||
@ -368,7 +368,7 @@ mod chained {
|
|||||||
vec::to_mut(vec::from_elem(nchains, None))
|
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,
|
let slf: t<K, V> = @hashmap_ {count: 0u,
|
||||||
chains: chains(initial_capacity)};
|
chains: chains(initial_capacity)};
|
||||||
slf
|
slf
|
||||||
@ -380,48 +380,48 @@ Function: hashmap
|
|||||||
|
|
||||||
Construct a hashmap.
|
Construct a hashmap.
|
||||||
*/
|
*/
|
||||||
fn hashmap<K:Eq IterBytes Hash const, V: copy>()
|
fn hashmap<K:Eq IterBytes Hash Const, V: Copy>()
|
||||||
-> hashmap<K, V> {
|
-> hashmap<K, V> {
|
||||||
chained::mk()
|
chained::mk()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for string-slice keys
|
/// 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();
|
return hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for string keys
|
/// Construct a hashmap for string keys
|
||||||
fn str_hash<V: copy>() -> hashmap<~str, V> {
|
fn str_hash<V: Copy>() -> hashmap<~str, V> {
|
||||||
return hashmap();
|
return hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for boxed string keys
|
/// 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()
|
hashmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for byte string keys
|
/// 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();
|
return hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for int keys
|
/// Construct a hashmap for int keys
|
||||||
fn int_hash<V: copy>() -> hashmap<int, V> {
|
fn int_hash<V: Copy>() -> hashmap<int, V> {
|
||||||
return hashmap();
|
return hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap for uint keys
|
/// Construct a hashmap for uint keys
|
||||||
fn uint_hash<V: copy>() -> hashmap<uint, V> {
|
fn uint_hash<V: Copy>() -> hashmap<uint, V> {
|
||||||
return hashmap();
|
return hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function for adding keys to a hashmap with nil type keys
|
/// 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, ())
|
set.insert(key, ())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a set into a vector.
|
/// 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 = ~[];
|
let mut v = ~[];
|
||||||
vec::reserve(v, s.size());
|
vec::reserve(v, s.size());
|
||||||
do s.each_key() |k| {
|
do s.each_key() |k| {
|
||||||
@ -432,7 +432,7 @@ fn vec_from_set<T:Eq IterBytes Hash copy>(s: set<T>) -> ~[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector
|
/// 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> {
|
items: &[(K, V)]) -> hashmap<K, V> {
|
||||||
let map = hashmap();
|
let map = hashmap();
|
||||||
do vec::iter(items) |item| {
|
do vec::iter(items) |item| {
|
||||||
@ -443,27 +443,27 @@ fn hash_from_vec<K: Eq IterBytes Hash const copy, V: copy>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector with string keys
|
/// 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)
|
hash_from_vec(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector with byte keys
|
/// 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)
|
hash_from_vec(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector with int keys
|
/// 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)
|
hash_from_vec(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a hashmap from a vector with uint keys
|
/// 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)
|
hash_from_vec(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX Transitional
|
// 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> {
|
map<K, V> {
|
||||||
pure fn size() -> uint {
|
pure fn size() -> uint {
|
||||||
unchecked {
|
unchecked {
|
||||||
|
@ -18,7 +18,7 @@ const min_granularity : uint = 1024u;
|
|||||||
* This is used to build most of the other parallel vector functions,
|
* This is used to build most of the other parallel vector functions,
|
||||||
* like map or alli.
|
* like map or alli.
|
||||||
*/
|
*/
|
||||||
fn map_slices<A: copy send, B: copy send>(
|
fn map_slices<A: Copy Send, B: Copy Send>(
|
||||||
xs: &[A],
|
xs: &[A],
|
||||||
f: fn() -> fn~(uint, v: &[A]) -> B)
|
f: fn() -> fn~(uint, v: &[A]) -> B)
|
||||||
-> ~[B] {
|
-> ~[B] {
|
||||||
@ -73,7 +73,7 @@ fn map_slices<A: copy send, B: copy send>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A parallel version of map.
|
/// 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, || {
|
vec::concat(map_slices(xs, || {
|
||||||
fn~(_base: uint, slice : &[A], copy f) -> ~[B] {
|
fn~(_base: uint, slice : &[A], copy f) -> ~[B] {
|
||||||
vec::map(slice, |x| f(x))
|
vec::map(slice, |x| f(x))
|
||||||
@ -82,7 +82,7 @@ fn map<A: copy send, B: copy send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A parallel version of mapi.
|
/// 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] {
|
f: fn~(uint, A) -> B) -> ~[B] {
|
||||||
let slices = map_slices(xs, || {
|
let slices = map_slices(xs, || {
|
||||||
fn~(base: uint, slice : &[A], copy f) -> ~[B] {
|
fn~(base: uint, slice : &[A], copy f) -> ~[B] {
|
||||||
@ -103,7 +103,7 @@ fn mapi<A: copy send, B: copy send>(xs: ~[A],
|
|||||||
* In this case, f is a function that creates functions to run over the
|
* 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.
|
* 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] {
|
xs: &[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] {
|
||||||
let slices = map_slices(xs, || {
|
let slices = map_slices(xs, || {
|
||||||
let f = f();
|
let f = f();
|
||||||
@ -120,7 +120,7 @@ fn mapi_factory<A: copy send, B: copy send>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the function holds for all elements in the vector.
|
/// 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, || {
|
do vec::all(map_slices(xs, || {
|
||||||
fn~(base: uint, slice : &[A], copy f) -> bool {
|
fn~(base: uint, slice : &[A], copy f) -> bool {
|
||||||
vec::alli(slice, |i, x| {
|
vec::alli(slice, |i, x| {
|
||||||
@ -131,7 +131,7 @@ fn alli<A: copy send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the function holds for any elements in the vector.
|
/// 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, || {
|
do vec::any(map_slices(xs, || {
|
||||||
fn~(_base : uint, slice: &[A], copy f) -> bool {
|
fn~(_base : uint, slice: &[A], copy f) -> bool {
|
||||||
vec::any(slice, |x| f(x))
|
vec::any(slice, |x| f(x))
|
||||||
|
@ -93,7 +93,7 @@ fn emit_from_vec<S: serializer, T>(s: S, v: ~[T], f: fn(T)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 d.read_vec |len| {
|
||||||
do vec::from_fn(len) |i| {
|
do vec::from_fn(len) |i| {
|
||||||
d.read_vec_elt(i, || f())
|
d.read_vec_elt(i, || f())
|
||||||
@ -112,11 +112,11 @@ impl<S: serializer> S: serializer_helpers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait deserializer_helpers {
|
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 {
|
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)
|
read_to_vec(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ fn serialize_Option<S: serializer,T>(s: S, v: Option<T>, st: fn(T)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
-> Option<T> {
|
||||||
do d.read_enum(~"option") {
|
do d.read_enum(~"option") {
|
||||||
do d.read_enum_variant |i| {
|
do d.read_enum_variant |i| {
|
||||||
|
@ -12,14 +12,14 @@ use map::map;
|
|||||||
|
|
||||||
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
|
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
|
||||||
// requires this to be.
|
// 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>)
|
SmallIntMap_(@SmallIntMap_<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a smallintmap
|
/// Create a smallintmap
|
||||||
fn mk<T: copy>() -> SmallIntMap<T> {
|
fn mk<T: Copy>() -> SmallIntMap<T> {
|
||||||
let v = DVec();
|
let v = DVec();
|
||||||
return SmallIntMap_(@{v: v});
|
return SmallIntMap_(@{v: v});
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ fn mk<T: copy>() -> SmallIntMap<T> {
|
|||||||
* the specified key then the original value is replaced.
|
* the specified key then the original value is replaced.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[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));
|
//io::println(fmt!("%?", key));
|
||||||
self.v.grow_set_elt(key, None, Some(val));
|
self.v.grow_set_elt(key, None, Some(val));
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ fn insert<T: copy>(self: SmallIntMap<T>, key: uint, +val: T) {
|
|||||||
* Get the value for the specified key. If the key does not exist
|
* Get the value for the specified key. If the key does not exist
|
||||||
* in the map then returns none
|
* 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); }
|
if key < self.v.len() { return self.v.get_elt(key); }
|
||||||
return None::<T>;
|
return None::<T>;
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ pure fn find<T: copy>(self: SmallIntMap<T>, key: uint) -> Option<T> {
|
|||||||
*
|
*
|
||||||
* If the key does not exist in the map
|
* 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) {
|
match find(self, key) {
|
||||||
None => {
|
None => {
|
||||||
error!("smallintmap::get(): key not present");
|
error!("smallintmap::get(): key not present");
|
||||||
@ -61,12 +61,12 @@ pure fn get<T: copy>(self: SmallIntMap<T>, key: uint) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the map contains a value for the specified key
|
/// 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));
|
return !option::is_none(find(self, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implements the map::map interface for smallintmap
|
/// 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 {
|
pure fn size() -> uint {
|
||||||
let mut sz = 0u;
|
let mut sz = 0u;
|
||||||
for self.v.each |item| {
|
for self.v.each |item| {
|
||||||
@ -137,7 +137,7 @@ impl<V: copy> SmallIntMap<V>: map::map<uint, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: copy> SmallIntMap<V>: ops::Index<uint, V> {
|
impl<V: Copy> SmallIntMap<V>: ops::Index<uint, V> {
|
||||||
pure fn index(&&key: uint) -> V {
|
pure fn index(&&key: uint) -> V {
|
||||||
unchecked {
|
unchecked {
|
||||||
get(self, key)
|
get(self, key)
|
||||||
@ -146,6 +146,6 @@ impl<V: copy> SmallIntMap<V>: ops::Index<uint, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cast the given smallintmap to a map::map
|
/// 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>
|
s as map::map::<uint, V>
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@ type Le<T> = pure fn(v1: &T, v2: &T) -> bool;
|
|||||||
* Has worst case O(n log n) performance, best case O(n), but
|
* Has worst case O(n log n) performance, best case O(n), but
|
||||||
* is not space efficient. This is a stable sort.
|
* 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);
|
type Slice = (uint, uint);
|
||||||
|
|
||||||
return merge_sort_(le, v, (0u, len(v)));
|
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] {
|
-> ~[T] {
|
||||||
let begin = slice.first();
|
let begin = slice.first();
|
||||||
let end = slice.second();
|
let end = slice.second();
|
||||||
@ -39,7 +39,7 @@ fn merge_sort<T: copy>(le: Le<T>, v: &[const T]) -> ~[T] {
|
|||||||
return merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b));
|
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 = ~[];
|
let mut rs = ~[];
|
||||||
vec::reserve(rs, len(a) + len(b));
|
vec::reserve(rs, len(a) + len(b));
|
||||||
let a_len = len(a);
|
let a_len = len(a);
|
||||||
@ -58,7 +58,7 @@ fn merge_sort<T: copy>(le: Le<T>, v: &[const T]) -> ~[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
right: uint, pivot: uint) -> uint {
|
||||||
let pivot_value = arr[pivot];
|
let pivot_value = arr[pivot];
|
||||||
arr[pivot] <-> arr[right];
|
arr[pivot] <-> arr[right];
|
||||||
@ -75,7 +75,7 @@ fn part<T: copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
|
|||||||
return storage_index;
|
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) {
|
right: uint) {
|
||||||
if right > left {
|
if right > left {
|
||||||
let pivot = (left + right) / 2u;
|
let pivot = (left + right) / 2u;
|
||||||
@ -94,12 +94,12 @@ fn qsort<T: copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
|
|||||||
* Has worst case O(n^2) performance, average case O(n log n).
|
* Has worst case O(n^2) performance, average case O(n log n).
|
||||||
* This is an unstable sort.
|
* 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; }
|
if len::<T>(arr) == 0u { return; }
|
||||||
qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u);
|
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; }
|
if right <= left { return; }
|
||||||
let v: T = arr[right];
|
let v: T = arr[right];
|
||||||
let mut i: int = left - 1;
|
let mut i: int = left - 1;
|
||||||
@ -156,7 +156,7 @@ fn qsort3<T: copy Ord Eq>(arr: &[mut T], left: int, right: int) {
|
|||||||
*
|
*
|
||||||
* This is an unstable sort.
|
* 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; }
|
if arr.len() <= 1 { return; }
|
||||||
qsort3(arr, 0, (arr.len() - 1) as int);
|
qsort3(arr, 0, (arr.len() - 1) as int);
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ trait Sort {
|
|||||||
fn qsort(self);
|
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); }
|
fn qsort(self) { quick_sort3(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +70,10 @@ struct SemInner<Q> {
|
|||||||
blocked: Q
|
blocked: Q
|
||||||
}
|
}
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
enum Sem<Q: send> = Exclusive<SemInner<Q>>;
|
enum Sem<Q: Send> = Exclusive<SemInner<Q>>;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[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 {
|
Sem(exclusive(SemInner {
|
||||||
mut count: count, waiters: new_waitqueue(), blocked: q }))
|
mut count: count, waiters: new_waitqueue(), blocked: q }))
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
impl<Q: send> &Sem<Q> {
|
impl<Q: Send> &Sem<Q> {
|
||||||
fn acquire() {
|
fn acquire() {
|
||||||
let mut waiter_nobe = None;
|
let mut waiter_nobe = None;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -26,7 +26,7 @@ export delayed_send, sleep, recv_timeout;
|
|||||||
* * ch - a channel of type T to send a `val` on
|
* * ch - a channel of type T to send a `val` on
|
||||||
* * val - a value of type T to send over the provided `ch`
|
* * 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) {
|
msecs: uint, ch: comm::Chan<T>, +val: T) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let timer_done_po = core::comm::Port::<()>();
|
let timer_done_po = core::comm::Port::<()>();
|
||||||
@ -102,7 +102,7 @@ fn sleep(iotask: IoTask, msecs: uint) {
|
|||||||
* on the provided port in the allotted timeout period, then the result will
|
* on the provided port in the allotted timeout period, then the result will
|
||||||
* be a `some(T)`. If not, then `none` will be returned.
|
* 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,
|
msecs: uint,
|
||||||
wait_po: comm::Port<T>) -> Option<T> {
|
wait_po: comm::Port<T>) -> Option<T> {
|
||||||
let timeout_po = comm::Port::<()>();
|
let timeout_po = comm::Port::<()>();
|
||||||
|
@ -32,7 +32,7 @@ enum TreeNode<K, V> = {
|
|||||||
fn TreeMap<K, V>() -> TreeMap<K, V> { @mut None }
|
fn TreeMap<K, V>() -> TreeMap<K, V> { @mut None }
|
||||||
|
|
||||||
/// Insert a value into the map
|
/// 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 {
|
match copy *m {
|
||||||
None => {
|
None => {
|
||||||
*m = Some(@TreeNode({key: k,
|
*m = Some(@TreeNode({key: k,
|
||||||
@ -54,7 +54,7 @@ fn insert<K: copy Eq Ord, V: copy>(m: &mut TreeEdge<K, V>, +k: K, +v: V) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find a value based on the key
|
/// 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> {
|
-> Option<V> {
|
||||||
match copy *m {
|
match copy *m {
|
||||||
None => None,
|
None => None,
|
||||||
@ -73,7 +73,7 @@ fn find<K: copy Eq Ord, V: copy>(m: &const TreeEdge<K, V>, +k: K)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all pairs in the map in order.
|
/// 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 {
|
match copy *m {
|
||||||
None => (),
|
None => (),
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
|
@ -259,7 +259,7 @@ impl def_id : core::to_bytes::IterBytes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>();
|
return std::map::hashmap::<ast::def_id, V>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect<T: copy>(diag: span_handler,
|
fn expect<T: Copy>(diag: span_handler,
|
||||||
opt: Option<T>, msg: fn() -> ~str) -> T {
|
opt: Option<T>, msg: fn() -> ~str) -> T {
|
||||||
match opt {
|
match opt {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
|
@ -88,7 +88,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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]> {
|
Option<~[U]> {
|
||||||
let mut res = ~[];
|
let mut res = ~[];
|
||||||
for v.each |elem| {
|
for v.each |elem| {
|
||||||
|
@ -41,21 +41,21 @@ trait parser_common {
|
|||||||
fn check_restricted_keywords();
|
fn check_restricted_keywords();
|
||||||
fn check_restricted_keywords_(w: ~str);
|
fn check_restricted_keywords_(w: ~str);
|
||||||
fn expect_gt();
|
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];
|
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];
|
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]>;
|
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];
|
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];
|
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,
|
ket: token::token,
|
||||||
sep: seq_sep,
|
sep: seq_sep,
|
||||||
f: fn(parser) -> T) -> ~[T];
|
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]>;
|
f: fn(parser) -> T) -> spanned<~[T]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ impl parser: parser_common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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] {
|
f: fn(parser) -> T) -> ~[T] {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
@ -217,7 +217,7 @@ impl parser: parser_common {
|
|||||||
return 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] {
|
f: fn(parser) -> T) -> ~[T] {
|
||||||
let v = self.parse_seq_to_before_gt(sep, f);
|
let v = self.parse_seq_to_before_gt(sep, f);
|
||||||
self.expect_gt();
|
self.expect_gt();
|
||||||
@ -225,7 +225,7 @@ impl parser: parser_common {
|
|||||||
return v;
|
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]> {
|
f: fn(parser) -> T) -> spanned<~[T]> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(token::LT);
|
self.expect(token::LT);
|
||||||
@ -235,7 +235,7 @@ impl parser: parser_common {
|
|||||||
return spanned(lo, hi, result);
|
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] {
|
f: fn(parser) -> T) -> ~[T] {
|
||||||
let val = self.parse_seq_to_before_end(ket, sep, f);
|
let val = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
self.bump();
|
self.bump();
|
||||||
@ -243,7 +243,7 @@ impl parser: parser_common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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] {
|
f: fn(parser) -> T) -> ~[T] {
|
||||||
let mut first: bool = true;
|
let mut first: bool = true;
|
||||||
let mut v: ~[T] = ~[];
|
let mut v: ~[T] = ~[];
|
||||||
@ -261,7 +261,7 @@ impl parser: parser_common {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_unspanned_seq<T: copy>(bra: token::token,
|
fn parse_unspanned_seq<T: Copy>(bra: token::token,
|
||||||
ket: token::token,
|
ket: token::token,
|
||||||
sep: seq_sep,
|
sep: seq_sep,
|
||||||
f: fn(parser) -> T) -> ~[T] {
|
f: fn(parser) -> T) -> ~[T] {
|
||||||
@ -273,7 +273,7 @@ impl parser: parser_common {
|
|||||||
|
|
||||||
// NB: Do not use this function unless you actually plan to place the
|
// NB: Do not use this function unless you actually plan to place the
|
||||||
// spanned list in the AST.
|
// 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]> {
|
f: fn(parser) -> T) -> spanned<~[T]> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
|
@ -2278,15 +2278,7 @@ struct parser {
|
|||||||
let mut bounds = ~[];
|
let mut bounds = ~[];
|
||||||
if self.eat(token::COLON) {
|
if self.eat(token::COLON) {
|
||||||
while is_ident(self.token) {
|
while is_ident(self.token) {
|
||||||
if self.eat_keyword(~"send") {
|
if is_ident(self.token) {
|
||||||
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) {
|
|
||||||
// XXX: temporary until kinds become traits
|
// XXX: temporary until kinds become traits
|
||||||
let maybe_bound = match self.token {
|
let maybe_bound = match self.token {
|
||||||
token::IDENT(sid, _) => {
|
token::IDENT(sid, _) => {
|
||||||
|
@ -386,7 +386,7 @@ fn contextual_keyword_table() -> hashmap<~str, ()> {
|
|||||||
~"else",
|
~"else",
|
||||||
~"move",
|
~"move",
|
||||||
~"priv", ~"pub",
|
~"priv", ~"pub",
|
||||||
~"self", ~"send", ~"static",
|
~"self", ~"static",
|
||||||
~"use"
|
~"use"
|
||||||
];
|
];
|
||||||
for keys.each |word| {
|
for keys.each |word| {
|
||||||
@ -421,7 +421,6 @@ fn restricted_keyword_table() -> hashmap<~str, ()> {
|
|||||||
~"if", ~"impl", ~"import",
|
~"if", ~"impl", ~"import",
|
||||||
~"let", ~"log", ~"loop",
|
~"let", ~"log", ~"loop",
|
||||||
~"match", ~"mod", ~"move", ~"mut",
|
~"match", ~"mod", ~"move", ~"mut",
|
||||||
~"owned",
|
|
||||||
~"pure",
|
~"pure",
|
||||||
~"ref", ~"return",
|
~"ref", ~"return",
|
||||||
~"struct",
|
~"struct",
|
||||||
|
@ -1658,10 +1658,10 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
|
|||||||
for vec::each(*bounds) |bound| {
|
for vec::each(*bounds) |bound| {
|
||||||
nbsp(s);
|
nbsp(s);
|
||||||
match bound {
|
match bound {
|
||||||
ast::bound_copy => word(s.s, ~"copy"),
|
ast::bound_copy => word(s.s, ~"Copy"),
|
||||||
ast::bound_send => word(s.s, ~"send"),
|
ast::bound_send => word(s.s, ~"Send"),
|
||||||
ast::bound_const => word(s.s, ~"const"),
|
ast::bound_const => word(s.s, ~"Const"),
|
||||||
ast::bound_owned => word(s.s, ~"owned"),
|
ast::bound_owned => word(s.s, ~"Owned"),
|
||||||
ast::bound_trait(t) => print_type(s, t)
|
ast::bound_trait(t) => print_type(s, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,18 +8,18 @@ use cmp::Eq;
|
|||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use to_bytes::IterBytes;
|
use to_bytes::IterBytes;
|
||||||
|
|
||||||
type hash_interner<T: const> =
|
type hash_interner<T: Const> =
|
||||||
{map: hashmap<T, uint>,
|
{map: hashmap<T, uint>,
|
||||||
vect: DVec<T>};
|
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 m = map::hashmap::<T, uint>();
|
||||||
let hi: hash_interner<T> =
|
let hi: hash_interner<T> =
|
||||||
{map: m, vect: DVec()};
|
{map: m, vect: DVec()};
|
||||||
return hi as interner::<T>;
|
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();
|
let rv = mk();
|
||||||
for init.each() |v| { rv.intern(v); }
|
for init.each() |v| { rv.intern(v); }
|
||||||
return rv;
|
return rv;
|
||||||
@ -27,14 +27,14 @@ fn mk_prefill<T:Eq IterBytes Hash const copy>(init: ~[T]) -> interner<T> {
|
|||||||
|
|
||||||
|
|
||||||
/* when traits can extend traits, we should extend index<uint,T> to get [] */
|
/* 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 intern(T) -> uint;
|
||||||
fn gensym(T) -> uint;
|
fn gensym(T) -> uint;
|
||||||
pure fn get(uint) -> T;
|
pure fn get(uint) -> T;
|
||||||
fn len() -> uint;
|
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 {
|
fn intern(val: T) -> uint {
|
||||||
match self.map.find(val) {
|
match self.map.find(val) {
|
||||||
Some(idx) => return idx,
|
Some(idx) => return idx,
|
||||||
|
@ -271,7 +271,7 @@ fn basic_options() -> @options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Seems out of place, but it uses session, so I'm putting it here
|
// 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)
|
diagnostic::expect(sess.diagnostic(), opt, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn use_core(crate: @ast::crate) -> bool {
|
|||||||
fn inject_libcore_ref(sess: session,
|
fn inject_libcore_ref(sess: session,
|
||||||
crate: @ast::crate) -> @ast::crate {
|
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,
|
return @{node: x,
|
||||||
span: dummy_sp()};
|
span: dummy_sp()};
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
|
|||||||
return @item;
|
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()};
|
return {node: t, span: dummy_sp()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,7 +866,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::Writer,
|
|||||||
|
|
||||||
// Path and definition ID indexing
|
// 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>]] {
|
~[@~[entry<T>]] {
|
||||||
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
|
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
|
||||||
for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); };
|
for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); };
|
||||||
|
@ -67,7 +67,7 @@ fn mk_filesearch(maybe_sysroot: Option<Path>,
|
|||||||
target_triple: str::from_slice(target_triple)} as filesearch
|
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;
|
let mut rslt = None;
|
||||||
for filesearch.lib_search_paths().each |lib_search_path| {
|
for filesearch.lib_search_paths().each |lib_search_path| {
|
||||||
debug!("searching %s", lib_search_path.to_str());
|
debug!("searching %s", lib_search_path.to_str());
|
||||||
|
@ -396,7 +396,7 @@ type req_maps = {
|
|||||||
pure_map: hashmap<ast::node_id, bckerr>
|
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 old_save_and_restore_t = save_and_restore_t;
|
||||||
let u <- f();
|
let u <- f();
|
||||||
save_and_restore_t = old_save_and_restore_t;
|
save_and_restore_t = old_save_and_restore_t;
|
||||||
|
@ -308,7 +308,7 @@ fn Atom(n: uint) -> Atom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a hash table of atoms.
|
/// 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>()
|
hashmap::<Atom,V>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ enum debug_metadata {
|
|||||||
retval_metadata(@metadata<retval_md>),
|
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;
|
let val2 = val;
|
||||||
return unsafe::transmute(val2);
|
return unsafe::transmute(val2);
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
eq: fn(md: T) -> bool) -> Option<T> unsafe {
|
||||||
if cache.contains_key(mdtag) {
|
if cache.contains_key(mdtag) {
|
||||||
let items = cache.get(mdtag);
|
let items = cache.get(mdtag);
|
||||||
|
@ -58,7 +58,7 @@ fn mk_nominal_id(tcx: ty::ctxt, did: ast::def_id,
|
|||||||
@{did: did, parent_id: parent_id, tps: tps_norm}
|
@{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 hashmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,7 +799,7 @@ fn mk_rcache() -> creader_cache {
|
|||||||
return map::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()
|
map::hashmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2568,7 +2568,7 @@ pure fn hash_bound_region(br: &bound_region) -> uint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn br_hashmap<V:copy>() -> hashmap<bound_region, V> {
|
fn br_hashmap<V:Copy>() -> hashmap<bound_region, V> {
|
||||||
map::hashmap()
|
map::hashmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3081,7 +3081,7 @@ fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) {
|
|||||||
|
|
||||||
// Maintains a little union-set tree for inferred modes. `canon()` returns
|
// Maintains a little union-set tree for inferred modes. `canon()` returns
|
||||||
// the current head value for `m0`.
|
// 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> {
|
+m0: ast::inferable<T>) -> ast::inferable<T> {
|
||||||
match m0 {
|
match m0 {
|
||||||
ast::infer(id) => match tbl.find(id) {
|
ast::infer(id) => match tbl.find(id) {
|
||||||
|
@ -69,7 +69,7 @@ fn get_region_reporting_err(tcx: ty::ctxt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region {
|
||||||
|
|
||||||
let res = match a_r.node {
|
let res = match a_r.node {
|
||||||
@ -80,7 +80,7 @@ fn ast_region_to_region<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
get_region_reporting_err(self.tcx(), span, res)
|
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,
|
self: AC, rscope: RS, did: ast::def_id,
|
||||||
path: @ast::path) -> ty_param_substs_and_ty {
|
path: @ast::path) -> ty_param_substs_and_ty {
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
{substs: substs, ty: ty::subst(tcx, &substs, decl_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,
|
self: AC,
|
||||||
rscope: RS,
|
rscope: RS,
|
||||||
did: ast::def_id,
|
did: ast::def_id,
|
||||||
@ -152,10 +152,10 @@ const NO_TPS: uint = 2u;
|
|||||||
// Parses the programmer's textual representation of a type into our
|
// Parses the programmer's textual representation of a type into our
|
||||||
// internal notion of a type. `getter` is a function that returns the type
|
// internal notion of a type. `getter` is a function that returns the type
|
||||||
// corresponding to a definition ID:
|
// 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 {
|
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 {
|
self: AC, rscope: RS, mt: ast::mt) -> ty::mt {
|
||||||
|
|
||||||
return {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl};
|
return {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl};
|
||||||
@ -164,7 +164,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
// Handle @, ~, and & being able to mean estrs and evecs.
|
// Handle @, ~, and & being able to mean estrs and evecs.
|
||||||
// If a_seq_ty is a str or a vec, make it an estr/evec.
|
// If a_seq_ty is a str or a vec, make it an estr/evec.
|
||||||
// Also handle function sigils and first-class trait types.
|
// 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,
|
self: AC, rscope: RS, a_seq_ty: ast::mt, vst: ty::vstore,
|
||||||
span: span, constr: fn(ty::mt) -> ty::t) -> ty::t {
|
span: span, constr: fn(ty::mt) -> ty::t) -> ty::t {
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
return typ;
|
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,
|
self: AC, rscope: RS, a: ast::arg,
|
||||||
expected_ty: Option<ty::arg>) -> ty::arg {
|
expected_ty: Option<ty::arg>) -> ty::arg {
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
{mode: mode, ty: ty}
|
{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 {
|
self: AC, rscope: RS, span: span, ast_proto: ast::proto) -> ty::fn_proto {
|
||||||
match ast_proto {
|
match ast_proto {
|
||||||
ast::proto_bare =>
|
ast::proto_bare =>
|
||||||
@ -465,7 +465,7 @@ fn ast_proto_to_proto<AC: ast_conv, RS: region_scope copy owned>(
|
|||||||
type expected_tys = Option<{inputs: ~[ty::arg],
|
type expected_tys = Option<{inputs: ~[ty::arg],
|
||||||
output: ty::t}>;
|
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,
|
self: AC, rscope: RS,
|
||||||
ast_proto: ast::proto,
|
ast_proto: ast::proto,
|
||||||
purity: ast::purity,
|
purity: ast::purity,
|
||||||
|
@ -1203,7 +1203,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
|||||||
// through the `unpack` function. It there is no expected type or
|
// through the `unpack` function. It there is no expected type or
|
||||||
// resolution is not possible (e.g., no constraints yet present), just
|
// resolution is not possible (e.g., no constraints yet present), just
|
||||||
// returns `none`.
|
// 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>)
|
unpack: fn(ty::sty) -> Option<O>)
|
||||||
-> Option<O> {
|
-> Option<O> {
|
||||||
match expected {
|
match expected {
|
||||||
|
@ -75,7 +75,7 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl @crate_ctxt {
|
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 {
|
rs: RS, ast_ty: @ast::ty) -> ty::t {
|
||||||
|
|
||||||
ast_ty_to_ty(self, rs, ast_ty)
|
ast_ty_to_ty(self, rs, ast_ty)
|
||||||
|
@ -298,8 +298,8 @@ export assignment;
|
|||||||
export root, to_str;
|
export root, to_str;
|
||||||
export int_ty_set_all;
|
export int_ty_set_all;
|
||||||
|
|
||||||
type bound<T:copy> = Option<T>;
|
type bound<T:Copy> = Option<T>;
|
||||||
type bounds<T:copy> = {lb: bound<T>, ub: bound<T>};
|
type bounds<T:Copy> = {lb: bound<T>, ub: bound<T>};
|
||||||
|
|
||||||
type cres<T> = Result<T,ty::type_err>; // "combine result"
|
type cres<T> = Result<T,ty::type_err>; // "combine result"
|
||||||
type ures = cres<()>; // "unify result"
|
type ures = cres<()>; // "unify result"
|
||||||
@ -348,7 +348,7 @@ fn fixup_err_to_str(f: fixup_err) -> ~str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_and_bindings {
|
||||||
vals: smallintmap::mk(),
|
vals: smallintmap::mk(),
|
||||||
mut bindings: ~[]
|
mut bindings: ~[]
|
||||||
@ -458,12 +458,12 @@ fn resolve_borrowings(cx: infer_ctxt) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
trait then {
|
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>;
|
-> Result<T,ty::type_err>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ures: then {
|
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> {
|
-> Result<T,ty::type_err> {
|
||||||
self.chain(|_i| f())
|
self.chain(|_i| f())
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ trait cres_helpers<T> {
|
|||||||
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T>;
|
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 {
|
fn to_ures() -> ures {
|
||||||
match self {
|
match self {
|
||||||
Ok(_v) => Ok(()),
|
Ok(_v) => Ok(()),
|
||||||
@ -497,7 +497,7 @@ fn uok() -> ures {
|
|||||||
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) {
|
vb: &vals_and_bindings<V, T>, len: uint) {
|
||||||
|
|
||||||
while vb.bindings.len() != len {
|
while vb.bindings.len() != len {
|
||||||
|
@ -23,7 +23,7 @@ impl ty::region: to_str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn to_str(cx: infer_ctxt) -> ~str {
|
||||||
match self {
|
match self {
|
||||||
Some(v) => v.to_str(cx),
|
Some(v) => v.to_str(cx),
|
||||||
@ -32,7 +32,7 @@ impl<V:copy to_str> bound<V>: to_str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn to_str(cx: infer_ctxt) -> ~str {
|
||||||
fmt!("{%s <: %s}",
|
fmt!("{%s <: %s}",
|
||||||
self.lb.to_str(cx),
|
self.lb.to_str(cx),
|
||||||
@ -48,7 +48,7 @@ impl int_ty_set: to_str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn to_str(cx: infer_ctxt) -> ~str {
|
||||||
match self {
|
match self {
|
||||||
redirect(vid) => fmt!("redirect(%s)", vid.to_str()),
|
redirect(vid) => fmt!("redirect(%s)", vid.to_str()),
|
||||||
|
@ -3,24 +3,24 @@ use integral::*;
|
|||||||
use to_str::to_str;
|
use to_str::to_str;
|
||||||
use std::smallintmap::SmallIntMap;
|
use std::smallintmap::SmallIntMap;
|
||||||
|
|
||||||
enum var_value<V:copy, T:copy> {
|
enum var_value<V:Copy, T:Copy> {
|
||||||
redirect(V),
|
redirect(V),
|
||||||
root(T, uint),
|
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>>,
|
vals: SmallIntMap<var_value<V, T>>,
|
||||||
mut bindings: ~[(V, 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,
|
root: V,
|
||||||
possible_types: T,
|
possible_types: T,
|
||||||
rank: uint,
|
rank: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl infer_ctxt {
|
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> {
|
vb: &vals_and_bindings<V, T>, vid: V) -> node<V, T> {
|
||||||
|
|
||||||
let vid_u = vid.to_uint();
|
let vid_u = vid.to_uint();
|
||||||
@ -46,7 +46,7 @@ impl infer_ctxt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
vb: &vals_and_bindings<V, T>, vid: V,
|
||||||
+new_v: var_value<V, T>) {
|
+new_v: var_value<V, T>) {
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ fn bound_self_region(rp: Option<ty::region_variance>) -> Option<ty::region> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum anon_rscope = {anon: ty::region, base: region_scope};
|
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_rscope({anon: r, base: self as region_scope})
|
@anon_rscope({anon: r, base: self as region_scope})
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ struct binding_rscope {
|
|||||||
base: region_scope,
|
base: region_scope,
|
||||||
mut anon_bindings: uint,
|
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 {
|
-> @binding_rscope {
|
||||||
let base = self as region_scope;
|
let base = self as region_scope;
|
||||||
@binding_rscope { base: base, anon_bindings: 0 }
|
@binding_rscope { base: base, anon_bindings: 0 }
|
||||||
|
@ -88,7 +88,7 @@ fn act(po: comm::Port<msg>, source: ~str, parse: parser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec<T:send>(
|
fn exec<T:Send>(
|
||||||
srv: srv,
|
srv: srv,
|
||||||
+f: fn~(ctxt: ctxt) -> T
|
+f: fn~(ctxt: ctxt) -> T
|
||||||
) -> T {
|
) -> T {
|
||||||
|
@ -89,7 +89,7 @@ fn fold_item(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_attrs<T:send>(
|
fn parse_item_attrs<T:Send>(
|
||||||
srv: astsrv::srv,
|
srv: astsrv::srv,
|
||||||
id: doc::ast_id,
|
id: doc::ast_id,
|
||||||
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
|
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
|
||||||
|
@ -50,7 +50,7 @@ type t<T> = {
|
|||||||
|
|
||||||
// This exists because fn types don't infer correctly as record
|
// This exists because fn types don't infer correctly as record
|
||||||
// initializers, but they do as function arguments
|
// initializers, but they do as function arguments
|
||||||
fn mk_fold<T:copy>(
|
fn mk_fold<T:Copy>(
|
||||||
ctxt: T,
|
ctxt: T,
|
||||||
+fold_doc: fold_doc<T>,
|
+fold_doc: fold_doc<T>,
|
||||||
+fold_crate: fold_crate<T>,
|
+fold_crate: fold_crate<T>,
|
||||||
@ -80,7 +80,7 @@ fn mk_fold<T:copy>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
|
fn default_any_fold<T:Send Copy>(ctxt: T) -> fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
@ -97,7 +97,7 @@ fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
|
fn default_seq_fold<T:Copy>(ctxt: T) -> fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
@ -114,7 +114,7 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
|
fn default_par_fold<T:Send Copy>(ctxt: T) -> fold<T> {
|
||||||
mk_fold(
|
mk_fold(
|
||||||
ctxt,
|
ctxt,
|
||||||
|f, d| default_seq_fold_doc(f, d),
|
|f, d| default_seq_fold_doc(f, d),
|
||||||
@ -163,7 +163,7 @@ fn default_seq_fold_item<T>(
|
|||||||
doc
|
doc
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_any_fold_mod<T:send copy>(
|
fn default_any_fold_mod<T:Send Copy>(
|
||||||
fold: fold<T>,
|
fold: fold<T>,
|
||||||
doc: doc::moddoc
|
doc: doc::moddoc
|
||||||
) -> doc::moddoc {
|
) -> doc::moddoc {
|
||||||
@ -189,7 +189,7 @@ fn default_seq_fold_mod<T>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_par_fold_mod<T:send copy>(
|
fn default_par_fold_mod<T:Send Copy>(
|
||||||
fold: fold<T>,
|
fold: fold<T>,
|
||||||
doc: doc::moddoc
|
doc: doc::moddoc
|
||||||
) -> doc::moddoc {
|
) -> doc::moddoc {
|
||||||
@ -202,7 +202,7 @@ fn default_par_fold_mod<T:send copy>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_any_fold_nmod<T:send copy>(
|
fn default_any_fold_nmod<T:Send Copy>(
|
||||||
fold: fold<T>,
|
fold: fold<T>,
|
||||||
doc: doc::nmoddoc
|
doc: doc::nmoddoc
|
||||||
) -> doc::nmoddoc {
|
) -> doc::nmoddoc {
|
||||||
@ -228,7 +228,7 @@ fn default_seq_fold_nmod<T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_par_fold_nmod<T:send copy>(
|
fn default_par_fold_nmod<T:Send Copy>(
|
||||||
fold: fold<T>,
|
fold: fold<T>,
|
||||||
doc: doc::nmoddoc
|
doc: doc::nmoddoc
|
||||||
) -> doc::nmoddoc {
|
) -> doc::nmoddoc {
|
||||||
|
@ -2,7 +2,7 @@ export foo;
|
|||||||
|
|
||||||
use comm::*;
|
use comm::*;
|
||||||
|
|
||||||
fn foo<T: send copy>(x: T) -> Port<T> {
|
fn foo<T: Send Copy>(x: T) -> Port<T> {
|
||||||
let p = Port();
|
let p = Port();
|
||||||
let c = Chan(p);
|
let c = Chan(p);
|
||||||
do task::spawn() |copy c, copy x| {
|
do task::spawn() |copy c, copy x| {
|
||||||
|
@ -3,11 +3,11 @@ use dvec::DVec;
|
|||||||
type entry<A,B> = {key: A, value: B};
|
type entry<A,B> = {key: A, value: B};
|
||||||
type alist<A,B> = { eq_fn: fn@(A,A) -> bool, data: DVec<entry<A,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});
|
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;
|
let eq_fn = lst.eq_fn;
|
||||||
for lst.data.each |entry| {
|
for lst.data.each |entry| {
|
||||||
if eq_fn(entry.key, k) { return entry.value; }
|
if eq_fn(entry.key, k) { return entry.value; }
|
||||||
@ -16,13 +16,13 @@ fn alist_get<A: copy, B: copy>(lst: alist<A,B>, k: A) -> B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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 }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return {eq_fn: eq_int, data: DVec()};
|
return {eq_fn: eq_int, data: DVec()};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_int_alist_2<B: copy>() -> alist<int, B> {
|
fn new_int_alist_2<B: Copy>() -> alist<int, B> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
||||||
return {eq_fn: eq_int, data: DVec()};
|
return {eq_fn: eq_int, data: DVec()};
|
||||||
|
@ -7,18 +7,18 @@ use std;
|
|||||||
|
|
||||||
export context;
|
export context;
|
||||||
|
|
||||||
struct arc_destruct<T:const> {
|
struct arc_destruct<T:Const> {
|
||||||
_data: int,
|
_data: int,
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arc_destruct<T: const>(data: int) -> arc_destruct<T> {
|
fn arc_destruct<T: Const>(data: int) -> arc_destruct<T> {
|
||||||
arc_destruct {
|
arc_destruct {
|
||||||
_data: data
|
_data: data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arc<T: const>(_data: T) -> arc_destruct<T> {
|
fn arc<T: Const>(_data: T) -> arc_destruct<T> {
|
||||||
arc_destruct(0)
|
arc_destruct(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,6 @@ use std::map::hashmap;
|
|||||||
type header_map = hashmap<~str, @DVec<@~str>>;
|
type header_map = hashmap<~str, @DVec<@~str>>;
|
||||||
|
|
||||||
// the unused ty param is necessary so this gets monomorphized
|
// 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];
|
let _x = *(*req.get(~"METHOD"))[0u];
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ impl bool: read {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read<T: read copy>(s: ~str) -> T {
|
fn read<T: read Copy>(s: ~str) -> T {
|
||||||
match readMaybe(s) {
|
match readMaybe(s) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => fail ~"read failed!"
|
_ => fail ~"read failed!"
|
||||||
|
@ -18,16 +18,16 @@ export recv;
|
|||||||
* transmitted. If a port value is copied, both copies refer to the same
|
* transmitted. If a port value is copied, both copies refer to the same
|
||||||
* port. Ports may be associated with multiple `chan`s.
|
* port. Ports may be associated with multiple `chan`s.
|
||||||
*/
|
*/
|
||||||
enum port<T: send> {
|
enum port<T: Send> {
|
||||||
port_t(@port_ptr<T>)
|
port_t(@port_ptr<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a port
|
/// 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)))
|
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,
|
po: *rust_port,
|
||||||
drop unsafe {
|
drop unsafe {
|
||||||
debug!("in the port_ptr destructor");
|
debug!("in the port_ptr destructor");
|
||||||
@ -48,7 +48,7 @@ struct port_ptr<T:send> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
debug!("in the port_ptr constructor");
|
||||||
port_ptr {
|
port_ptr {
|
||||||
po: po
|
po: po
|
||||||
@ -59,11 +59,11 @@ fn port_ptr<T: send>(po: *rust_port) -> port_ptr<T> {
|
|||||||
* Receive from a port. If no data is available on the port then the
|
* Receive from a port. If no data is available on the port then the
|
||||||
* task will block until data becomes available.
|
* 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
|
/// 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 yield = 0u;
|
||||||
let yieldp = ptr::addr_of(yield);
|
let yieldp = ptr::addr_of(yield);
|
||||||
let mut res;
|
let mut res;
|
||||||
|
@ -64,7 +64,7 @@ macro_rules! follow (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
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: fn(+Option<T>) -> U) -> U {
|
||||||
f(pipes::try_recv(endp))
|
f(pipes::try_recv(endp))
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str {
|
|||||||
return (xx as float) * 100f / (yy as float);
|
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 {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (_, v0) = *kv0;
|
let (_, v0) = *kv0;
|
||||||
let (_, v1) = *kv1;
|
let (_, v1) = *kv1;
|
||||||
return v0 >= v1;
|
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 {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (k0, _) = *kv0;
|
let (k0, _) = *kv0;
|
||||||
let (k1, _) = *kv1;
|
let (k1, _) = *kv1;
|
||||||
@ -30,7 +30,7 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort by key, then by value
|
// 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 sort::merge_sort(le_by_val, sort::merge_sort(le_by_key, orig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str {
|
|||||||
return (xx as float) * 100f / (yy as float);
|
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 {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (_, v0) = *kv0;
|
let (_, v0) = *kv0;
|
||||||
let (_, v1) = *kv1;
|
let (_, v1) = *kv1;
|
||||||
return v0 >= v1;
|
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 {
|
kv1: &(TT,UU)) -> bool {
|
||||||
let (k0, _) = *kv0;
|
let (k0, _) = *kv0;
|
||||||
let (k1, _) = *kv1;
|
let (k1, _) = *kv1;
|
||||||
@ -29,7 +29,7 @@ fn sort_and_fmt(mm: hashmap<~[u8], uint>, total: uint) -> ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort by key, then by value
|
// 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 sort::merge_sort(le_by_val, sort::merge_sort(le_by_key, orig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ trait hash_key {
|
|||||||
pure fn eq(&&k: self) -> bool;
|
pure fn eq(&&k: self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_hash<K: const hash_key, V: copy>() -> map::hashmap<K, V> {
|
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 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) }
|
pure fn hasheq<K: Const hash_key>(k1: &K, k2: &K) -> bool { k1.eq(*k2) }
|
||||||
|
|
||||||
map::hashmap(hashfn, hasheq)
|
map::hashmap(hashfn, hasheq)
|
||||||
}
|
}
|
||||||
@ -125,35 +125,35 @@ mod map_reduce {
|
|||||||
export reducer;
|
export reducer;
|
||||||
export map_reduce;
|
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>>>),
|
find_reducer(K, Chan<Chan<reduce_proto<V>>>),
|
||||||
mapper_done
|
mapper_done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
proto! ctrl_proto (
|
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>,
|
find_reducer(K) -> reducer_response<K, V>,
|
||||||
mapper_done -> !
|
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>
|
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,
|
fn start_mappers<K1: Copy Send, K2: Const Copy Send hash_key,
|
||||||
V: copy send>(
|
V: Copy Send>(
|
||||||
map: mapper<K1, K2, V>,
|
map: mapper<K1, K2, V>,
|
||||||
&ctrls: ~[ctrl_proto::server::open<K2, V>],
|
&ctrls: ~[ctrl_proto::server::open<K2, V>],
|
||||||
inputs: ~[K1])
|
inputs: ~[K1])
|
||||||
@ -169,7 +169,7 @@ mod map_reduce {
|
|||||||
return tasks;
|
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>,
|
map: mapper<K1, K2, V>,
|
||||||
ctrl: box<ctrl_proto::client::open<K2, V>>,
|
ctrl: box<ctrl_proto::client::open<K2, V>>,
|
||||||
input: K1)
|
input: K1)
|
||||||
@ -198,7 +198,7 @@ mod map_reduce {
|
|||||||
send(c.get(), emit_val(val));
|
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);
|
send(v, release);
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ mod map_reduce {
|
|||||||
ctrl_proto::client::mapper_done(ctrl.unwrap());
|
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>,
|
reduce: reducer<K, V>,
|
||||||
key: K,
|
key: K,
|
||||||
out: Chan<Chan<reduce_proto<V>>>)
|
out: Chan<Chan<reduce_proto<V>>>)
|
||||||
@ -218,7 +218,7 @@ mod map_reduce {
|
|||||||
let mut ref_count = 0;
|
let mut ref_count = 0;
|
||||||
let mut is_done = false;
|
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)
|
&ref_count: int, &is_done: bool)
|
||||||
-> Option<V> {
|
-> Option<V> {
|
||||||
while !is_done || ref_count > 0 {
|
while !is_done || ref_count > 0 {
|
||||||
@ -241,7 +241,7 @@ mod map_reduce {
|
|||||||
reduce(key, || get(p, ref_count, is_done) );
|
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>,
|
map: mapper<K1, K2, V>,
|
||||||
reduce: reducer<K2, V>,
|
reduce: reducer<K2, V>,
|
||||||
inputs: ~[K1])
|
inputs: ~[K1])
|
||||||
|
@ -3,11 +3,11 @@ fn foo<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait bar {
|
trait bar {
|
||||||
fn bar<T:copy>();
|
fn bar<T:Copy>();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl uint: bar {
|
impl uint: bar {
|
||||||
fn bar<T:copy>() {
|
fn bar<T:Copy>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn reproduce<T:copy>(t: T) -> fn@() -> T {
|
fn reproduce<T:Copy>(t: T) -> fn@() -> T {
|
||||||
fn@() -> T { t }
|
fn@() -> T { t }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn mk_identity<T:copy>() -> fn@(T) -> T {
|
fn mk_identity<T:Copy>() -> fn@(T) -> T {
|
||||||
fn@(t: T) -> T { t }
|
fn@(t: T) -> T { t }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ impl uint: to_opt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:copy> Option<T>: to_opt {
|
impl<T:Copy> Option<T>: to_opt {
|
||||||
fn to_option() -> Option<Option<T>> {
|
fn to_option() -> Option<Option<T>> {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn foo<T: copy>(+_t: T) { fail; }
|
fn foo<T: Copy>(+_t: T) { fail; }
|
||||||
|
|
||||||
fn bar<T>(+_t: T) { fail; }
|
fn bar<T>(+_t: T) { fail; }
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import iter;
|
|||||||
import iter::BaseIter;
|
import iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:copy const, D>(x: C) -> C;
|
fn b<C:Copy Const, D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
@ -15,7 +15,7 @@ struct E {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl E: A {
|
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() {}
|
fn main() {}
|
@ -4,7 +4,7 @@ import iter;
|
|||||||
import iter::BaseIter;
|
import iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:copy, D>(x: C) -> C;
|
fn b<C:Copy, D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
@ -12,7 +12,7 @@ struct E {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl E: A {
|
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() {}
|
fn main() {}
|
@ -4,7 +4,7 @@ import iter;
|
|||||||
import iter::BaseIter;
|
import iter::BaseIter;
|
||||||
|
|
||||||
trait A {
|
trait A {
|
||||||
fn b<C:copy, D>(x: C) -> C;
|
fn b<C:Copy, D>(x: C) -> C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct E {
|
struct E {
|
||||||
@ -13,7 +13,7 @@ struct E {
|
|||||||
|
|
||||||
impl E: A {
|
impl E: A {
|
||||||
// n.b. The error message is awful -- see #3404
|
// 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() {}
|
fn main() {}
|
@ -1,4 +1,4 @@
|
|||||||
struct send_packet<T: copy> {
|
struct send_packet<T: Copy> {
|
||||||
p: T
|
p: T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
mod stream {
|
mod stream {
|
||||||
enum stream<T: send> { send(T, server::stream<T>), }
|
enum stream<T: Send> { send(T, server::stream<T>), }
|
||||||
mod server {
|
mod server {
|
||||||
impl<T: send> stream<T> {
|
impl<T: Send> stream<T> {
|
||||||
fn recv() -> extern fn(+stream<T>) -> stream::stream<T> {
|
fn recv() -> extern fn(+stream<T>) -> stream::stream<T> {
|
||||||
// resolve really should report just one error here.
|
// resolve really should report just one error here.
|
||||||
// Change the test case when it changes.
|
// Change the test case when it changes.
|
||||||
@ -14,7 +14,7 @@ mod stream {
|
|||||||
recv
|
recv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type stream<T: send> = pipes::RecvPacket<stream::stream<T>>;
|
type stream<T: Send> = pipes::RecvPacket<stream::stream<T>>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
trait repeat<A> { fn get() -> A; }
|
trait repeat<A> { fn get() -> A; }
|
||||||
|
|
||||||
impl<A:copy> @A: repeat<A> {
|
impl<A:Copy> @A: repeat<A> {
|
||||||
fn get() -> A { *self }
|
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
|
// Note: owned kind is not necessary as A appears in the trait type
|
||||||
v as repeat::<A> // No
|
v as repeat::<A> // No
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ trait foo {
|
|||||||
fn foo(i: &self/int) -> int;
|
fn foo(i: &self/int) -> int;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:copy> T: foo {
|
impl<T:Copy> T: foo {
|
||||||
fn foo(i: &self/int) -> int {*i}
|
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
|
// This version is ok because, although T may contain borrowed
|
||||||
// pointers, it never escapes the fn body. We know this because
|
// pointers, it never escapes the fn body. We know this because
|
||||||
// the type of foo includes a region which will be resolved to
|
// the type of foo includes a region which will be resolved to
|
||||||
@ -19,13 +19,13 @@ fn to_foo<T:copy>(t: T) {
|
|||||||
assert x.foo(v) == 3;
|
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
|
// Not OK---T may contain borrowed ptrs and it is going to escape
|
||||||
// as part of the returned foo value
|
// as part of the returned foo value
|
||||||
{f:t} as foo //~ ERROR value may contain borrowed pointers; use `owned` bound
|
{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
|
// OK---T may escape as part of the returned foo value, but it is
|
||||||
// owned and hence does not contain borrowed ptrs
|
// owned and hence does not contain borrowed ptrs
|
||||||
{f:t} as foo
|
{f:t} as foo
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
trait foo { fn 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
|
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
|
t as foo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
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@() -> 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@() -> T { t }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn send<T: send>(ch: _chan<T>, -data: T) {
|
fn send<T: Send>(ch: _chan<T>, -data: T) {
|
||||||
log(debug, ch);
|
log(debug, ch);
|
||||||
log(debug, data);
|
log(debug, data);
|
||||||
fail;
|
fail;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Test that various non const things are rejected.
|
// Test that various non const things are rejected.
|
||||||
|
|
||||||
fn foo<T: const>(_x: T) { }
|
fn foo<T: Const>(_x: T) { }
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
x:int,
|
x:int,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use core;
|
use core;
|
||||||
|
|
||||||
fn last<T: copy>(v: ~[const T]) -> core::Option<T> {
|
fn last<T: Copy>(v: ~[const T]) -> core::Option<T> {
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ enum box_impl<T> = {
|
|||||||
mut f: T
|
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 get() -> T { return self.f; }
|
||||||
fn set(t: T) { self.f = t; }
|
fn set(t: T) { self.f = t; }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn f<T: send>(_i: T) {
|
fn f<T: Send>(_i: T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn concat<T: copy>(v: ~[const ~[const T]]) -> ~[T] {
|
fn concat<T: Copy>(v: ~[const ~[const T]]) -> ~[T] {
|
||||||
let mut r = ~[];
|
let mut r = ~[];
|
||||||
|
|
||||||
// Earlier versions of our type checker accepted this:
|
// Earlier versions of our type checker accepted this:
|
||||||
|
@ -4,8 +4,8 @@ fn test00_start(ch: chan_t<int>, message: int) { send(ch, message); }
|
|||||||
type task_id = int;
|
type task_id = int;
|
||||||
type port_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"; }
|
fn main() { fail ~"quux"; }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use std;
|
use std;
|
||||||
use std::arc;
|
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;}
|
fn foo() -> e<int> {fail;}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use comm::Port;
|
|||||||
use comm::send;
|
use comm::send;
|
||||||
use comm::recv;
|
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
|
// Tests that the type argument in port gets
|
||||||
// visited
|
// visited
|
||||||
let p = Port::<T>();
|
let p = Port::<T>();
|
||||||
|
@ -2,7 +2,7 @@ type pair<A,B> = {
|
|||||||
a: A, b: B
|
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) }
|
fn@() -> (A, u16) { (a, b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user