librustc: Disallow trait bounds in types, enumerations, and structure definitions. r=tjc

This commit is contained in:
Patrick Walton 2013-01-28 10:46:43 -08:00
parent eb4d39e1fe
commit 6ce74460e6
44 changed files with 424 additions and 107 deletions

View File

@ -35,13 +35,13 @@ pub mod linear {
const INITIAL_CAPACITY: uint = 32u; // 2^5
struct Bucket<K: Eq Hash, V> {
struct Bucket<K,V> {
hash: uint,
key: K,
value: V,
}
pub struct LinearMap<K: Eq Hash, V> {
pub struct LinearMap<K,V> {
k0: u64,
k1: u64,
resize_at: uint,
@ -408,7 +408,7 @@ pub mod linear {
pure fn ne(&self, other: &LinearMap<K, V>) -> bool { !self.eq(other) }
}
pub struct LinearSet<T: Hash IterBytes Eq> {
pub struct LinearSet<T> {
priv map: LinearMap<T, ()>
}

View File

@ -1111,7 +1111,7 @@ pub mod fsync {
// Artifacts that need to fsync on destruction
pub struct Res<t: Copy> {
pub struct Res<t> {
arg: Arg<t>,
}

View File

@ -68,7 +68,7 @@ use vec;
* 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: Owned> {
pub enum Port<T> {
Port_(@PortPtr<T>)
}
@ -84,7 +84,7 @@ pub enum Port<T: Owned> {
* data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels.
*/
pub enum Chan<T: Owned> {
pub enum Chan<T> {
Chan_(port_id)
}
@ -120,7 +120,7 @@ pub fn listen<T: Owned, U>(f: fn(Chan<T>) -> U) -> U {
f(po.chan())
}
struct PortPtr<T:Owned> {
struct PortPtr<T> {
po: *rust_port,
drop {
unsafe {
@ -238,7 +238,7 @@ fn peek_chan<T: Owned>(ch: Chan<T>) -> bool {
}
/// Receive on a raw port pointer
fn recv_<T: Owned>(p: *rust_port) -> T {
fn recv_<T>(p: *rust_port) -> T {
unsafe {
let yield = 0;
let yieldp = ptr::addr_of(&yield);

View File

@ -151,7 +151,7 @@ type Buffer<T: Owned> = {
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub struct Buffer<T: Owned> {
pub struct Buffer<T> {
header: BufferHeader,
data: T,
}
@ -212,10 +212,18 @@ impl PacketHeader {
}
#[doc(hidden)]
#[cfg(stage0)]
pub struct Packet<T: Owned> {
header: PacketHeader,
mut payload: Option<T>,
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub struct Packet<T> {
header: PacketHeader,
mut payload: Option<T>,
}
#[doc(hidden)]
pub trait HasBuffer {
@ -256,12 +264,11 @@ fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
}
move b
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
fn unibuffer<T>() -> ~Buffer<Packet<T>> {
let b = ~Buffer {
header: BufferHeader(),
data: Packet {
@ -277,6 +284,7 @@ fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn packet<T: Owned>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(&(b.data));
@ -284,6 +292,16 @@ pub fn packet<T: Owned>() -> *Packet<T> {
unsafe { forget(move b) }
p
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn packet<T>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(&(b.data));
// We'll take over memory management from here.
unsafe { forget(move b) }
p
}
#[doc(hidden)]
pub fn entangle_buffer<T: Owned, Tstart: Owned>(
@ -387,11 +405,19 @@ fn swap_state_rel(dst: &mut State, src: State) -> State {
}
#[doc(hidden)]
#[cfg(stage0)]
pub unsafe fn get_buffer<T: Owned>(p: *PacketHeader) -> ~Buffer<T> {
transmute((*p).buf_header())
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> {
transmute((*p).buf_header())
}
// This could probably be done with SharedMutableState to avoid move_it!().
#[cfg(stage0)]
struct BufferResource<T: Owned> {
buffer: ~Buffer<T>,
@ -413,7 +439,31 @@ struct BufferResource<T: Owned> {
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
struct BufferResource<T> {
buffer: ~Buffer<T>,
drop {
unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
//error!("drop %?", p);
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
if old_count == 1 {
// The new count is 0.
// go go gadget drop glue
}
else {
forget(move b)
}
}
}
}
#[cfg(stage0)]
fn BufferResource<T: Owned>(b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//error!("take %?", p);
@ -424,8 +474,21 @@ fn BufferResource<T: Owned>(b: ~Buffer<T>) -> BufferResource<T> {
buffer: move b
}
}
#[cfg(stage1)]
#[cfg(stage2)]
fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//error!("take %?", p);
atomic_add_acq(&mut b.header.ref_count, 1);
BufferResource {
// tjc: ????
buffer: move b
}
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn send<T: Owned, Tbuffer: Owned>(p: SendPacketBuffered<T, Tbuffer>,
payload: T) -> bool {
let header = p.header();
@ -467,6 +530,49 @@ pub fn send<T: Owned, Tbuffer: Owned>(p: SendPacketBuffered<T, Tbuffer>,
}
}
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
let header = p.header();
let p_ = p.unwrap();
let p = unsafe { &*p_ };
assert ptr::addr_of(&(p.header)) == header;
assert p.payload.is_none();
p.payload = move Some(move payload);
let old_state = swap_state_rel(&mut p.header.state, Full);
match old_state {
Empty => {
// Yay, fastpath.
// The receiver will eventually clean this up.
//unsafe { forget(p); }
return true;
}
Full => fail ~"duplicate send",
Blocked => {
debug!("waking up task for %?", p_);
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
if !old_task.is_null() {
unsafe {
rustrt::task_signal_event(
old_task,
ptr::addr_of(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task);
}
}
// The receiver will eventually clean this up.
//unsafe { forget(p); }
return true;
}
Terminated => {
// The receiver will never receive this. Rely on drop_glue
// to clean everything up.
return false;
}
}
}
/** Receives a message from a pipe.
@ -812,13 +918,24 @@ pub fn select<T: Owned, Tb: Owned>(endpoints: ~[RecvPacketBuffered<T, Tb>])
message.
*/
#[cfg(stage0)]
pub type SendPacket<T: Owned> = SendPacketBuffered<T, Packet<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type SendPacket<T> = SendPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
#[cfg(stage0)]
pub fn SendPacket<T: Owned>(p: *Packet<T>) -> SendPacket<T> {
SendPacketBuffered(p)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn SendPacket<T>(p: *Packet<T>) -> SendPacket<T> {
SendPacketBuffered(p)
}
#[cfg(stage0)]
pub struct SendPacketBuffered<T: Owned, Tbuffer: Owned> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
@ -837,7 +954,31 @@ pub struct SendPacketBuffered<T: Owned, Tbuffer: Owned> {
// } else { "some" }); }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct SendPacketBuffered<T, Tbuffer> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
}
impl<T:Owned,Tbuffer:Owned> SendPacketBuffered<T,Tbuffer> : ::ops::Drop {
fn finalize(&self) {
//if self.p != none {
// debug!("drop send %?", option::get(self.p));
//}
if self.p != None {
let mut p = None;
p <-> self.p;
sender_terminate(option::unwrap(move p))
}
//unsafe { error!("send_drop: %?",
// if self.buffer == none {
// "none"
// } else { "some" }); }
}
}
#[cfg(stage0)]
pub fn SendPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
@ -849,8 +990,50 @@ pub fn SendPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
SendPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
}
}
}
impl<T: Owned, Tbuffer: Owned> SendPacketBuffered<T, Tbuffer> {
#[cfg(stage0)]
impl<T:Owned,Tbuffer:Owned> SendPacketBuffered<T,Tbuffer> {
fn unwrap() -> *Packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(move p)
}
pure fn header() -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(&(packet.header));
//forget(packet);
header
},
None => fail ~"packet already consumed"
}
}
fn reuse_buffer() -> BufferResource<Tbuffer> {
//error!("send reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
option::unwrap(move tmp)
}
}
#[cfg(stage1)]
#[cfg(stage2)]
impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
fn unwrap() -> *Packet<T> {
let mut p = None;
p <-> self.p;
@ -879,13 +1062,25 @@ impl<T: Owned, Tbuffer: Owned> SendPacketBuffered<T, Tbuffer> {
/// Represents the receive end of a pipe. It can receive exactly one
/// message.
#[cfg(stage0)]
pub type RecvPacket<T: Owned> = RecvPacketBuffered<T, Packet<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type RecvPacket<T> = RecvPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
#[cfg(stage0)]
pub fn RecvPacket<T: Owned>(p: *Packet<T>) -> RecvPacket<T> {
RecvPacketBuffered(p)
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn RecvPacket<T>(p: *Packet<T>) -> RecvPacket<T> {
RecvPacketBuffered(p)
}
#[cfg(stage0)]
pub struct RecvPacketBuffered<T: Owned, Tbuffer: Owned> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
@ -904,6 +1099,29 @@ pub struct RecvPacketBuffered<T: Owned, Tbuffer: Owned> {
// } else { "some" }); }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct RecvPacketBuffered<T, Tbuffer> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
}
impl<T:Owned, Tbuffer:Owned> RecvPacketBuffered<T,Tbuffer> : ::ops::Drop {
fn finalize(&self) {
//if self.p != none {
// debug!("drop recv %?", option::get(self.p));
//}
if self.p != None {
let mut p = None;
p <-> self.p;
receiver_terminate(option::unwrap(move p))
}
//unsafe { error!("recv_drop: %?",
// if self.buffer == none {
// "none"
// } else { "some" }); }
}
}
impl<T: Owned, Tbuffer: Owned> RecvPacketBuffered<T, Tbuffer> {
fn unwrap() -> *Packet<T> {
@ -934,6 +1152,7 @@ impl<T: Owned, Tbuffer: Owned> RecvPacketBuffered<T, Tbuffer> : Selectable {
}
}
#[cfg(stage0)]
pub fn RecvPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
-> RecvPacketBuffered<T, Tbuffer> {
//debug!("take recv %?", p);
@ -945,12 +1164,33 @@ pub fn RecvPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn RecvPacketBuffered<T,Tbuffer>(p: *Packet<T>)
-> RecvPacketBuffered<T,Tbuffer> {
//debug!("take recv %?", p);
RecvPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
}
}
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn entangle<T: Owned>() -> (SendPacket<T>, RecvPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn entangle<T>() -> (SendPacket<T>, RecvPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
}
/** Spawn a task to provide a service.
@ -1042,24 +1282,50 @@ pub trait Peekable<T> {
}
#[doc(hidden)]
#[cfg(stage0)]
struct Chan_<T:Owned> {
mut endp: Option<streamp::client::Open<T>>,
mut endp: Option<streamp::client::Open<T>>
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
struct Chan_<T> {
mut endp: Option<streamp::client::Open<T>>
}
/// An endpoint that can send many messages.
#[cfg(stage0)]
pub enum Chan<T:Owned> {
Chan_(Chan_<T>)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub enum Chan<T> {
Chan_(Chan_<T>)
}
#[doc(hidden)]
#[cfg(stage0)]
struct Port_<T:Owned> {
mut endp: Option<streamp::server::Open<T>>,
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
struct Port_<T> {
mut endp: Option<streamp::server::Open<T>>,
}
/// An endpoint that can receive many messages.
#[cfg(stage0)]
pub enum Port<T:Owned> {
Port_(Port_<T>)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub enum Port<T> {
Port_(Port_<T>)
}
/** Creates a `(chan, port)` pair.
@ -1145,9 +1411,15 @@ impl<T: Owned> Port<T>: Selectable {
}
/// Treat many ports as one.
#[cfg(stage0)]
pub struct PortSet<T: Owned> {
mut ports: ~[pipes::Port<T>],
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct PortSet<T> {
mut ports: ~[pipes::Port<T>],
}
pub fn PortSet<T: Owned>() -> PortSet<T>{
PortSet {
@ -1210,7 +1482,11 @@ impl<T: Owned> PortSet<T> : Peekable<T> {
}
/// A channel that can be shared between many senders.
#[cfg(stage0)]
pub type SharedChan<T: Owned> = private::Exclusive<Chan<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type SharedChan<T> = private::Exclusive<Chan<T>>;
impl<T: Owned> SharedChan<T>: GenericChan<T> {
fn send(x: T) {
@ -1278,9 +1554,17 @@ proto! oneshot (
)
/// The send end of a oneshot pipe.
#[cfg(stage0)]
pub type ChanOne<T: Owned> = oneshot::client::Oneshot<T>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type ChanOne<T> = oneshot::client::Oneshot<T>;
/// The receive end of a oneshot pipe.
#[cfg(stage0)]
pub type PortOne<T: Owned> = oneshot::server::Oneshot<T>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type PortOne<T> = oneshot::server::Oneshot<T>;
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {

View File

@ -238,7 +238,7 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
* Data races between tasks can result in crashes and, with sufficient
* cleverness, arbitrary type coercion.
*/
pub type SharedMutableState<T: Owned> = ArcDestruct<T>;
pub type SharedMutableState<T> = ArcDestruct<T>;
pub unsafe fn shared_mutable_state<T: Owned>(data: T) ->
SharedMutableState<T> {
@ -341,11 +341,11 @@ impl LittleLock {
}
}
struct ExData<T: Owned> { lock: LittleLock, mut failed: bool, mut data: T, }
struct ExData<T> { lock: LittleLock, mut failed: bool, mut data: T, }
/**
* An arc over mutable data that is protected by a lock. For library use only.
*/
pub struct Exclusive<T: Owned> { x: SharedMutableState<ExData<T>> }
pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
pub fn exclusive<T:Owned >(user_data: T) -> Exclusive<T> {
let data = ExData {

View File

@ -41,7 +41,7 @@ use sys::Closure;
use task::spawn;
use uint;
pub type GlobalDataKey<T: Owned> = &fn(v: T);
pub type GlobalDataKey<T> = &fn(v: T);
pub unsafe fn global_data_clone_create<T: Owned Clone>(
key: GlobalDataKey<T>, create: &fn() -> ~T) -> T {

View File

@ -41,7 +41,7 @@ pub fn align(size: uint, align: uint) -> uint {
}
/// Adaptor to wrap around visitors implementing MovePtr.
pub struct MovePtrAdaptor<V: TyVisitor MovePtr> {
pub struct MovePtrAdaptor<V> {
inner: V
}
pub fn MovePtrAdaptor<V: TyVisitor MovePtr>(v: V) -> MovePtrAdaptor<V> {

View File

@ -45,7 +45,7 @@ use task;
*
* These two cases aside, the interface is safe.
*/
pub type LocalDataKey<T: Durable> = &fn(v: @T);
pub type LocalDataKey<T> = &fn(v: @T);
/**
* Remove a task-local data value from the table, returning the

View File

@ -77,7 +77,7 @@ use cast;
use container::Map;
use oldcomm;
use option;
use pipes::{Chan, GenericChan, GenericPort, Port};
use pipes::{Chan, GenericChan, GenericPort, Port, stream};
use pipes;
use prelude::*;
use private;

View File

@ -569,7 +569,7 @@ struct FnSig {
* by the meta information because, in some cases, the
* meta information is inferred. */
#[deriving_eq]
struct FnTyBase<M: cmp::Eq> {
struct FnTyBase<M> {
meta: M, // Either FnMeta or FnVid
sig: FnSig // Types of arguments/return type
}

View File

@ -598,6 +598,20 @@ fn convert_methods(ccx: @crate_ctxt,
}
}
fn ensure_no_ty_param_bounds(ccx: @crate_ctxt,
span: span,
ty_params: &[ast::ty_param],
thing: &static/str) {
for ty_params.each |ty_param| {
if ty_param.bounds.len() > 0 {
ccx.tcx.sess.span_err(
span,
fmt!("trait bounds are not allowed in %s definitions",
thing));
}
}
}
fn convert(ccx: @crate_ctxt, it: @ast::item) {
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.find(it.id);
@ -607,6 +621,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
// These don't define types.
ast::item_foreign_mod(_) | ast::item_mod(_) => {}
ast::item_enum(ref enum_definition, ref ty_params) => {
ensure_no_ty_param_bounds(ccx, it.span, *ty_params, "enumeration");
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
get_enum_variant_types(ccx,
@ -644,6 +659,8 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
let _ = convert_methods(ccx, provided_methods, rp, bounds);
}
ast::item_struct(struct_def, tps) => {
ensure_no_ty_param_bounds(ccx, it.span, tps, "structure");
// Write the class type
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
@ -651,6 +668,11 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
convert_struct(ccx, rp, struct_def, tps, tpt, it.id);
}
ast::item_ty(_, ref ty_params) => {
ensure_no_ty_param_bounds(ccx, it.span, *ty_params, "type");
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
}
_ => {
// This call populates the type cache with the converted type
// of the item in passing. All we have to do here is to write

View File

@ -31,7 +31,7 @@ struct ValsAndBindings<V, T> {
mut bindings: ~[(V, VarValue<V, T>)],
}
struct Node<V:Copy, T:Copy> {
struct Node<V, T> {
root: V,
possible_types: T,
rank: uint,

View File

@ -79,7 +79,7 @@ impl &Condvar {
****************************************************************************/
/// An atomically reference counted wrapper for shared immutable state.
struct ARC<T: Const Owned> { x: SharedMutableState<T> }
struct ARC<T> { x: SharedMutableState<T> }
/// Create an atomically reference counted wrapper.
pub fn ARC<T: Const Owned>(data: T) -> ARC<T> {
@ -130,9 +130,9 @@ impl<T: Const Owned> ARC<T>: Clone {
****************************************************************************/
#[doc(hidden)]
struct MutexARCInner<T: Owned> { lock: Mutex, failed: bool, data: T }
struct MutexARCInner<T> { lock: Mutex, failed: bool, data: T }
/// An ARC with mutable data protected by a blocking mutex.
struct MutexARC<T: Owned> { x: SharedMutableState<MutexARCInner<T>> }
struct MutexARC<T> { x: SharedMutableState<MutexARCInner<T>> }
/// Create a mutex-protected ARC with the supplied data.
pub fn MutexARC<T: Owned>(user_data: T) -> MutexARC<T> {
@ -267,14 +267,14 @@ fn PoisonOnFail(failed: &r/mut bool) -> PoisonOnFail {
****************************************************************************/
#[doc(hidden)]
struct RWARCInner<T: Const Owned> { lock: RWlock, failed: bool, data: T }
struct RWARCInner<T> { lock: RWlock, failed: bool, data: T }
/**
* 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.
*
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
*/
struct RWARC<T: Const Owned> {
struct RWARC<T> {
x: SharedMutableState<RWARCInner<T>>,
mut cant_nest: ()
}
@ -426,10 +426,10 @@ fn borrow_rwlock<T: Const Owned>(state: &r/mut RWARCInner<T>) -> &r/RWlock {
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
/// The "write permission" token used for RWARC.write_downgrade().
pub enum RWWriteMode<T: Const Owned> =
pub enum RWWriteMode<T> =
(&mut T, sync::RWlockWriteMode, PoisonOnFail);
/// The "read permission" token used for RWARC.write_downgrade().
pub enum RWReadMode<T:Const Owned> = (&T, sync::RWlockReadMode);
pub enum RWReadMode<T> = (&T, sync::RWlockReadMode);
impl<T: Const Owned> &RWWriteMode<T> {
/// Access the pre-downgrade RWARC in write mode.

View File

@ -23,7 +23,14 @@ use core::pipes;
use core::prelude::*;
/// An extension of `pipes::stream` that allows both sending and receiving.
pub struct DuplexStream<T: Owned, U: Owned> {
#[cfg(stage0)]
pub struct DuplexStream<T:Owned, U:Owned> {
priv chan: Chan<T>,
priv port: Port<U>,
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct DuplexStream<T, U> {
priv chan: Chan<T>,
priv port: Port<U>,
}

View File

@ -63,7 +63,7 @@ and an `Unflattener` that converts the bytes to a value.
Create using the constructors in the `serial` and `pod` modules.
*/
pub struct FlatPort<T, U: Unflattener<T>, P: BytePort> {
pub struct FlatPort<T, U, P> {
unflattener: U,
byte_port: P
}
@ -74,7 +74,7 @@ byte vectors, and a `ByteChan` that transmits the bytes.
Create using the constructors in the `serial` and `pod` modules.
*/
pub struct FlatChan<T, F: Flattener<T>, C: ByteChan> {
pub struct FlatChan<T, F, C> {
flattener: F,
byte_chan: C
}
@ -181,14 +181,12 @@ pub mod pod {
use core::pipes;
use core::prelude::*;
pub type ReaderPort<T: Copy Owned, R> =
pub type ReaderPort<T, R> =
FlatPort<T, PodUnflattener<T>, ReaderBytePort<R>>;
pub type WriterChan<T: Copy Owned, W> =
pub type WriterChan<T, W> =
FlatChan<T, PodFlattener<T>, WriterByteChan<W>>;
pub type PipePort<T: Copy Owned> =
FlatPort<T, PodUnflattener<T>, PipeBytePort>;
pub type PipeChan<T: Copy Owned> =
FlatChan<T, PodFlattener<T>, PipeByteChan>;
pub type PipePort<T> = FlatPort<T, PodUnflattener<T>, PipeBytePort>;
pub type PipeChan<T> = FlatChan<T, PodFlattener<T>, PipeByteChan>;
/// Create a `FlatPort` from a `Reader`
pub fn reader_port<T: Copy Owned, R: Reader>(
@ -352,11 +350,11 @@ pub mod flatteners {
// FIXME #4074: Copy + Owned != POD
pub struct PodUnflattener<T: Copy Owned> {
pub struct PodUnflattener<T> {
bogus: ()
}
pub struct PodFlattener<T: Copy Owned> {
pub struct PodFlattener<T> {
bogus: ()
}
@ -398,14 +396,13 @@ pub mod flatteners {
pub type DeserializeBuffer<T> = ~fn(buf: &[u8]) -> T;
pub struct DeserializingUnflattener<D: Decoder,
T: Decodable<D>> {
pub struct DeserializingUnflattener<D, T> {
deserialize_buffer: DeserializeBuffer<T>
}
pub type SerializeValue<T> = ~fn(val: &T) -> ~[u8];
pub struct SerializingFlattener<S: Encoder, T: Encodable<S>> {
pub struct SerializingFlattener<S, T> {
serialize_value: SerializeValue<T>
}
@ -518,11 +515,11 @@ pub mod bytepipes {
use core::pipes;
use core::prelude::*;
pub struct ReaderBytePort<R: Reader> {
pub struct ReaderBytePort<R> {
reader: R
}
pub struct WriterByteChan<W: Writer> {
pub struct WriterByteChan<W> {
writer: W
}
@ -767,9 +764,9 @@ mod test {
test_some_tcp_stream(reader_port, writer_chan, 9667);
}
type ReaderPortFactory<U: Unflattener<int>> =
type ReaderPortFactory<U> =
~fn(TcpSocketBuf) -> FlatPort<int, U, ReaderBytePort<TcpSocketBuf>>;
type WriterChanFactory<F: Flattener<int>> =
type WriterChanFactory<F> =
~fn(TcpSocketBuf) -> FlatChan<int, F, WriterByteChan<TcpSocketBuf>>;
fn test_some_tcp_stream<U: Unflattener<int>, F: Flattener<int>>(
@ -893,7 +890,7 @@ mod test {
use core::sys;
use core::task;
type PortLoader<P: BytePort> =
type PortLoader<P> =
~fn(~[u8]) -> FlatPort<int, PodUnflattener<int>, P>;
fn reader_port_loader(bytes: ~[u8]

View File

@ -24,9 +24,9 @@ use core::uint;
use core::vec;
/// A convenience type to treat a hashmap as a set
pub type Set<K:Eq IterBytes Hash> = HashMap<K, ()>;
pub type Set<K> = HashMap<K, ()>;
pub type HashMap<K:Eq IterBytes Hash, V> = chained::T<K, V>;
pub type HashMap<K, V> = chained::T<K, V>;
pub trait StdMap<K:Eq IterBytes Hash Copy, V: Copy> {
/// Return the number of elements in the map
@ -142,12 +142,12 @@ pub mod chained {
mut next: Option<@Entry<K, V>>
}
struct HashMap_<K:Eq IterBytes Hash, V> {
struct HashMap_<K, V> {
mut count: uint,
mut chains: ~[mut Option<@Entry<K,V>>]
}
pub type T<K:Eq IterBytes Hash, V> = @HashMap_<K, V>;
pub type T<K, V> = @HashMap_<K, V>;
enum SearchResult<K, V> {
NotFound,

View File

@ -22,7 +22,7 @@ extern "C" mod rusti {
fn init<T>() -> T;
}
pub struct PriorityQueue <T: Ord>{
pub struct PriorityQueue<T> {
priv data: ~[T],
}

View File

@ -83,7 +83,7 @@ struct SemInner<Q> {
blocked: Q
}
#[doc(hidden)]
enum Sem<Q: Owned> = Exclusive<SemInner<Q>>;
enum Sem<Q> = Exclusive<SemInner<Q>>;
#[doc(hidden)]
fn new_sem<Q: Owned>(count: int, q: Q) -> Sem<Q> {
@ -167,7 +167,7 @@ impl &Sem<~[mut Waitqueue]> {
#[doc(hidden)]
type SemRelease = SemReleaseGeneric<()>;
type SemAndSignalRelease = SemReleaseGeneric<~[mut Waitqueue]>;
struct SemReleaseGeneric<Q: Owned> { sem: &Sem<Q> }
struct SemReleaseGeneric<Q> { sem: &Sem<Q> }
impl<Q: Owned> SemReleaseGeneric<Q> : Drop {
fn finalize(&self) {

View File

@ -35,7 +35,7 @@ use core::prelude::*;
// * symmetric difference: ^
// These would be convenient since the methods work like `each`
pub struct TreeMap<K: Ord, V> {
pub struct TreeMap<K, V> {
priv root: Option<~TreeNode<K, V>>,
priv length: uint
}
@ -202,7 +202,7 @@ impl <K: Ord, V> TreeMap<K, V> {
}
/// Lazy forward iterator over a map
pub struct TreeMapIterator<K: Ord, V> {
pub struct TreeMapIterator<K, V> {
priv stack: ~[&~TreeNode<K, V>],
priv node: &Option<~TreeNode<K, V>>,
priv current: Option<&~TreeNode<K, V>>
@ -240,7 +240,7 @@ impl <K: Ord, V> TreeMapIterator<K, V> {
}
}
pub struct TreeSet<T: Ord> {
pub struct TreeSet<T> {
priv map: TreeMap<T, ()>
}
@ -518,7 +518,7 @@ impl <T: Ord> TreeSet<T> {
}
/// Lazy forward iterator over a set
pub struct TreeSetIterator<T: Ord> {
pub struct TreeSetIterator<T> {
priv iter: TreeMapIterator<T, ()>
}
@ -540,7 +540,7 @@ impl <T: Ord> TreeSetIterator<T> {
// Nodes keep track of their level in the tree, starting at 1 in the
// leaves and with a red child sharing the level of the parent.
struct TreeNode<K: Ord, V> {
struct TreeNode<K, V> {
key: K,
value: V,
left: Option<~TreeNode<K, V>>,

View File

@ -235,10 +235,17 @@ struct Exec {
discovered_outputs: WorkMap
}
#[cfg(stage0)]
struct Work<T:Owned> {
prep: @Mut<Prep>,
res: Option<Either<T,PortOne<(Exec,T)>>>
}
#[cfg(stage1)]
#[cfg(stage2)]
struct Work<T> {
prep: @Mut<Prep>,
res: Option<Either<T,PortOne<(Exec,T)>>>
}
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
do io::with_str_writer |wr| {

View File

@ -110,6 +110,7 @@ pub trait ext_ctxt_ast_builder {
fn ty_option(ty: @ast::Ty) -> @ast::Ty;
fn ty_infer() -> @ast::Ty;
fn ty_nil_ast_builder() -> @ast::Ty;
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param];
}
impl ext_ctxt: ext_ctxt_ast_builder {
@ -370,6 +371,12 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}
}
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
do bounds.map |ty_param| {
ast::ty_param { bounds: @~[], ..copy *ty_param }
}
}
fn item_ty_poly(name: ident,
span: span,
ty: @ast::Ty,

View File

@ -248,7 +248,7 @@ impl state: to_type_decls {
ast::enum_def(enum_def_ {
variants: items_msg,
common: None }),
self.ty_params
cx.strip_bounds(self.ty_params)
)
]
}
@ -281,7 +281,7 @@ impl state: to_type_decls {
self.data_name()],
dummy_sp())
.add_tys(cx.ty_vars_global(self.ty_params))))),
self.ty_params));
cx.strip_bounds(self.ty_params)));
}
else {
items.push(
@ -299,7 +299,7 @@ impl state: to_type_decls {
dummy_sp())
.add_tys(cx.ty_vars_global(self.ty_params))),
self.proto.buffer_ty_path(cx)])),
self.ty_params));
cx.strip_bounds(self.ty_params)));
};
items
}
@ -417,7 +417,7 @@ impl protocol: gen_init {
cx.ident_of(~"__Buffer"),
dummy_sp(),
cx.ty_rec(fields),
params)
cx.strip_bounds(params))
}
fn compile(cx: ext_ctxt) -> @ast::item {

View File

@ -33,6 +33,7 @@ use core::str;
use core::to_bytes;
/// The specific types of unsupported syntax
#[deriving_eq]
pub enum ObsoleteSyntax {
ObsoleteLowerCaseKindBounds,
ObsoleteLet,
@ -45,16 +46,8 @@ pub enum ObsoleteSyntax {
ObsoleteModeInFnType,
ObsoleteMoveInit,
ObsoleteBinaryMove,
ObsoleteUnsafeBlock
}
impl ObsoleteSyntax : cmp::Eq {
pure fn eq(&self, other: &ObsoleteSyntax) -> bool {
(*self) as uint == (*other) as uint
}
pure fn ne(&self, other: &ObsoleteSyntax) -> bool {
!(*self).eq(other)
}
ObsoleteUnsafeBlock,
ObsoleteUnenforcedBound
}
impl ObsoleteSyntax: to_bytes::IterBytes {
@ -123,6 +116,11 @@ impl Parser {
ObsoleteUnsafeBlock => (
"non-standalone unsafe block",
"use an inner `unsafe { ... }` block instead"
),
ObsoleteUnenforcedBound => (
"unenforced type parameter bound",
"use trait bounds on the functions that take the type as \
arguments, not on the types themselves"
)
};

View File

@ -18,7 +18,7 @@ use core::dvec::DVec;
use std::map::HashMap;
use std::map;
type hash_interner<T: Const> =
type hash_interner<T> =
{map: HashMap<T, uint>,
vect: DVec<T>};

View File

@ -17,7 +17,7 @@ extern mod std;
export context;
struct arc_destruct<T:Const> {
struct arc_destruct<T> {
_data: int,
}

View File

@ -24,7 +24,7 @@ use core::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: Owned> {
pub enum port<T> {
port_t(@port_ptr<T>)
}
@ -35,7 +35,7 @@ pub fn port<T: Owned>() -> port<T> {
}
}
struct port_ptr<T:Owned> {
struct port_ptr<T> {
po: *rust_port,
}

View File

@ -122,15 +122,15 @@ mod map_reduce {
use std::map::HashMap;
use std::map;
pub type putter<K: Owned, V: Owned> = fn(&K, V);
pub type putter<K, V> = fn(&K, V);
pub type mapper<K1: Owned, K2: Owned, V: Owned> = fn~(K1, putter<K2, V>);
pub type mapper<K1, K2, V> = fn~(K1, putter<K2, V>);
pub type getter<V: Owned> = fn() -> Option<V>;
pub type getter<V> = fn() -> Option<V>;
pub type reducer<K: Copy Owned, V: Copy Owned> = fn~(&K, getter<V>);
pub type reducer<K, V> = fn~(&K, getter<V>);
enum ctrl_proto<K: Copy Owned, V: Copy Owned> {
enum ctrl_proto<K, V> {
find_reducer(K, Chan<Chan<::map_reduce::reduce_proto<V>>>),
mapper_done
}
@ -148,7 +148,7 @@ mod map_reduce {
}
)
pub enum reduce_proto<V: Copy Owned> {
pub enum reduce_proto<V> {
emit_val(V),
done,
addref,

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub struct send_packet<T: Copy> {
pub struct send_packet<T> {
p: T
}

View File

@ -14,7 +14,7 @@ fn test00_start(ch: chan_t<int>, message: int) { send(ch, message); }
type task_id = int;
type port_id = int;
enum chan_t<T: Owned> = {task: task_id, port: port_id};
enum chan_t<T> = {task: task_id, port: port_id};
fn send<T: Owned>(ch: chan_t<T>, data: T) { fail; }

View File

@ -13,7 +13,7 @@
extern mod std;
use std::arc;
enum e<T: Const Owned> { e(arc::ARC<T>) }
enum e<T> { e(arc::ARC<T>) }
fn foo() -> e<int> {fail;}

View File

@ -135,11 +135,6 @@ struct Spanned<T> {
node: T,
}
enum AnEnum {
AVariant,
AnotherVariant
}
#[auto_encode]
#[auto_decode]
struct SomeStruct { v: ~[uint] }

View File

@ -10,7 +10,7 @@
struct Box<T: Copy> {c: @T}
struct Box<T> {c: @T}
fn unbox<T: Copy>(b: Box<T>) -> T { return *b.c; }

View File

@ -27,7 +27,7 @@ impl cat_type : cmp::Eq {
// for any int value that's less than the meows field
// ok: T should be in scope when resolving the trait ref for map
struct cat<T: Copy> {
struct cat<T> {
// Yes, you can have negative meows
priv mut meows : int,

View File

@ -10,7 +10,7 @@
struct Recbox<T: Copy> {x: @T}
struct Recbox<T> {x: @T}
fn reclift<T: Copy>(t: T) -> Recbox<T> { return Recbox {x: @t}; }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Recbox<T: Copy> {x: ~T}
struct Recbox<T> {x: ~T}
fn reclift<T: Copy>(t: T) -> Recbox<T> { return Recbox {x: ~t}; }

View File

@ -11,7 +11,7 @@
trait clam<A: Copy> {
fn chowder(y: A);
}
struct foo<A: Copy> {
struct foo<A> {
x: A,
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
trait clam<A: Copy> { }
struct foo<A: Copy> {
struct foo<A> {
x: A,
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct c1<T: Copy> {
struct c1<T> {
x: T,
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct c1<T: Copy> {
struct c1<T> {
x: T,
}

View File

@ -34,7 +34,7 @@ pub mod pipes {
pure fn ne(&self, other: &state) -> bool { !(*self).eq(other) }
}
pub type packet<T: Owned> = {
pub type packet<T> = {
mut state: state,
mut blocked_task: Option<task::Task>,
mut payload: Option<T>
@ -157,7 +157,7 @@ pub mod pipes {
}
}
pub struct send_packet<T: Owned> {
pub struct send_packet<T> {
mut p: Option<*packet<T>>,
}
@ -185,7 +185,7 @@ pub mod pipes {
}
}
pub struct recv_packet<T: Owned> {
pub struct recv_packet<T> {
mut p: Option<*packet<T>>,
}

View File

@ -22,7 +22,7 @@ pure fn Matrix4<T:Copy Num>(m11: T, m12: T, m13: T, m14: T,
}
}
struct Matrix4<T:Copy Num> {
struct Matrix4<T> {
m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,

View File

@ -29,7 +29,7 @@ fn align(size: uint, align: uint) -> uint {
((size + align) - 1u) & !(align - 1u)
}
enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = Inner<V>;
enum ptr_visit_adaptor<V> = Inner<V>;
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V> {

View File

@ -13,7 +13,7 @@
struct Arg<T> {val: T, fin: extern fn(T)}
struct finish<T: Copy> {
struct finish<T> {
arg: Arg<T>
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
// tests that ctrl's type gets inferred properly
type command<K: Owned, V: Owned> = {key: K, val: V};
type command<K, V> = {key: K, val: V};
fn cache_server<K: Owned, V: Owned>(c: oldcomm::Chan<oldcomm::Chan<command<K, V>>>) {
let ctrl = oldcomm::Port();