From 1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 27 Aug 2014 21:46:52 -0400 Subject: Implement generalized object and type parameter bounds (Fixes #16462) --- src/librustrt/exclusive.rs | 12 +++++++++++- src/librustrt/lib.rs | 3 ++- src/librustrt/local_data.rs | 10 ++++++++++ src/librustrt/rtio.rs | 4 ++-- src/librustrt/task.rs | 8 ++++---- 5 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src/librustrt') diff --git a/src/librustrt/exclusive.rs b/src/librustrt/exclusive.rs index 179d050f598..28514bec5b4 100644 --- a/src/librustrt/exclusive.rs +++ b/src/librustrt/exclusive.rs @@ -26,7 +26,8 @@ pub struct Exclusive { data: UnsafeCell, } -/// An RAII guard returned via `lock` +/// stage0 only +#[cfg(stage0)] pub struct ExclusiveGuard<'a, T> { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -34,6 +35,15 @@ pub struct ExclusiveGuard<'a, T> { _guard: mutex::LockGuard<'a>, } +/// An RAII guard returned via `lock` +#[cfg(not(stage0))] +pub struct ExclusiveGuard<'a, T:'a> { + // FIXME #12808: strange name to try to avoid interfering with + // field accesses of the contained type via Deref + _data: &'a mut T, + _guard: mutex::LockGuard<'a>, +} + impl Exclusive { /// Creates a new `Exclusive` which will protect the data provided. pub fn new(user_data: T) -> Exclusive { diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index 70ce85ee649..5ca46a728c3 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -19,6 +19,7 @@ #![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)] #![feature(linkage, lang_items, unsafe_destructor, default_type_params)] #![feature(import_shadowing)] +#![feature(issue_5723_bootstrap)] #![no_std] #![experimental] @@ -98,7 +99,7 @@ pub trait Runtime { fn can_block(&self) -> bool; // FIXME: This is a serious code smell and this should not exist at all. - fn wrap(self: Box) -> Box; + fn wrap(self: Box) -> Box; } /// The default error code of the rust runtime if the main task fails instead diff --git a/src/librustrt/local_data.rs b/src/librustrt/local_data.rs index 6a0b599179c..fedea3c31e0 100644 --- a/src/librustrt/local_data.rs +++ b/src/librustrt/local_data.rs @@ -144,6 +144,16 @@ unsafe fn get_local_map<'a>() -> Option<&'a mut Map> { /// /// The task-local data can be accessed through this value, and when this /// structure is dropped it will return the borrow on the data. +#[cfg(not(stage0))] +pub struct Ref { + // FIXME #12808: strange names to try to avoid interfering with + // field accesses of the contained type via Deref + _inner: &'static TLDValueBox, + _marker: marker::NoSend +} + +/// stage0 only +#[cfg(stage0)] pub struct Ref { // FIXME #12808: strange names to try to avoid interfering with // field accesses of the contained type via Deref diff --git a/src/librustrt/rtio.rs b/src/librustrt/rtio.rs index 261d544a241..1afd88edbc2 100644 --- a/src/librustrt/rtio.rs +++ b/src/librustrt/rtio.rs @@ -120,7 +120,7 @@ pub struct ProcessConfig<'a> { } pub struct LocalIo<'a> { - factory: &'a mut IoFactory, + factory: &'a mut IoFactory+'a, } #[unsafe_destructor] @@ -174,7 +174,7 @@ impl<'a> LocalIo<'a> { } } - pub fn new<'a>(io: &'a mut IoFactory) -> LocalIo<'a> { + pub fn new<'a>(io: &'a mut IoFactory+'a) -> LocalIo<'a> { LocalIo { factory: io } } diff --git a/src/librustrt/task.rs b/src/librustrt/task.rs index acd53535e3b..e39071864a7 100644 --- a/src/librustrt/task.rs +++ b/src/librustrt/task.rs @@ -103,7 +103,7 @@ pub struct Task { pub name: Option, state: TaskState, - imp: Option>, + imp: Option>, } // Once a task has entered the `Armed` state it must be destroyed via `drop`, @@ -353,14 +353,14 @@ impl Task { /// Inserts a runtime object into this task, transferring ownership to the /// task. It is illegal to replace a previous runtime object in this task /// with this argument. - pub fn put_runtime(&mut self, ops: Box) { + pub fn put_runtime(&mut self, ops: Box) { assert!(self.imp.is_none()); self.imp = Some(ops); } /// Removes the runtime from this task, transferring ownership to the /// caller. - pub fn take_runtime(&mut self) -> Box { + pub fn take_runtime(&mut self) -> Box { assert!(self.imp.is_some()); self.imp.take().unwrap() } @@ -390,7 +390,7 @@ impl Task { Ok(t) => Some(t), Err(t) => { let data = mem::transmute::<_, raw::TraitObject>(t).data; - let obj: Box = + let obj: Box = mem::transmute(raw::TraitObject { vtable: vtable, data: data, -- cgit 1.4.1-3-g733a5