librustc: Rename Owned to Send in the compiler

This commit is contained in:
Patrick Walton 2013-06-05 11:33:14 -07:00 committed by Corey Richardson
parent 811e045c60
commit 607b91d5f9
9 changed files with 65 additions and 54 deletions

View File

@ -35,8 +35,8 @@ struct RcBox<T> {
}
/// Immutable reference counted pointer type
#[non_owned]
#[unsafe_no_drop_flag]
#[non_sendable]
pub struct Rc<T> {
priv ptr: *mut RcBox<T>,
}
@ -168,6 +168,7 @@ struct RcMutBox<T> {
/// Mutable reference counted pointer type
#[non_owned]
#[non_sendable]
#[mutable]
#[unsafe_no_drop_flag]
pub struct RcMut<T> {

View File

@ -554,7 +554,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
loop {
match next(st) {
'S' => {
param_bounds.builtin_bounds.add(ty::BoundOwned);
param_bounds.builtin_bounds.add(ty::BoundSend);
}
'C' => {
param_bounds.builtin_bounds.add(ty::BoundCopy);

View File

@ -401,7 +401,7 @@ fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
for bs.builtin_bounds.each |bound| {
match bound {
ty::BoundOwned => w.write_char('S'),
ty::BoundSend => w.write_char('S'),
ty::BoundCopy => w.write_char('C'),
ty::BoundConst => w.write_char('K'),
ty::BoundStatic => w.write_char('O'),

View File

@ -33,7 +33,7 @@ use syntax::{visit, ast_util};
// copy: Things that can be copied.
// const: Things thare are deeply immutable. They are guaranteed never to
// change, and can be safely shared without copying between tasks.
// owned: Things that do not contain borrowed pointers.
// 'static: Things that do not contain borrowed pointers.
//
// Send includes scalar types as well as classes and unique types containing
// only sendable types.
@ -90,10 +90,10 @@ fn check_struct_safe_for_destructor(cx: Context,
self_ty: None,
tps: ~[]
});
if !ty::type_is_owned(cx.tcx, struct_ty) {
if !ty::type_is_sendable(cx.tcx, struct_ty) {
cx.tcx.sess.span_err(span,
"cannot implement a destructor on a struct \
that is not Owned");
"cannot implement a destructor on a \
structure that does not satisfy Send");
cx.tcx.sess.span_note(span,
"use \"#[unsafe_destructor]\" on the \
implementation to force the compiler to \
@ -101,7 +101,7 @@ fn check_struct_safe_for_destructor(cx: Context,
}
} else {
cx.tcx.sess.span_err(span,
"cannot implement a destructor on a struct \
"cannot implement a destructor on a structure \
with type parameters");
cx.tcx.sess.span_note(span,
"use \"#[unsafe_destructor]\" on the \
@ -438,10 +438,10 @@ fn check_copy(cx: Context, ty: ty::t, sp: span, reason: &str) {
}
}
pub fn check_owned(cx: Context, ty: ty::t, sp: span) -> bool {
if !ty::type_is_owned(cx.tcx, ty) {
pub fn check_send(cx: Context, ty: ty::t, sp: span) -> bool {
if !ty::type_is_sendable(cx.tcx, ty) {
cx.tcx.sess.span_err(
sp, fmt!("value has non-owned type `%s`",
sp, fmt!("value has non-sendable type `%s`",
ty_to_str(cx.tcx, ty)));
false
} else {
@ -489,7 +489,7 @@ pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
/// `deque<T>`, then whatever borrowed ptrs may appear in `T` also
/// appear in `deque<T>`.
///
/// (3) The type parameter is owned (and therefore does not contain
/// (3) The type parameter is sendable (and therefore does not contain
/// borrowed ptrs).
///
/// FIXME(#5723)---This code should probably move into regionck.
@ -528,7 +528,7 @@ pub fn check_cast_for_escaping_regions(
}
// Assuming the trait instance can escape, then ensure that each parameter
// either appears in the trait type or is owned.
// either appears in the trait type or is sendable.
let target_params = ty::param_tys_in_type(target_ty);
let source_ty = ty::expr_ty(cx.tcx, source);
ty::walk_regions_and_ty(
@ -574,3 +574,4 @@ pub fn check_cast_for_escaping_regions(
cx.tcx.region_maps.is_subregion_of(r_sub, r_sup)
}
}

View File

@ -13,7 +13,7 @@
// Language items are items that represent concepts intrinsic to the language
// itself. Examples are:
//
// * Traits that specify "kinds"; e.g. "const", "copy", "owned".
// * Traits that specify "kinds"; e.g. "const", "copy", "send".
//
// * Traits that represent operators; e.g. "add", "sub", "index".
//
@ -33,9 +33,9 @@ use syntax::visit::visit_crate;
use core::hashmap::HashMap;
pub enum LangItem {
ConstTraitLangItem, // 0
FreezeTraitLangItem, // 0
CopyTraitLangItem, // 1
OwnedTraitLangItem, // 2
SendTraitLangItem, // 2
SizedTraitLangItem, // 3
DropTraitLangItem, // 4
@ -101,7 +101,7 @@ impl LanguageItems {
match index {
0 => "const",
1 => "copy",
2 => "owned",
2 => "send",
3 => "sized",
4 => "drop",
@ -152,14 +152,14 @@ impl LanguageItems {
// FIXME #4621: Method macros sure would be nice here.
pub fn const_trait(&const self) -> def_id {
self.items[ConstTraitLangItem as uint].get()
pub fn freeze_trait(&const self) -> def_id {
self.items[FreezeTraitLangItem as uint].get()
}
pub fn copy_trait(&const self) -> def_id {
self.items[CopyTraitLangItem as uint].get()
}
pub fn owned_trait(&const self) -> def_id {
self.items[OwnedTraitLangItem as uint].get()
pub fn send_trait(&const self) -> def_id {
self.items[SendTraitLangItem as uint].get()
}
pub fn sized_trait(&const self) -> def_id {
self.items[SizedTraitLangItem as uint].get()
@ -291,13 +291,13 @@ struct LanguageItemCollector<'self> {
}
impl<'self> LanguageItemCollector<'self> {
pub fn new<'a>(crate: &'a crate, session: Session) -> LanguageItemCollector<'a> {
pub fn new<'a>(crate: &'a crate, session: Session)
-> LanguageItemCollector<'a> {
let mut item_refs = HashMap::new();
item_refs.insert(@"const", ConstTraitLangItem as uint);
item_refs.insert(@"const", FreezeTraitLangItem as uint);
item_refs.insert(@"copy", CopyTraitLangItem as uint);
item_refs.insert(@"owned", OwnedTraitLangItem as uint);
item_refs.insert(@"owned", SendTraitLangItem as uint);
item_refs.insert(@"sized", SizedTraitLangItem as uint);
item_refs.insert(@"drop", DropTraitLangItem as uint);

View File

@ -686,7 +686,7 @@ pub type BuiltinBounds = EnumSet<BuiltinBound>;
pub enum BuiltinBound {
BoundCopy,
BoundStatic,
BoundOwned,
BoundSend,
BoundConst,
BoundSized,
}
@ -699,7 +699,7 @@ pub fn AllBuiltinBounds() -> BuiltinBounds {
let mut set = EnumSet::empty();
set.add(BoundCopy);
set.add(BoundStatic);
set.add(BoundOwned);
set.add(BoundSend);
set.add(BoundConst);
set.add(BoundSized);
set
@ -1839,7 +1839,7 @@ impl TypeContents {
BoundCopy => self.is_copy(cx),
BoundStatic => self.is_static(cx),
BoundConst => self.is_const(cx),
BoundOwned => self.is_owned(cx),
BoundSend => self.is_sendable(cx),
BoundSized => self.is_sized(cx),
}
}
@ -1865,12 +1865,12 @@ impl TypeContents {
TC_BORROWED_POINTER
}
pub fn is_owned(&self, cx: ctxt) -> bool {
!self.intersects(TypeContents::nonowned(cx))
pub fn is_sendable(&self, cx: ctxt) -> bool {
!self.intersects(TypeContents::nonsendable(cx))
}
pub fn nonowned(_cx: ctxt) -> TypeContents {
TC_MANAGED + TC_BORROWED_POINTER + TC_NON_OWNED
pub fn nonsendable(_cx: ctxt) -> TypeContents {
TC_MANAGED + TC_BORROWED_POINTER + TC_NON_SENDABLE
}
pub fn contains_managed(&self) -> bool {
@ -1912,8 +1912,8 @@ impl TypeContents {
self.intersects(tc)
}
pub fn owned(_cx: ctxt) -> TypeContents {
//! Any kind of owned contents.
pub fn sendable(_cx: ctxt) -> TypeContents {
//! Any kind of sendable contents.
TC_OWNED_POINTER + TC_OWNED_VEC
}
}
@ -1969,8 +1969,8 @@ static TC_ONCE_CLOSURE: TypeContents = TypeContents{bits: 0b0001_0000_0000};
/// An enum with no variants.
static TC_EMPTY_ENUM: TypeContents = TypeContents{bits: 0b0010_0000_0000};
/// Contains a type marked with `#[non_owned]`
static TC_NON_OWNED: TypeContents = TypeContents{bits: 0b0100_0000_0000};
/// Contains a type marked with `#[non_sendable]`
static TC_NON_SENDABLE: TypeContents = TypeContents{bits: 0b0100_0000_0000};
/// Is a bare vector, str, function, trait, etc (only relevant at top level).
static TC_DYNAMIC_SIZE: TypeContents = TypeContents{bits: 0b1000_0000_0000};
@ -1986,8 +1986,8 @@ pub fn type_is_static(cx: ctxt, t: ty::t) -> bool {
type_contents(cx, t).is_static(cx)
}
pub fn type_is_owned(cx: ctxt, t: ty::t) -> bool {
type_contents(cx, t).is_owned(cx)
pub fn type_is_sendable(cx: ctxt, t: ty::t) -> bool {
type_contents(cx, t).is_sendable(cx)
}
pub fn type_is_const(cx: ctxt, t: ty::t) -> bool {
@ -2045,7 +2045,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
let _i = indenter();
let result = match get(ty).sty {
// Scalar and unique types are sendable, constant, and owned
// Scalar and unique types are sendable, constant, and durable
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_bare_fn(_) | ty_ptr(_) => {
TC_NONE
@ -2060,7 +2060,8 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
}
ty_box(mt) => {
TC_MANAGED + statically_sized(nonowned(tc_mt(cx, mt, cache)))
TC_MANAGED +
statically_sized(nonsendable(tc_mt(cx, mt, cache)))
}
ty_trait(_, _, store, mutbl, bounds) => {
@ -2069,7 +2070,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
ty_rptr(r, mt) => {
borrowed_contents(r, mt.mutbl) +
statically_sized(nonowned(tc_mt(cx, mt, cache)))
statically_sized(nonsendable(tc_mt(cx, mt, cache)))
}
ty_uniq(mt) => {
@ -2081,12 +2082,13 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
}
ty_evec(mt, vstore_box) => {
TC_MANAGED + statically_sized(nonowned(tc_mt(cx, mt, cache)))
TC_MANAGED +
statically_sized(nonsendable(tc_mt(cx, mt, cache)))
}
ty_evec(mt, vstore_slice(r)) => {
borrowed_contents(r, mt.mutbl) +
statically_sized(nonowned(tc_mt(cx, mt, cache)))
statically_sized(nonsendable(tc_mt(cx, mt, cache)))
}
ty_evec(mt, vstore_fixed(_)) => {
@ -2205,8 +2207,8 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
if has_attr(cx, did, "mutable") {
tc += TC_MUTABLE;
}
if has_attr(cx, did, "non_owned") {
tc += TC_NON_OWNED;
if has_attr(cx, did, "non_sendable") {
tc += TC_NON_SENDABLE;
}
tc
}
@ -2227,7 +2229,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
mc + rc
}
fn nonowned(pointee: TypeContents) -> TypeContents {
fn nonsendable(pointee: TypeContents) -> TypeContents {
/*!
*
* Given a non-owning pointer to some type `T` with
@ -2314,7 +2316,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
tc = tc - match bound {
BoundCopy => TypeContents::noncopyable(cx),
BoundStatic => TypeContents::nonstatic(cx),
BoundOwned => TypeContents::nonowned(cx),
BoundSend => TypeContents::nonsendable(cx),
BoundConst => TypeContents::nonconst(cx),
// The dynamic-size bit can be removed at pointer-level, etc.
BoundSized => TypeContents::dynamically_sized(cx),

View File

@ -753,7 +753,7 @@ fn conv_builtin_bounds(tcx: ty::ctxt, ast_bounds: &Option<OptVec<ast::TyParamBou
//! Converts a list of bounds from the AST into a `BuiltinBounds`
//! struct. Reports an error if any of the bounds that appear
//! in the AST refer to general traits and not the built-in traits
//! like `Copy` or `Owned`. Used to translate the bounds that
//! like `Copy` or `Send`. Used to translate the bounds that
//! appear in closure and trait types, where only builtin bounds are
//! legal.
//! If no bounds were specified, we choose a "default" bound based on
@ -807,13 +807,13 @@ pub fn try_add_builtin_trait(tcx: ty::ctxt,
trait_def_id: ast::def_id,
builtin_bounds: &mut ty::BuiltinBounds) -> bool {
//! Checks whether `trait_ref` refers to one of the builtin
//! traits, like `Copy` or `Owned`, and adds the corresponding
//! traits, like `Copy` or `Send`, and adds the corresponding
//! bound to the set `builtin_bounds` if so. Returns true if `trait_ref`
//! is a builtin trait.
let li = &tcx.lang_items;
if trait_def_id == li.owned_trait() {
builtin_bounds.add(ty::BoundOwned);
if trait_def_id == li.send_trait() {
builtin_bounds.add(ty::BoundSend);
true
} else if trait_def_id == li.copy_trait() {
builtin_bounds.add(ty::BoundCopy);

View File

@ -575,7 +575,7 @@ impl Repr for ty::ParamBounds {
res.push(match b {
ty::BoundCopy => ~"Copy",
ty::BoundStatic => ~"'static",
ty::BoundOwned => ~"Owned",
ty::BoundSend => ~"Send",
ty::BoundConst => ~"Const",
ty::BoundSized => ~"Sized",
});
@ -781,7 +781,7 @@ impl UserString for ty::BuiltinBound {
match *self {
ty::BoundCopy => ~"Copy",
ty::BoundStatic => ~"'static",
ty::BoundOwned => ~"Owned",
ty::BoundSend => ~"Send",
ty::BoundConst => ~"Const",
ty::BoundSized => ~"Sized",
}

View File

@ -44,9 +44,16 @@ pub trait Copy {
// Empty.
}
#[cfg(stage0)]
#[lang="owned"]
pub trait Owned {
// Empty.
// empty.
}
#[cfg(not(stage0))]
#[lang="send"]
pub trait Owned {
// empty.
}
#[lang="const"]