librustc: Change Const to Freeze in the compiler

This commit is contained in:
Patrick Walton 2013-06-05 14:52:27 -07:00 committed by Corey Richardson
parent 607b91d5f9
commit d350981c0e
9 changed files with 34 additions and 27 deletions

View File

@ -560,7 +560,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
param_bounds.builtin_bounds.add(ty::BoundCopy);
}
'K' => {
param_bounds.builtin_bounds.add(ty::BoundConst);
param_bounds.builtin_bounds.add(ty::BoundFreeze);
}
'O' => {
param_bounds.builtin_bounds.add(ty::BoundStatic);

View File

@ -403,7 +403,7 @@ fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
match bound {
ty::BoundSend => w.write_char('S'),
ty::BoundCopy => w.write_char('C'),
ty::BoundConst => w.write_char('K'),
ty::BoundFreeze => w.write_char('K'),
ty::BoundStatic => w.write_char('O'),
ty::BoundSized => w.write_char('Z'),
}

View File

@ -31,7 +31,7 @@ use syntax::{visit, ast_util};
//
// send: Things that can be sent on channels or included in spawned closures.
// copy: Things that can be copied.
// const: Things thare are deeply immutable. They are guaranteed never to
// freeze: Things thare are deeply immutable. They are guaranteed never to
// change, and can be safely shared without copying between tasks.
// 'static: Things that do not contain borrowed pointers.
//
@ -40,12 +40,12 @@ use syntax::{visit, ast_util};
//
// Copy includes boxes, closure and unique types containing copyable types.
//
// Const include scalar types, things without non-const fields, and pointers
// to const things.
// Freeze include scalar types, things without non-const fields, and pointers
// to freezable things.
//
// This pass ensures that type parameters are only instantiated with types
// whose kinds are equal or less general than the way the type parameter was
// annotated (with the `send`, `copy` or `const` keyword).
// annotated (with the `Send`, `Copy` or `Freeze` bound).
//
// It also verifies that noncopyable kinds are not copied. Sendability is not
// applied, since none of our language primitives send. Instead, the sending

View File

@ -13,9 +13,9 @@
// Language items are items that represent concepts intrinsic to the language
// itself. Examples are:
//
// * Traits that specify "kinds"; e.g. "const", "copy", "send".
// * Traits that specify "kinds"; e.g. "Freeze", "Copy", "Send".
//
// * Traits that represent operators; e.g. "add", "sub", "index".
// * Traits that represent operators; e.g. "Add", "Sub", "Index".
//
// * Functions called by the compiler itself.
@ -99,7 +99,7 @@ impl LanguageItems {
pub fn item_name(index: uint) -> &'static str {
match index {
0 => "const",
0 => "freeze",
1 => "copy",
2 => "send",
3 => "sized",

View File

@ -687,7 +687,7 @@ pub enum BuiltinBound {
BoundCopy,
BoundStatic,
BoundSend,
BoundConst,
BoundFreeze,
BoundSized,
}
@ -700,7 +700,7 @@ pub fn AllBuiltinBounds() -> BuiltinBounds {
set.add(BoundCopy);
set.add(BoundStatic);
set.add(BoundSend);
set.add(BoundConst);
set.add(BoundFreeze);
set.add(BoundSized);
set
}
@ -1838,7 +1838,7 @@ impl TypeContents {
match bb {
BoundCopy => self.is_copy(cx),
BoundStatic => self.is_static(cx),
BoundConst => self.is_const(cx),
BoundFreeze => self.is_freezable(cx),
BoundSend => self.is_sendable(cx),
BoundSized => self.is_sized(cx),
}
@ -1877,11 +1877,11 @@ impl TypeContents {
self.intersects(TC_MANAGED)
}
pub fn is_const(&self, cx: ctxt) -> bool {
!self.intersects(TypeContents::nonconst(cx))
pub fn is_freezable(&self, cx: ctxt) -> bool {
!self.intersects(TypeContents::nonfreezable(cx))
}
pub fn nonconst(_cx: ctxt) -> TypeContents {
pub fn nonfreezable(_cx: ctxt) -> TypeContents {
TC_MUTABLE
}
@ -1990,8 +1990,8 @@ 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 {
type_contents(cx, t).is_const(cx)
pub fn type_is_freezable(cx: ctxt, t: ty::t) -> bool {
type_contents(cx, t).is_freezable(cx)
}
pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
@ -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 durable
// Scalar and unique types are sendable, freezable, and durable
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_bare_fn(_) | ty_ptr(_) => {
TC_NONE
@ -2317,7 +2317,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
BoundCopy => TypeContents::noncopyable(cx),
BoundStatic => TypeContents::nonstatic(cx),
BoundSend => TypeContents::nonsendable(cx),
BoundConst => TypeContents::nonconst(cx),
BoundFreeze => TypeContents::nonfreezable(cx),
// The dynamic-size bit can be removed at pointer-level, etc.
BoundSized => TypeContents::dynamically_sized(cx),
};

View File

@ -818,8 +818,8 @@ pub fn try_add_builtin_trait(tcx: ty::ctxt,
} else if trait_def_id == li.copy_trait() {
builtin_bounds.add(ty::BoundCopy);
true
} else if trait_def_id == li.const_trait() {
builtin_bounds.add(ty::BoundConst);
} else if trait_def_id == li.freeze_trait() {
builtin_bounds.add(ty::BoundFreeze);
true
} else if trait_def_id == li.sized_trait() {
builtin_bounds.add(ty::BoundSized);

View File

@ -576,7 +576,7 @@ impl Repr for ty::ParamBounds {
ty::BoundCopy => ~"Copy",
ty::BoundStatic => ~"'static",
ty::BoundSend => ~"Send",
ty::BoundConst => ~"Const",
ty::BoundFreeze => ~"Freeze",
ty::BoundSized => ~"Sized",
});
}
@ -782,7 +782,7 @@ impl UserString for ty::BuiltinBound {
ty::BoundCopy => ~"Copy",
ty::BoundStatic => ~"'static",
ty::BoundSend => ~"Send",
ty::BoundConst => ~"Const",
ty::BoundFreeze => ~"Freeze",
ty::BoundSized => ~"Sized",
}
}

View File

@ -27,8 +27,7 @@ The 4 kinds are
* Owned - owned types and types containing owned types. These types
may be transferred across task boundaries.
* Const - types that are deeply immutable. Const types are used for
freezable data structures.
* Freeze - types that are deeply immutable.
`Copy` types include both implicitly copyable types that the compiler
will copy automatically and non-implicitly copyable types that require
@ -56,9 +55,16 @@ pub trait Owned {
// empty.
}
#[cfg(stage0)]
#[lang="const"]
pub trait Const {
// Empty.
// empty.
}
#[cfg(not(stage0))]
#[lang="freeze"]
pub trait Const {
// empty.
}
#[lang="sized"]

View File

@ -29,7 +29,8 @@ Rust's prelude has three main parts:
// Reexported core operators
pub use either::{Either, Left, Right};
pub use kinds::{Const, Copy, Owned, Sized};
pub use kinds::{Copy, Sized};
pub use kinds::{Const, Owned};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop};