From e12711540a00ded4021250f7b2a31773fc4dc734 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 17 Dec 2013 16:46:18 -0800 Subject: librustc: Implement placement `box` for GC and unique pointers. --- src/libstd/gc.rs | 18 ++++++++++++++++++ src/libstd/owned.rs | 14 ++++++++++++++ src/libstd/prelude.rs | 4 ++++ 3 files changed, 36 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 1b53c70a9a1..4cbecc9b42f 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -21,6 +21,14 @@ use clone::{Clone, DeepClone}; use managed; /// Immutable garbage-collected pointer type +#[lang="gc"] +#[cfg(not(test))] +#[no_send] +pub struct Gc { + priv ptr: @T +} + +#[cfg(test)] #[no_send] pub struct Gc { priv ptr: @T @@ -54,6 +62,16 @@ impl Clone for Gc { } } +/// An value that represents the task-local managed heap. +/// +/// Use this like `let foo = box(GC) Bar::new(...);` +#[lang="managed_heap"] +#[cfg(not(test))] +pub static GC: () = (); + +#[cfg(test)] +pub static GC: () = (); + /// The `Send` bound restricts this to acyclic graphs where it is well-defined. /// /// A `Freeze` bound would also work, but `Send` *or* `Freeze` cannot be expressed. diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs index 424c4fd6b2f..dc8ea34c84b 100644 --- a/src/libstd/owned.rs +++ b/src/libstd/owned.rs @@ -12,6 +12,20 @@ #[cfg(not(test))] use cmp::*; +/// A value that represents the global exchange heap. This is the default +/// place that the `box` keyword allocates into when no place is supplied. +/// +/// The following two examples are equivalent: +/// +/// let foo = box(HEAP) Bar::new(...); +/// let foo = box Bar::new(...); +#[lang="exchange_heap"] +#[cfg(not(test))] +pub static HEAP: () = (); + +#[cfg(test)] +pub static HEAP: () = (); + #[cfg(not(test))] impl Eq for ~T { #[inline] diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index afacc4e8c17..36bcc81c06d 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -86,6 +86,10 @@ pub use vec::{Vector, VectorVector, CopyableVector, ImmutableVector}; pub use comm::{Port, Chan, SharedChan}; pub use task::spawn; +// Reexported statics +#[cfg(not(test))] +pub use gc::GC; + /// Disposes of a value. #[inline] pub fn drop(_x: T) { } -- cgit 1.4.1-3-g733a5