Skip to content

Rename Owned to Static, Send to Owned #4166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2725,11 +2725,11 @@ The kinds are:
`Const`
: Types of this kind are deeply immutable;
they contain no mutable memory locations directly or indirectly via pointers.
`Send`
`Owned`
: Types of this kind can be safely sent between tasks.
This kind includes scalars, owning pointers, owned closures, and
structural types containing only other sendable types.
`Owned`
structural types containing only other owned types. All `Owned` types are `Static`.
`Static`
: Types of this kind do not contain any borrowed pointers;
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
`Copy`
Expand Down Expand Up @@ -2818,10 +2818,10 @@ frame they are allocated within.
A task owns all memory it can *safely* reach through local variables,
as well as managed, owning and borrowed pointers.

When a task sends a value that has the `Send` trait to another task,
When a task sends a value that has the `Owned` trait to another task,
it loses ownership of the value sent and can no longer refer to it.
This is statically guaranteed by the combined use of "move semantics",
and the compiler-checked _meaning_ of the `Send` trait:
and the compiler-checked _meaning_ of the `Owned` trait:
it is only instantiated for (transitively) sendable kinds of data constructor and pointers,
never including managed or borrowed pointers.

Expand Down Expand Up @@ -2956,7 +2956,7 @@ These include:
- read-only and read-write shared variables with various safe mutual exclusion patterns
- simple locks and semaphores

When such facilities carry values, the values are restricted to the [`Send` type-kind](#type-kinds).
When such facilities carry values, the values are restricted to the [`Owned` type-kind](#type-kinds).
Restricting communication interfaces to this kind ensures that no borrowed or managed pointers move between tasks.
Thus access to an entire data structure can be mediated through its owning "root" value;
no further locking or copying is required to avoid data races within the substructure of such a value.
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1914,9 +1914,9 @@ types by the compiler, and may not be overridden:
`copy` operator. All types are copyable unless they have destructors or
contain types with destructors.

* `Send` - Sendable (owned) types. All types are sendable unless they
contain managed boxes, managed closures, or otherwise managed
types. Sendable types may or may not be copyable.
* `Owned` - Owned types. Types are owned unless they contain managed
boxes, managed closures, or borrowed pointers. Owned types may or
may not be copyable.

* `Const` - Constant (immutable) types. These are types that do not contain
mutable fields.
Expand Down Expand Up @@ -1949,7 +1949,7 @@ may call it.
## Declaring and implementing traits

A trait consists of a set of methods, without bodies, or may be empty,
as is the case with `Copy`, `Send`, and `Const`. For example, we could
as is the case with `Copy`, `Owned`, and `Const`. For example, we could
declare the trait `Printable` for things that can be printed to the
console, with a single method:

Expand Down
34 changes: 17 additions & 17 deletions src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use libc::size_t;
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
pub enum Port<T: Send> {
pub enum Port<T: Owned> {
Port_(@PortPtr<T>)
}

Expand All @@ -73,16 +73,16 @@ pub enum Port<T: Send> {
* data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels.
*/
pub enum Chan<T: Send> {
pub enum Chan<T: Owned> {
Chan_(port_id)
}

/// Constructs a port
pub fn Port<T: Send>() -> Port<T> {
pub fn Port<T: Owned>() -> Port<T> {
Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}

impl<T: Send> Port<T> {
impl<T: Owned> Port<T> {

fn chan() -> Chan<T> { Chan(&self) }
fn send(v: T) { self.chan().send(move v) }
Expand All @@ -91,7 +91,7 @@ impl<T: Send> Port<T> {

}

impl<T: Send> Chan<T> {
impl<T: Owned> Chan<T> {

fn chan() -> Chan<T> { self }
fn send(v: T) { send(self, move v) }
Expand All @@ -101,12 +101,12 @@ impl<T: Send> Chan<T> {
}

/// Open a new receiving channel for the duration of a function
pub fn listen<T: Send, U>(f: fn(Chan<T>) -> U) -> U {
pub fn listen<T: Owned, U>(f: fn(Chan<T>) -> U) -> U {
let po = Port();
f(po.chan())
}

struct PortPtr<T:Send> {
struct PortPtr<T:Owned> {
po: *rust_port,
drop unsafe {
do task::unkillable {
Expand All @@ -130,7 +130,7 @@ struct PortPtr<T:Send> {
}
}

fn PortPtr<T: Send>(po: *rust_port) -> PortPtr<T> {
fn PortPtr<T: Owned>(po: *rust_port) -> PortPtr<T> {
PortPtr {
po: po
}
Expand All @@ -144,7 +144,7 @@ fn PortPtr<T: Send>(po: *rust_port) -> PortPtr<T> {
* Fails if the port is detached or dead. Fails if the port
* is owned by a different task.
*/
fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
fn as_raw_port<T: Owned, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {

struct PortRef {
p: *rust_port,
Expand Down Expand Up @@ -176,15 +176,15 @@ 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
* construct it.
*/
pub fn Chan<T: Send>(p: &Port<T>) -> Chan<T> {
pub fn Chan<T: Owned>(p: &Port<T>) -> Chan<T> {
Chan_(rustrt::get_port_id((**p).po))
}

/**
* Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it.
*/
pub fn send<T: Send>(ch: Chan<T>, data: T) {
pub fn send<T: Owned>(ch: Chan<T>, data: T) {
let Chan_(p) = ch;
let data_ptr = ptr::addr_of(&data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
Expand All @@ -199,22 +199,22 @@ pub fn send<T: Send>(ch: Chan<T>, data: T) {
* Receive from a port. If no data is available on the port then the
* task will block until data becomes available.
*/
pub fn recv<T: Send>(p: Port<T>) -> T { recv_((**p).po) }
pub fn recv<T: Owned>(p: Port<T>) -> T { recv_((**p).po) }

/// Returns true if there are messages available
pub fn peek<T: Send>(p: Port<T>) -> bool { peek_((**p).po) }
pub fn peek<T: Owned>(p: Port<T>) -> bool { peek_((**p).po) }

#[doc(hidden)]
pub fn recv_chan<T: Send>(ch: comm::Chan<T>) -> T {
pub fn recv_chan<T: Owned>(ch: comm::Chan<T>) -> T {
as_raw_port(ch, |x|recv_(x))
}

fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
fn peek_chan<T: Owned>(ch: comm::Chan<T>) -> bool {
as_raw_port(ch, |x|peek_(x))
}

/// Receive on a raw port pointer
fn recv_<T: Send>(p: *rust_port) -> T {
fn recv_<T: Owned>(p: *rust_port) -> T {
let yield = 0;
let yieldp = ptr::addr_of(&yield);
let mut res;
Expand All @@ -240,7 +240,7 @@ fn peek_(p: *rust_port) -> bool {
}

/// Receive on one of two ports
pub fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
pub fn select2<A: Owned, B: Owned>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0, yieldp = ptr::addr_of(&yield);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub mod util;

/* Reexported core operators */

pub use kinds::{Const, Copy, Send, Owned};
pub use kinds::{Const, Copy, Owned, Static};
pub use ops::{Drop};
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg};
pub use ops::{BitAnd, BitOr, BitXor};
Expand Down
28 changes: 22 additions & 6 deletions src/libcore/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ The 4 kinds are
scalar types and managed pointers, and exludes owned pointers. It
also excludes types that implement `Drop`.

* Send - owned types and types containing owned types. These types
* Owned - owned types and types containing owned types. These types
may be transferred across task boundaries.

* Const - types that are deeply immutable. Const types are used for
freezable data structures.

* Owned - types that do not contain borrowed pointers. Note that this
meaning of 'owned' conflicts with 'owned pointers'. The two notions
of ownership are different.
* Static - types that do not contain borrowed pointers.

`Copy` types include both implicitly copyable types that the compiler
will copy automatically and non-implicitly copyable types that require
Expand All @@ -46,8 +44,17 @@ pub trait Copy {
// Empty.
}

#[cfg(stage0)]
#[lang="send"]
pub trait Send {
pub trait Owned {
// Empty.
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[lang="owned"]
pub trait Owned {
// Empty.
}

Expand All @@ -56,7 +63,16 @@ pub trait Const {
// Empty.
}

#[cfg(stage0)]
#[lang="owned"]
pub trait Owned {
pub trait Static {
// Empty.
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
#[lang="static"]
pub trait Static {
// Empty.
}
Loading