Rename Pod into Copy

Summary:
So far, we've used the term POD "Plain Old Data" to refer to types that
can be safely copied. However, this term is not consistent with the
other built-in bounds that use verbs instead. This patch renames the Pod
kind into Copy.

RFC: 0003-opt-in-builtin-traits

Test Plan: make check

Reviewers: cmr

Differential Revision: http://phabricator.octayn.net/D3
This commit is contained in:
Flavio Percoco 2014-03-27 00:01:11 +01:00
parent ff64381c8b
commit 81ec1f3c18
35 changed files with 233 additions and 218 deletions

View File

@ -595,7 +595,7 @@ Other features provided by lang items include:
- stack unwinding and general failure; the `eh_personality`, `fail_`
and `fail_bounds_checks` lang items.
- the traits in `std::kinds` used to indicate types that satisfy
various kinds; lang items `send`, `share` and `pod`.
various kinds; lang items `send`, `share` and `copy`.
- the marker types and variance indicators found in
`std::kinds::markers`; lang items `covariant_type`,
`contravariant_lifetime`, `no_share_bound`, etc.

View File

@ -3439,12 +3439,12 @@ The kinds are:
This kind includes scalars, owning pointers, owned closures, and
structural types containing only other owned types.
All `Send` types are `'static`.
`Pod`
`Copy`
: Types of this kind consist of "Plain Old Data"
which can be copied by simply moving bits.
All values of this kind can be implicitly copied.
This kind includes scalars and immutable references,
as well as structural types containing other `Pod` types.
as well as structural types containing other `Copy` types.
`'static`
: Types of this kind do not contain any references (except for
references with the `static` lifetime, which are allowed).

View File

@ -52,7 +52,7 @@ syn keyword rustType f64 i8 i16 i32 i64 str Self
" to make it easy to update.
" Core operators {{{3
syn keyword rustTrait Freeze Pod Send Sized
syn keyword rustTrait Freeze Copy Send Sized
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
syn keyword rustTrait BitAnd BitOr BitXor
syn keyword rustTrait Drop

View File

