Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
flaper87 committed Mar 28, 2014
1 parent ff64381 commit 81ec1f3
Show file tree
Hide file tree
Showing 35 changed files with 233 additions and 218 deletions.
2 changes: 1 addition & 1 deletion src/doc/guide-unsafe.md
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rust.md
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/etc/vim/syntax/rust.vim
Expand Up @@ -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
Expand Down
78 changes: 39 additions & 39 deletions src/libarena/lib.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>>,
}

Expand All @@ -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),
}
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -173,61 +173,61 @@ 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);
}
}

// 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());
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
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;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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(|| {
Expand All @@ -544,48 +544,48 @@ 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 ),
});
}
}

#[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 ),
})
})
}

#[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 ),
}
})
}

#[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 ),
})
Expand Down
14 changes: 7 additions & 7 deletions src/libcollections/hashmap.rs
Expand Up @@ -110,15 +110,15 @@ 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
/// in it.
pub struct FullIndex {
priv idx: int,
priv hash: SafeHash,
priv nopod: marker::NoPod,
priv nocopy: marker::NoCopy,
}

impl FullIndex {
Expand Down Expand Up @@ -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,
})
}
}
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tydecode.rs
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Expand Up @@ -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"),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/lang_items.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

5 comments on commit 81ec1f3

@bors
Copy link
Contributor

@bors bors commented on 81ec1f3 Mar 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at flaper87@81ec1f3

@bors
Copy link
Contributor

@bors bors commented on 81ec1f3 Mar 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging FlaPer87/rust/rename-pod = 81ec1f3 into auto

@bors
Copy link
Contributor

@bors bors commented on 81ec1f3 Mar 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlaPer87/rust/rename-pod = 81ec1f3 merged ok, testing candidate = b8601a3

@bors
Copy link
Contributor

@bors bors commented on 81ec1f3 Mar 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 81ec1f3 Mar 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b8601a3

Please sign in to comment.