Implement generalized object and type parameter bounds (Fixes #16462)

This commit is contained in:
Niko Matsakis 2014-08-27 21:46:52 -04:00
parent 3ee047ae1f
commit 1b487a8906
272 changed files with 6783 additions and 3154 deletions

View file

@ -26,7 +26,8 @@ pub struct Exclusive<T> {
data: UnsafeCell<T>,
}
/// 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<T: Send> Exclusive<T> {
/// Creates a new `Exclusive` which will protect the data provided.
pub fn new(user_data: T) -> Exclusive<T> {

View file

@ -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<Self>) -> Box<Any>;
fn wrap(self: Box<Self>) -> Box<Any+'static>;
}
/// The default error code of the rust runtime if the main task fails instead

View file

@ -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<T:'static> {
// FIXME #12808: strange names to try to avoid interfering with
// field accesses of the contained type via Deref
_inner: &'static TLDValueBox<T>,
_marker: marker::NoSend
}
/// stage0 only
#[cfg(stage0)]
pub struct Ref<T> {
// FIXME #12808: strange names to try to avoid interfering with
// field accesses of the contained type via Deref

View file

@ -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 }
}

View file

@ -103,7 +103,7 @@ pub struct Task {
pub name: Option<SendStr>,
state: TaskState,
imp: Option<Box<Runtime + Send>>,
imp: Option<Box<Runtime + Send + 'static>>,
}
// 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<Runtime + Send>) {
pub fn put_runtime(&mut self, ops: Box<Runtime + Send + 'static>) {
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<Runtime + Send> {
pub fn take_runtime(&mut self) -> Box<Runtime + Send + 'static> {
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<Runtime + Send> =
let obj: Box<Runtime + Send + 'static> =
mem::transmute(raw::TraitObject {
vtable: vtable,
data: data,