@ -48,7 +48,7 @@ use std::intrinsics;
struct Chunk {
data: Rc<RefCell<Vec<u8> >>,
fill: Cell<uint>,
is_pod: Cell<bool>,
is_copy: Cell<bool>,
}
impl Chunk {
fn capacity(&self) -> uint {
@ -86,7 +86,7 @@ pub struct Arena {
// microoptimization, to avoid needing to case on the list to
// access the head.
priv head: Chunk,
priv pod_head: Chunk,
priv copy_head: Chunk,
priv chunks: RefCell<@List<Chunk>>,
}
@ -98,17 +98,17 @@ impl Arena {
pub fn new_with_size(initial_size: uint) -> Arena {
Arena {
head: chunk(initial_size, false),
pod_head: chunk(initial_size, true),
copy_head: chunk(initial_size, true),
chunks: RefCell::new(@Nil),
}
}
}
fn chunk(size: uint, is_pod: bool) -> Chunk {
fn chunk(size: uint, is_copy: bool) -> Chunk {
Chunk {
data: Rc::new(RefCell::new(Vec::with_capacity(size))),
fill: Cell::new(0u),
is_pod: Cell::new(is_pod),
is_copy: Cell::new(is_copy),
}
}
@ -118,7 +118,7 @@ impl Drop for Arena {
unsafe {
destroy_chunk(&self.head);
for chunk in self.chunks.get().iter() {
if !chunk.is_pod.get() {
if !chunk.is_copy.get() {
destroy_chunk(chunk);
}
}
@ -173,41 +173,41 @@ fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
impl Arena {
fn chunk_size(&self) -> uint {
self.pod_head.capacity()
self.copy_head.capacity()
}
// Functions for the POD part of the arena
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
fn alloc_copy_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
self.pod_head =
self.chunks.set(@Cons(self.copy_head.clone(), self.chunks.get()));
self.copy_head =
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
return self.alloc_pod_inner(n_bytes, align);
return self.alloc_copy_inner(n_bytes, align);
}
#[inline]
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
unsafe {
let this = transmute_mut_region(self);
let start = round_up(this.pod_head.fill.get(), align);
let start = round_up(this.copy_head.fill.get(), align);
let end = start + n_bytes;
if end > self.chunk_size() {
return this.alloc_pod_grow(n_bytes, align);
return this.alloc_copy_grow(n_bytes, align);
}
this.pod_head.fill.set(end);
this.copy_head.fill.set(end);
//debug!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill.get());
this.pod_head.as_ptr().offset(start as int)
this.copy_head.as_ptr().offset(start as int)
}
}
#[inline]
fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
unsafe {
let ptr = self.alloc_pod_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
let ptr: *mut T = transmute(ptr);
mem::move_val_init(&mut (*ptr), op());
return transmute(ptr);
@ -215,7 +215,7 @@ impl Arena {
}
// Functions for the non-POD part of the arena
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
fn alloc_noncopy_grow(&mut self, n_bytes: uint, align: uint)
-> (*u8, *u8) {
// Allocate a new chunk.
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
@ -223,11 +223,11 @@ impl Arena {
self.head =
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
return self.alloc_nonpod_inner(n_bytes, align);
return self.alloc_noncopy_inner(n_bytes, align);
}
#[inline]
fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint)
-> (*u8, *u8) {
unsafe {
let start;
@ -245,7 +245,7 @@ impl Arena {
}
if end > self.head.capacity() {
return self.alloc_nonpod_grow(n_bytes, align);
return self.alloc_noncopy_grow(n_bytes, align);
}
let head = transmute_mut_region(&mut self.head);
@ -260,11 +260,11 @@ impl Arena {
}
#[inline]
fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
fn alloc_noncopy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
unsafe {
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
self.alloc_nonpod_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
self.alloc_noncopy_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
let ty_ptr: *mut uint = transmute(ty_ptr);
let ptr: *mut T = transmute(ptr);
// Write in our tydesc along with a bit indicating that it
@ -287,9 +287,9 @@ impl Arena {
// FIXME: Borrow check
let this = transmute_mut(self);
if intrinsics::needs_drop::<T>() {
this.alloc_nonpod(op)
this.alloc_noncopy(op)
} else {
this.alloc_pod(op)
this.alloc_copy(op)
}
}
}
@ -496,7 +496,7 @@ mod tests {
}
#[test]
pub fn test_pod() {
pub fn test_copy() {
let arena = TypedArena::new();
for _ in range(0, 100000) {
arena.alloc(Point {
@ -508,7 +508,7 @@ mod tests {
}
#[bench]
pub fn bench_pod(bh: &mut BenchHarness) {
pub fn bench_copy(bh: &mut BenchHarness) {
let arena = TypedArena::new();
bh.iter(|| {
arena.alloc(Point {
@ -520,7 +520,7 @@ mod tests {
}
#[bench]
pub fn bench_pod_nonarena(bh: &mut BenchHarness) {
pub fn bench_copy_nonarena(bh: &mut BenchHarness) {
bh.iter(|| {
~Point {
x: 1,
@ -531,7 +531,7 @@ mod tests {
}
#[bench]
pub fn bench_pod_old_arena(bh: &mut BenchHarness) {
pub fn bench_copy_old_arena(bh: &mut BenchHarness) {
let arena = Arena::new();
bh.iter(|| {
arena.alloc(|| {
@ -544,16 +544,16 @@ mod tests {
})
}
struct Nonpod {
struct Noncopy {
string: ~str,
array: Vec<int> ,
}
#[test]
pub fn test_nonpod() {
pub fn test_noncopy() {
let arena = TypedArena::new();
for _ in range(0, 100000) {
arena.alloc(Nonpod {
arena.alloc(Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
});
@ -561,10 +561,10 @@ mod tests {
}
#[bench]
pub fn bench_nonpod(bh: &mut BenchHarness) {
pub fn bench_noncopy(bh: &mut BenchHarness) {
let arena = TypedArena::new();
bh.iter(|| {
arena.alloc(Nonpod {
arena.alloc(Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
})
@ -572,9 +572,9 @@ mod tests {
}
#[bench]
pub fn bench_nonpod_nonarena(bh: &mut BenchHarness) {
pub fn bench_noncopy_nonarena(bh: &mut BenchHarness) {
bh.iter(|| {
~Nonpod {
~Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
}
@ -582,10 +582,10 @@ mod tests {
}
#[bench]
pub fn bench_nonpod_old_arena(bh: &mut BenchHarness) {
pub fn bench_noncopy_old_arena(bh: &mut BenchHarness) {
let arena = Arena::new();
bh.iter(|| {
arena.alloc(|| Nonpod {
arena.alloc(|| Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
})

View File

@ -110,7 +110,7 @@ mod table {
/// Represents an index into a `RawTable` with no key or value in it.
pub struct EmptyIndex {
priv idx: int,
priv nopod: marker::NoPod,
priv nocopy: marker::NoCopy,
}
/// Represents an index into a `RawTable` with a key, value, and hash
@ -118,7 +118,7 @@ mod table {
pub struct FullIndex {
priv idx: int,
priv hash: SafeHash,
priv nopod: marker::NoPod,
priv nocopy: marker::NoCopy,
}
impl FullIndex {
@ -237,19 +237,19 @@ mod table {
let idx = index as int;
let hash = unsafe { *self.hashes.offset(idx) };
let nopod = marker::NoPod;
let nocopy = marker::NoCopy;
match hash {
EMPTY_BUCKET =>
Empty(EmptyIndex {
idx: idx,
nopod: nopod
nocopy: nocopy
}),
full_hash =>
Full(FullIndex {
idx: idx,
hash: SafeHash { hash: full_hash },
nopod: nopod,
nocopy: nocopy,
})
}
}
@ -320,7 +320,7 @@ mod table {
self.size += 1;
FullIndex { idx: idx, hash: hash, nopod: marker::NoPod }
FullIndex { idx: idx, hash: hash, nocopy: marker::NoCopy }
}
/// Removes a key and value from the hashtable.
@ -347,7 +347,7 @@ mod table {
self.size -= 1;
(EmptyIndex { idx: idx, nopod: marker::NoPod }, k, v)
(EmptyIndex { idx: idx, nocopy: marker::NoCopy }, k, v)
}
}

View File

@ -591,7 +591,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
param_bounds.builtin_bounds.add(ty::BoundSized);
}
'P' => {
param_bounds.builtin_bounds.add(ty::BoundPod);
param_bounds.builtin_bounds.add(ty::BoundCopy);
}
'T' => {
param_bounds.builtin_bounds.add(ty::BoundShare);

View File

@ -394,7 +394,7 @@ fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
ty::BoundSend => mywrite!(w, "S"),
ty::BoundStatic => mywrite!(w, "O"),
ty::BoundSized => mywrite!(w, "Z"),
ty::BoundPod => mywrite!(w, "P"),
ty::BoundCopy => mywrite!(w, "P"),
ty::BoundShare => mywrite!(w, "T"),
}
}

View File

@ -86,8 +86,8 @@ impl LanguageItems {
Some(ty::BoundSend)
} else if Some(id) == self.sized_trait() {
Some(ty::BoundSized)
} else if Some(id) == self.pod_trait() {
Some(ty::BoundPod)
} else if Some(id) == self.copy_trait() {
Some(ty::BoundCopy)
} else if Some(id) == self.share_trait() {
Some(ty::BoundShare)
} else {
@ -210,7 +210,7 @@ lets_do_this! {
// Variant name, Name, Method name;
SendTraitLangItem, "send", send_trait;
SizedTraitLangItem, "sized", sized_trait;
PodTraitLangItem, "pod", pod_trait;
CopyTraitLangItem, "copy", copy_trait;
ShareTraitLangItem, "share", share_trait;
DropTraitLangItem, "drop", drop_trait;
@ -271,7 +271,7 @@ lets_do_this! {
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
NoSendItem, "no_send_bound", no_send_bound;
NoPodItem, "no_pod_bound", no_pod_bound;
NoCopyItem, "no_copy_bound", no_copy_bound;
NoShareItem, "no_share_bound", no_share_bound;
ManagedItem, "managed_bound", managed_bound;
}

View File

@ -842,7 +842,7 @@ pub enum BuiltinBound {
BoundStatic,
BoundSend,
BoundSized,
BoundPod,
BoundCopy,
BoundShare,
}
@ -1905,7 +1905,7 @@ def_type_content_sets!(
// Things that make values considered not POD (would be same
// as `Moves`, but for the fact that managed data `@` is
// not considered POD)
Nonpod = 0b0000_0000__0000_1111__0000,
Noncopy = 0b0000_0000__0000_1111__0000,
// Bits to set when a managed value is encountered
//
@ -1929,7 +1929,7 @@ impl TypeContents {
BoundStatic => self.is_static(cx),
BoundSend => self.is_sendable(cx),
BoundSized => self.is_sized(cx),
BoundPod => self.is_pod(cx),
BoundCopy => self.is_copy(cx),
BoundShare => self.is_sharable(cx),
}
}
@ -1966,8 +1966,8 @@ impl TypeContents {
!self.intersects(TC::Nonsized)
}
pub fn is_pod(&self, _: &ctxt) -> bool {
!self.intersects(TC::Nonpod)
pub fn is_copy(&self, _: &ctxt) -> bool {
!self.intersects(TC::Noncopy)
}
pub fn interior_unsafe(&self) -> bool {
@ -2263,7 +2263,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
tc | TC::ReachesNonsendAnnot
} else if Some(did) == cx.lang_items.managed_bound() {
tc | TC::Managed
} else if Some(did) == cx.lang_items.no_pod_bound() {
} else if Some(did) == cx.lang_items.no_copy_bound() {
tc | TC::OwnsAffine
} else if Some(did) == cx.lang_items.no_share_bound() {
tc | TC::ReachesNoShare
@ -2345,7 +2345,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
BoundStatic => TC::Nonstatic,
BoundSend => TC::Nonsendable,
BoundSized => TC::Nonsized,
BoundPod => TC::Nonpod,
BoundCopy => TC::Noncopy,
BoundShare => TC::Nonsharable,
};
});

View File

@ -665,7 +665,7 @@ impl Repr for ty::ParamBounds {
ty::BoundStatic => ~"'static",
ty::BoundSend => ~"Send",
ty::BoundSized => ~"Sized",
ty::BoundPod => ~"Pod",
ty::BoundCopy => ~"Pod",
ty::BoundShare => ~"Share",
});
}
@ -952,7 +952,7 @@ impl UserString for ty::BuiltinBound {
ty::BoundStatic => ~"'static",
ty::BoundSend => ~"Send",
ty::BoundSized => ~"Sized",
ty::BoundPod => ~"Pod",
ty::BoundCopy => ~"Pod",
ty::BoundShare => ~"Share",
}
}

View File

@ -14,18 +14,18 @@ use cast;
use clone::Clone;
use cmp::Eq;
use fmt;
use kinds::{marker, Pod};
use kinds::{marker, Copy};
use ops::{Deref, DerefMut, Drop};
use option::{None, Option, Some};
use ty::Unsafe;
/// A mutable memory location that admits only `Pod` data.
/// A mutable memory location that admits only `Copy` data.
pub struct Cell<T> {
priv value: Unsafe<T>,
priv noshare: marker::NoShare,
}
impl<T:Pod> Cell<T> {
impl<T:Copy> Cell<T> {
/// Creates a new `Cell` containing the given value.
pub fn new(value: T) -> Cell<T> {
Cell {
@ -49,13 +49,13 @@ impl<T:Pod> Cell<T> {
}
}
impl<T:Pod> Clone for Cell<T> {
impl<T:Copy> Clone for Cell<T> {
fn clone(&self) -> Cell<T> {
Cell::new(self.get())
}
}
impl<T:Eq + Pod> Eq for Cell<T> {
impl<T:Eq + Copy> Eq for Cell<T> {
fn eq(&self, other: &Cell<T>) -> bool {
self.get() == other.get()
}
@ -71,7 +71,7 @@ impl<T: fmt::Show> fmt::Show for Cell<T> {
pub struct RefCell<T> {
priv value: Unsafe<T>,
priv borrow: BorrowFlag,
priv nopod: marker::NoPod,
priv nocopy: marker::NoCopy,
priv noshare: marker::NoShare,
}
@ -86,7 +86,7 @@ impl<T> RefCell<T> {
pub fn new(value: T) -> RefCell<T> {
RefCell {
value: Unsafe::new(value),
nopod: marker::NoPod,
nocopy: marker::NoCopy,
noshare: marker::NoShare,
borrow: UNUSED,
}

View File

@ -296,7 +296,7 @@ extern "rust-intrinsic" {
/// Create a value initialized to zero.
///
/// `init` is unsafe because it returns a zeroed-out datum,
/// which is unsafe unless T is Pod.
/// which is unsafe unless T is Copy.
pub fn init<T>() -> T;
/// Create an uninitialized value.

View File

@ -33,10 +33,16 @@ pub trait Sized {
}
/// Types that can be copied by simply copying bits (i.e. `memcpy`).
///
/// The name "POD" stands for "Plain Old Data" and is borrowed from C++.
#[cfg(stage0)]
#[lang="pod"]
pub trait Pod {
pub trait Copy {
// Empty.
}
/// Types that can be copied by simply copying bits (i.e. `memcpy`).
#[cfg(not(stage0))]
#[lang="copy"]
pub trait Copy {
// Empty.
}
@ -264,9 +270,18 @@ pub mod marker {
/// A type which is considered "not POD", meaning that it is not
/// implicitly copyable. This is typically embedded in other types to
/// ensure that they are never copied, even if they lack a destructor.
#[cfg(not(stage0))]
#[lang="no_copy_bound"]
#[deriving(Eq,Clone)]
pub struct NoCopy;
/// A type which is considered "not POD", meaning that it is not
/// implicitly copyable. This is typically embedded in other types to
/// ensure that they are never copied, even if they lack a destructor.
#[cfg(stage0)]
#[lang="no_pod_bound"]
#[deriving(Eq,Clone)]
pub struct NoPod;
pub struct NoCopy;
/// A type which is considered "not sharable", meaning that
/// its contents are not threadsafe, hence they cannot be

View File

@ -79,7 +79,7 @@ pub fn pref_align_of_val<T>(_val: &T) -> uint {
/// Create a value initialized to zero.
///
/// `init` is unsafe because it returns a zeroed-out datum,
/// which is unsafe unless T is Pod.
/// which is unsafe unless T is Copy.
#[inline]
pub unsafe fn init<T>() -> T {
intrinsics::init()

View File

@ -17,7 +17,7 @@
use clone::Clone;
use cmp::{Eq, Ord};
use kinds::Pod;
use kinds::Copy;
use mem::size_of;
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
@ -276,7 +276,7 @@ pub trait Bitwise: Bounded
/// Specifies the available operations common to all of Rust's core numeric primitives.
/// These may not always make sense from a purely mathematical point of view, but
/// may be useful for systems programming.
pub trait Primitive: Pod
pub trait Primitive: Copy
+ Clone
+ Num
+ NumCast

View File

@ -684,7 +684,7 @@ mod tests {
#[test] #[should_fail]
fn test_option_too_much_dance() {
let mut y = Some(marker::NoPod);
let mut y = Some(marker::NoCopy);
let _y2 = y.take_unwrap();
let _y3 = y.take_unwrap();
}

View File

@ -20,7 +20,7 @@ generally useful to many Rust programs.
*/
// Reexported core operators
pub use kinds::{Pod, Send, Sized, Share};
pub use kinds::{Copy, Send, Sized, Share};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop, Deref, DerefMut};

View File

@ -2304,12 +2304,12 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
MutItems{ptr: p,
end: (p as uint + self.len()) as *mut T,
marker: marker::ContravariantLifetime::<'a>,
marker2: marker::NoPod}
marker2: marker::NoCopy}
} else {
MutItems{ptr: p,
end: p.offset(self.len() as int),
marker: marker::ContravariantLifetime::<'a>,
marker2: marker::NoPod}
marker2: marker::NoCopy}
}
}
}
@ -2670,7 +2670,7 @@ pub struct MutItems<'a, T> {
priv ptr: *mut T,
priv end: *mut T,
priv marker: marker::ContravariantLifetime<'a>,
priv marker2: marker::NoPod
priv marker2: marker::NoCopy
}
macro_rules! iterator {

View File

@ -117,25 +117,25 @@ use ty::Unsafe;
/// An atomic boolean type.
pub struct AtomicBool {
priv v: Unsafe<uint>,
priv nopod: marker::NoPod
priv nocopy: marker::NoCopy
}
/// A signed atomic integer type, supporting basic atomic arithmetic operations
pub struct AtomicInt {
priv v: Unsafe<int>,
priv nopod: marker::NoPod
priv nocopy: marker::NoCopy
}
/// An unsigned atomic integer type, supporting basic atomic arithmetic operations
pub struct AtomicUint {
priv v: Unsafe<uint>,
priv nopod: marker::NoPod
priv nocopy: marker::NoCopy
}
/// An unsafe atomic pointer. Only supports basic atomic operations
pub struct AtomicPtr<T> {
priv p: Unsafe<uint>,
priv nopod: marker::NoPod
priv nocopy: marker::NoCopy
}
/// An atomic, nullable unique pointer
@ -180,15 +180,15 @@ pub enum Ordering {
/// An `AtomicBool` initialized to `false`
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: Unsafe{value: 0,
marker1: marker::InvariantType},
nopod: marker::NoPod };
nocopy: marker::NoCopy };
/// An `AtomicInt` initialized to `0`
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: Unsafe{value: 0,
marker1: marker::InvariantType},
nopod: marker::NoPod };
nocopy: marker::NoCopy };
/// An `AtomicUint` initialized to `0`
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: Unsafe{value: 0,
marker1: marker::InvariantType},
nopod: marker::NoPod };
nocopy: marker::NoCopy };
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
static UINT_TRUE: uint = -1;
@ -197,7 +197,7 @@ impl AtomicBool {
/// Create a new `AtomicBool`
pub fn new(v: bool) -> AtomicBool {
let val = if v { UINT_TRUE } else { 0 };
AtomicBool { v: Unsafe::new(val), nopod: marker::NoPod }
AtomicBool { v: Unsafe::new(val), nocopy: marker::NoCopy }
}
/// Load the value
@ -400,7 +400,7 @@ impl AtomicBool {
impl AtomicInt {
/// Create a new `AtomicInt`
pub fn new(v: int) -> AtomicInt {
AtomicInt {v: Unsafe::new(v), nopod: marker::NoPod}
AtomicInt {v: Unsafe::new(v), nocopy: marker::NoCopy}
}
/// Load the value
@ -467,7 +467,7 @@ impl AtomicInt {
impl AtomicUint {
/// Create a new `AtomicUint`
pub fn new(v: uint) -> AtomicUint {
AtomicUint { v: Unsafe::new(v), nopod: marker::NoPod }
AtomicUint { v: Unsafe::new(v), nocopy: marker::NoCopy }
}
/// Load the value
@ -534,7 +534,7 @@ impl AtomicUint {
impl<T> AtomicPtr<T> {
/// Create a new `AtomicPtr`
pub fn new(p: *mut T) -> AtomicPtr<T> {
AtomicPtr { p: Unsafe::new(p as uint), nopod: marker::NoPod }
AtomicPtr { p: Unsafe::new(p as uint), nocopy: marker::NoCopy }
}
/// Load the value

View File

@ -87,7 +87,7 @@ pub struct TaskBuilder {
/// Options to spawn the new task with
opts: TaskOpts,
priv gen_body: Option<proc:Send(v: proc:Send()) -> proc:Send()>,
priv nopod: Option<marker::NoPod>,
priv nocopy: Option<marker::NoCopy>,
}
/**
@ -98,7 +98,7 @@ pub fn task() -> TaskBuilder {
TaskBuilder {
opts: TaskOpts::new(),
gen_body: None,
nopod: None,
nocopy: None,
}
}

View File

@ -192,7 +192,7 @@ impl Sem<Vec<WaitQueue>> {
pub fn access_cond<'a>(&'a self) -> SemCondGuard<'a> {
SemCondGuard {
guard: self.access(),
cvar: Condvar { sem: self, order: Nothing, nopod: marker::NoPod },
cvar: Condvar { sem: self, order: Nothing, nocopy: marker::NoCopy },
}
}
}
@ -218,7 +218,7 @@ pub struct Condvar<'a> {
// See the comment in write_cond for more detail.
priv order: ReacquireOrderLock<'a>,
// Make sure condvars are non-copyable.
priv nopod: marker::NoPod,
priv nocopy: marker::NoCopy,
}
impl<'a> Condvar<'a> {
@ -565,7 +565,7 @@ impl RWLock {
cond: Condvar {
sem: &self.access_lock,
order: Just(&self.order_lock),
nopod: marker::NoPod,
nocopy: marker::NoCopy,
}
}
}

View File

@ -68,7 +68,7 @@ impl<'a> Iterator<PathElem> for LinkedPath<'a> {
#[deriving(Clone)]
pub struct Values<'a, T>(slice::Items<'a, T>);
impl<'a, T: Pod> Iterator<T> for Values<'a, T> {
impl<'a, T: Copy> Iterator<T> for Values<'a, T> {
fn next(&mut self) -> Option<T> {
let &Values(ref mut items) = self;
items.next().map(|&x| x)

View File

@ -306,7 +306,7 @@ pub fn Parser<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig, rdr: ~Reader:)
obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(),
open_braces: Vec::new(),
nopod: marker::NoPod
nocopy: marker::NoCopy
}
}
@ -337,7 +337,7 @@ pub struct Parser<'a> {
/// Stack of spans of open delimiters. Used for error message.
open_braces: Vec<Span> ,
/* do not copy the parser; its state is tied to outside state */
priv nopod: marker::NoPod
priv nocopy: marker::NoCopy
}
fn is_plain_ident_or_underscore(t: &token::Token) -> bool {

View File

@ -11,9 +11,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that metadata serialization works for the `Pod` kind.
// Tests that metadata serialization works for the `Copy` kind.
#[crate_type="lib"];
pub fn f<T:Pod>() {}
pub fn f<T:Copy>() {}

View File

@ -15,4 +15,4 @@
pub trait RequiresShare : Share { }
pub trait RequiresRequiresShareAndSend : RequiresShare + Send { }
pub trait RequiresPod : Pod { }
pub trait RequiresCopy : Copy { }

View File

@ -14,10 +14,10 @@ use std::kinds::marker;
struct Foo {
foo: int,
nopod: marker::NoPod
nocopy: marker::NoCopy
}
static BAR: Foo = Foo{foo: 5, nopod: marker::NoPod};
static BAR: Foo = Foo{foo: 5, nocopy: marker::NoCopy};
fn test(f: Foo) {

View File

@ -11,8 +11,8 @@
// Issue 4691: Ensure that functional-struct-update can only copy, not
// move, when the struct implements Drop.
// NoPod
use NP = std::kinds::marker::NoPod;
// NoCopy
use NP = std::kinds::marker::NoCopy;
struct S { a: int, np: NP }
impl Drop for S { fn drop(&mut self) { } }

View File

@ -0,0 +1,86 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test which of the builtin types are considered POD.
#[feature(managed_boxes)];
use std::rc::Rc;
fn assert_copy<T:Copy>() { }
trait Dummy { }
struct MyStruct {
x: int,
y: int,
}
struct MyNoncopyStruct {
x: ~int,
}
fn test<'a,T,U:Copy>(_: &'a int) {
// lifetime pointers are ok...
assert_copy::<&'static int>();
assert_copy::<&'a int>();
assert_copy::<&'a str>();
assert_copy::<&'a [int]>();
// ...unless they are mutable
assert_copy::<&'static mut int>(); //~ ERROR does not fulfill
assert_copy::<&'a mut int>(); //~ ERROR does not fulfill
// ~ pointers are not ok
assert_copy::<~int>(); //~ ERROR does not fulfill
assert_copy::<~str>(); //~ ERROR does not fulfill
assert_copy::<Vec<int> >(); //~ ERROR does not fulfill
assert_copy::<~&'a mut int>(); //~ ERROR does not fulfill
// borrowed object types are generally ok
assert_copy::<&'a Dummy>();
assert_copy::<&'a Dummy:Copy>();
assert_copy::<&'static Dummy:Copy>();
// owned object types are not ok
assert_copy::<~Dummy>(); //~ ERROR does not fulfill
assert_copy::<~Dummy:Copy>(); //~ ERROR does not fulfill
// mutable object types are not ok
assert_copy::<&'a mut Dummy:Copy>(); //~ ERROR does not fulfill
// closures are like an `&mut` object
assert_copy::<||>(); //~ ERROR does not fulfill
// unsafe ptrs are ok
assert_copy::<*int>();
assert_copy::<*&'a mut int>();
// regular old ints and such are ok
assert_copy::<int>();
assert_copy::<bool>();
assert_copy::<()>();
// tuples are ok
assert_copy::<(int,int)>();
// structs of POD are ok
assert_copy::<MyStruct>();
// structs containing non-POD are not ok
assert_copy::<MyNoncopyStruct>(); //~ ERROR does not fulfill
// managed or ref counted types are not ok
assert_copy::<@int>(); //~ ERROR does not fulfill
assert_copy::<Rc<int>>(); //~ ERROR does not fulfill
}
pub fn main() {
}

View File

@ -1,86 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test which of the builtin types are considered POD.
#[feature(managed_boxes)];
use std::rc::Rc;
fn assert_pod<T:Pod>() { }
trait Dummy { }
struct MyStruct {
x: int,
y: int,
}
struct MyNonpodStruct {
x: ~int,
}
fn test<'a,T,U:Pod>(_: &'a int) {
// lifetime pointers are ok...
assert_pod::<&'static int>();
assert_pod::<&'a int>();
assert_pod::<&'a str>();
assert_pod::<&'a [int]>();
// ...unless they are mutable
assert_pod::<&'static mut int>(); //~ ERROR does not fulfill `Pod`
assert_pod::<&'a mut int>(); //~ ERROR does not fulfill `Pod`
// ~ pointers are not ok
assert_pod::<~int>(); //~ ERROR does not fulfill `Pod`
assert_pod::<~str>(); //~ ERROR does not fulfill `Pod`
assert_pod::<Vec<int> >(); //~ ERROR does not fulfill `Pod`
assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod`
// borrowed object types are generally ok
assert_pod::<&'a Dummy>();
assert_pod::<&'a Dummy:Pod>();
assert_pod::<&'static Dummy:Pod>();
// owned object types are not ok
assert_pod::<~Dummy>(); //~ ERROR does not fulfill `Pod`
assert_pod::<~Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
// mutable object types are not ok
assert_pod::<&'a mut Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
// closures are like an `&mut` object
assert_pod::<||>(); //~ ERROR does not fulfill `Pod`
// unsafe ptrs are ok
assert_pod::<*int>();
assert_pod::<*&'a mut int>();
// regular old ints and such are ok
assert_pod::<int>();
assert_pod::<bool>();
assert_pod::<()>();
// tuples are ok
assert_pod::<(int,int)>();
// structs of POD are ok
assert_pod::<MyStruct>();
// structs containing non-POD are not ok
assert_pod::<MyNonpodStruct>(); //~ ERROR does not fulfill `Pod`
// managed or ref counted types are not ok
assert_pod::<@int>(); //~ ERROR does not fulfill `Pod`
assert_pod::<Rc<int>>(); //~ ERROR does not fulfill `Pod`
}
pub fn main() {
}

View File

@ -10,9 +10,9 @@
use std::kinds::marker;
fn foo<P:Pod>(p: P) { }
fn foo<P:Copy>(p: P) { }
fn main()
{
foo(marker::NoPod); //~ ERROR does not fulfill `Pod`
foo(marker::NoCopy); //~ ERROR does not fulfill
}

View File

@ -14,10 +14,10 @@ use std::kinds::marker;
struct Foo {
foo: int,
nopod: marker::NoPod
nocopy: marker::NoCopy
}
static BAR: Foo = Foo{foo: 5, nopod: marker::NoPod};
static BAR: Foo = Foo{foo: 5, nocopy: marker::NoCopy};
fn test(f: Foo) {

View File

@ -16,7 +16,7 @@
extern crate trait_superkinds_in_metadata;
use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
use trait_superkinds_in_metadata::{RequiresPod};
use trait_superkinds_in_metadata::{RequiresCopy};
struct X<T>(T);
@ -24,6 +24,6 @@ impl <T:Share> RequiresShare for X<T> { }
impl <T:Share+Send> RequiresRequiresShareAndSend for X<T> { }
impl <T:Pod> RequiresPod for X<T> { }
impl <T:Copy> RequiresCopy for X<T> { }
pub fn main() { }

View File

@ -11,11 +11,11 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that type parameters with the `Pod` are implicitly copyable.
// Tests that type parameters with the `Copy` are implicitly copyable.
#[allow(dead_code)];
fn can_copy_pod<T:Pod>(v: T) {
fn can_copy_copy<T:Copy>(v: T) {
let _a = v;
let _b = v;
}

View File

@ -11,14 +11,14 @@
// Issue 4691: Ensure that functional-struct-updates operates
// correctly and moves rather than copy when appropriate.
use NP = std::kinds::marker::NoPod;
use NP = std::kinds::marker::NoCopy;
struct ncint { np: NP, v: int }
fn ncint(v: int) -> ncint { ncint { np: NP, v: v } }
struct NoFoo { copied: int, nopod: ncint, }
struct NoFoo { copied: int, nocopy: ncint, }
impl NoFoo {
fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nopod: ncint(y) } }
fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nocopy: ncint(y) } }
}
struct MoveFoo { copied: int, moved: ~int, }
@ -44,18 +44,18 @@ fn test0() {
// (and thus it is okay that these are Drop; compare against
// compile-fail test: borrowck-struct-update-with-dtor.rs).
// Case 1: Nopodable
// Case 1: Nocopyable
let f = DropNoFoo::new(1, 2);
let b = DropNoFoo { inner: NoFoo { nopod: ncint(3), ..f.inner }};
let c = DropNoFoo { inner: NoFoo { nopod: ncint(4), ..f.inner }};
let b = DropNoFoo { inner: NoFoo { nocopy: ncint(3), ..f.inner }};
let c = DropNoFoo { inner: NoFoo { nocopy: ncint(4), ..f.inner }};
assert_eq!(f.inner.copied, 1);
assert_eq!(f.inner.nopod.v, 2);
assert_eq!(f.inner.nocopy.v, 2);
assert_eq!(b.inner.copied, 1);
assert_eq!(b.inner.nopod.v, 3);
assert_eq!(b.inner.nocopy.v, 3);
assert_eq!(c.inner.copied, 1);
assert_eq!(c.inner.nopod.v, 4);
assert_eq!(c.inner.nocopy.v, 4);
// Case 2: Owned
let f = DropMoveFoo::new(5, 6);
@ -86,12 +86,12 @@ fn test1() {
fn test2() {
// move non-copyable field
let f = NoFoo::new(21, 22);
let b = NoFoo {nopod: ncint(23), ..f};
let b = NoFoo {nocopy: ncint(23), ..f};
let c = NoFoo {copied: 24, ..f};
assert_eq!(b.copied, 21);
assert_eq!(b.nopod.v, 23);
assert_eq!(b.nocopy.v, 23);
assert_eq!(c.copied, 24);
assert_eq!(c.nopod.v, 22);
assert_eq!(c.nocopy.v, 22);
}
pub fn main() {

View File

@ -14,7 +14,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that metadata serialization works for the `Pod` kind.
// Tests that metadata serialization works for the `Copy` kind.
extern crate kinds_in_metadata;