Rename `UniquePtr` to `Unique`

Mostly following the convention in RFC 356
This commit is contained in:
Flavio Percoco 2014-12-22 14:25:58 +01:00
parent 51d2fefd91
commit 7df17a2868
12 changed files with 53 additions and 53 deletions

View File

@ -19,7 +19,7 @@ use core::hash::{mod, Hash};
use core::kinds::Sized;
use core::mem;
use core::option::Option;
use core::ptr::UniquePtr;
use core::ptr::Unique;
use core::raw::TraitObject;
use core::result::Result;
use core::result::Result::{Ok, Err};
@ -45,7 +45,7 @@ pub static HEAP: () = ();
/// A type that represents a uniquely-owned value.
#[lang = "owned_box"]
#[unstable = "custom allocators will add an additional type parameter (with default)"]
pub struct Box<T>(UniquePtr<T>);
pub struct Box<T>(Unique<T>);
#[stable]
impl<T: Default> Default for Box<T> {

View File

@ -58,7 +58,7 @@ use core::kinds::marker::{ContravariantLifetime, InvariantType};
use core::mem;
use core::num::{Int, UnsignedInt};
use core::ops;
use core::ptr::{mod, UniquePtr};
use core::ptr::{mod, Unique};
use core::raw::Slice as RawSlice;
use core::uint;
@ -133,7 +133,7 @@ use slice::CloneSliceExt;
#[unsafe_no_drop_flag]
#[stable]
pub struct Vec<T> {
ptr: UniquePtr<T>,
ptr: Unique<T>,
len: uint,
cap: uint,
}
@ -176,7 +176,7 @@ impl<T> Vec<T> {
// non-null value which is fine since we never call deallocate on the ptr
// if cap is 0. The reason for this is because the pointer of a slice
// being NULL would break the null pointer optimization for enums.
Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: 0 }
Vec { ptr: Unique(EMPTY as *mut T), len: 0, cap: 0 }
}
/// Constructs a new, empty `Vec<T>` with the specified capacity.
@ -209,7 +209,7 @@ impl<T> Vec<T> {
#[stable]
pub fn with_capacity(capacity: uint) -> Vec<T> {
if mem::size_of::<T>() == 0 {
Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: uint::MAX }
Vec { ptr: Unique(EMPTY as *mut T), len: 0, cap: uint::MAX }
} else if capacity == 0 {
Vec::new()
} else {
@ -217,7 +217,7 @@ impl<T> Vec<T> {
.expect("capacity overflow");
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
if ptr.is_null() { ::alloc::oom() }
Vec { ptr: UniquePtr(ptr as *mut T), len: 0, cap: capacity }
Vec { ptr: Unique(ptr as *mut T), len: 0, cap: capacity }
}
}
@ -284,7 +284,7 @@ impl<T> Vec<T> {
#[unstable = "needs finalization"]
pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
capacity: uint) -> Vec<T> {
Vec { ptr: UniquePtr(ptr), len: length, cap: capacity }
Vec { ptr: Unique(ptr), len: length, cap: capacity }
}
/// Creates a vector by copying the elements from a raw pointer.
@ -803,7 +803,7 @@ impl<T> Vec<T> {
unsafe {
// Overflow check is unnecessary as the vector is already at
// least this large.
self.ptr = UniquePtr(reallocate(self.ptr.0 as *mut u8,
self.ptr = Unique(reallocate(self.ptr.0 as *mut u8,
self.cap * mem::size_of::<T>(),
self.len * mem::size_of::<T>(),
mem::min_align_of::<T>()) as *mut T);
@ -1110,7 +1110,7 @@ impl<T> Vec<T> {
let size = max(old_size, 2 * mem::size_of::<T>()) * 2;
if old_size > size { panic!("capacity overflow") }
unsafe {
self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0, old_size, size));
self.ptr = Unique(alloc_or_realloc(self.ptr.0, old_size, size));
if self.ptr.0.is_null() { ::alloc::oom() }
}
self.cap = max(self.cap, 2) * 2;
@ -1231,7 +1231,7 @@ impl<T> Vec<T> {
let size = capacity.checked_mul(mem::size_of::<T>())
.expect("capacity overflow");
unsafe {
self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0,
self.ptr = Unique(alloc_or_realloc(self.ptr.0,
self.cap * mem::size_of::<T>(),
size));
if self.ptr.0.is_null() { ::alloc::oom() }
@ -1420,7 +1420,7 @@ impl<T> IntoIter<T> {
for _x in self { }
let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self;
mem::forget(self);
Vec { ptr: UniquePtr(allocation), cap: cap, len: 0 }
Vec { ptr: Unique(allocation), cap: cap, len: 0 }
}
}

View File

@ -505,28 +505,28 @@ impl<T> PartialOrd for *mut T {
/// A wrapper around a raw `*mut T` that indicates that the possessor
/// of this wrapper owns the referent. This in turn implies that the
/// `UniquePtr<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
/// `Unique<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
/// raw `*mut T` (which conveys no particular ownership semantics).
/// Useful for building abstractions like `Vec<T>` or `Box<T>`, which
/// internally use raw pointers to manage the memory that they own.
pub struct UniquePtr<T>(pub *mut T);
pub struct Unique<T>(pub *mut T);
/// `UniquePtr` pointers are `Send` if `T` is `Send` because the data they
/// `Unique` pointers are `Send` if `T` is `Send` because the data they
/// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the
/// `UniquePtr` must enforce it.
unsafe impl<T:Send> Send for UniquePtr<T> { }
/// `Unique` must enforce it.
unsafe impl<T:Send> Send for Unique<T> { }
/// `UniquePtr` pointers are `Sync` if `T` is `Sync` because the data they
/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
/// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the
/// `UniquePtr` must enforce it.
unsafe impl<T:Sync> Sync for UniquePtr<T> { }
/// `Unique` must enforce it.
unsafe impl<T:Sync> Sync for Unique<T> { }
impl<T> UniquePtr<T> {
/// Returns a null UniquePtr.
pub fn null() -> UniquePtr<T> {
UniquePtr(RawPtr::null())
impl<T> Unique<T> {
/// Returns a null Unique.
pub fn null() -> Unique<T> {
Unique(RawPtr::null())
}
/// Return an (unsafe) pointer into the memory owned by `self`.

View File

@ -29,7 +29,7 @@ extern crate libc;
use libc::{c_void, size_t, c_int};
use std::c_vec::CVec;
use std::ptr::UniquePtr;
use std::ptr::Unique;
#[link(name = "miniz", kind = "static")]
extern {
@ -60,7 +60,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
&mut outsz,
flags);
if !res.is_null() {
let res = UniquePtr(res);
let res = Unique(res);
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0)))
} else {
None
@ -86,7 +86,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
&mut outsz,
flags);
if !res.is_null() {
let res = UniquePtr(res);
let res = Unique(res);
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0)))
} else {
None

View File

@ -113,7 +113,7 @@ pub struct Upvar {
// different kinds of pointers:
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)]
pub enum PointerKind {
UniquePtr,
Unique,
BorrowedPtr(ty::BorrowKind, ty::Region),
Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr.
UnsafePtr(ast::Mutability)
@ -199,7 +199,7 @@ pub fn opt_deref_kind(t: Ty) -> Option<deref_kind> {
match t.sty {
ty::ty_uniq(_) |
ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
Some(deref_ptr(UniquePtr))
Some(deref_ptr(Unique))
}
ty::ty_rptr(r, mt) => {
@ -315,7 +315,7 @@ impl MutabilityCategory {
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
ptr: PointerKind) -> MutabilityCategory {
match ptr {
UniquePtr => {
Unique => {
base_mutbl.inherit()
}
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
@ -1351,7 +1351,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
Implicit(..) => {
"dereference (dereference is implicit, due to indexing)".to_string()
}
UniquePtr => format!("dereference of `{}`", ptr_sigil(pk)),
Unique => format!("dereference of `{}`", ptr_sigil(pk)),
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
}
}
@ -1412,7 +1412,7 @@ impl<'tcx> cmt_<'tcx> {
}
cat_downcast(ref b, _) |
cat_interior(ref b, _) |
cat_deref(ref b, _, UniquePtr) => {
cat_deref(ref b, _, Unique) => {
b.guarantor()
}
}
@ -1431,7 +1431,7 @@ impl<'tcx> cmt_<'tcx> {
cat_deref(ref b, _, BorrowedPtr(ty::UniqueImmBorrow, _)) |
cat_deref(ref b, _, Implicit(ty::UniqueImmBorrow, _)) |
cat_downcast(ref b, _) |
cat_deref(ref b, _, UniquePtr) |
cat_deref(ref b, _, Unique) |
cat_interior(ref b, _) => {
// Aliasability depends on base cmt
b.freely_aliasable(ctxt)
@ -1523,7 +1523,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> {
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
match ptr {
UniquePtr => "Box",
Unique => "Box",
BorrowedPtr(ty::ImmBorrow, _) |
Implicit(ty::ImmBorrow, _) => "&",
BorrowedPtr(ty::MutBorrow, _) |

View File

@ -33,11 +33,11 @@ use std::rc::Rc;
// FIXME (#16118): These functions are intended to allow the borrow checker to
// be less precise in its handling of Box while still allowing moves out of a
// Box. They should be removed when UniquePtr is removed from LoanPath.
// Box. They should be removed when Unique is removed from LoanPath.
fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<'tcx> {
//! Returns the base of the leftmost dereference of an UniquePtr in
//! `loan_path`. If there is no dereference of an UniquePtr in `loan_path`,
//! Returns the base of the leftmost dereference of an Unique in
//! `loan_path`. If there is no dereference of an Unique in `loan_path`,
//! then it just returns `loan_path` itself.
return match helper(loan_path) {
@ -48,7 +48,7 @@ fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<
fn helper<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> Option<&'a LoanPath<'tcx>> {
match loan_path.kind {
LpVar(_) | LpUpvar(_) => None,
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => {
match helper(&**lp_base) {
v @ Some(_) => v,
None => Some(&**lp_base)
@ -72,7 +72,7 @@ fn owned_ptr_base_path_rc<'tcx>(loan_path: &Rc<LoanPath<'tcx>>) -> Rc<LoanPath<'
fn helper<'tcx>(loan_path: &Rc<LoanPath<'tcx>>) -> Option<Rc<LoanPath<'tcx>>> {
match loan_path.kind {
LpVar(_) | LpUpvar(_) => None,
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => {
match helper(lp_base) {
v @ Some(_) => v,
None => Some(lp_base.clone())
@ -880,7 +880,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
}
}
mc::cat_deref(b, _, mc::UniquePtr) => {
mc::cat_deref(b, _, mc::Unique) => {
assert_eq!(cmt.mutbl, mc::McInherited);
cmt = b;
}

View File

@ -291,9 +291,9 @@ fn add_fragment_siblings<'tcx>(this: &MoveData<'tcx>,
add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id);
}
// *LV for UniquePtr consumes the contents of the box (at
// *LV for Unique consumes the contents of the box (at
// least when it is non-copy...), so propagate inward.
LpExtend(ref loan_parent, _, LpDeref(mc::UniquePtr)) => {
LpExtend(ref loan_parent, _, LpDeref(mc::Unique)) => {
add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id);
}

View File

@ -190,7 +190,7 @@ fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
}
}
mc::cat_deref(ref b, _, mc::UniquePtr) => {
mc::cat_deref(ref b, _, mc::Unique) => {
check_and_get_illegal_move_origin(bccx, b)
}
}

View File

@ -84,7 +84,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
}
mc::cat_downcast(ref base, _) |
mc::cat_deref(ref base, _, mc::UniquePtr) | // L-Deref-Send
mc::cat_deref(ref base, _, mc::Unique) | // L-Deref-Send
mc::cat_interior(ref base, _) => { // L-Field
self.check(base, discr_scope)
}
@ -129,7 +129,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
r
}
mc::cat_downcast(ref cmt, _) |
mc::cat_deref(ref cmt, _, mc::UniquePtr) |
mc::cat_deref(ref cmt, _, mc::Unique) |
mc::cat_interior(ref cmt, _) => {
self.scope(cmt)
}

View File

@ -107,7 +107,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
mc::cat_deref(cmt_base, _, pk) => {
match pk {
mc::UniquePtr => {
mc::Unique => {
// R-Deref-Send-Pointer
//
// When we borrow the interior of an owned pointer, we

View File

@ -1460,7 +1460,7 @@ fn link_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
}
mc::cat_downcast(cmt_base, _) |
mc::cat_deref(cmt_base, _, mc::UniquePtr) |
mc::cat_deref(cmt_base, _, mc::Unique) |
mc::cat_interior(cmt_base, _) => {
// Borrowing interior or owned data requires the base
// to be valid and borrowable in the same fashion.
@ -1684,7 +1684,7 @@ fn adjust_upvar_borrow_kind_for_mut<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
cmt.repr(rcx.tcx()));
match cmt.cat.clone() {
mc::cat_deref(base, _, mc::UniquePtr) |
mc::cat_deref(base, _, mc::Unique) |
mc::cat_interior(base, _) |
mc::cat_downcast(base, _) => {
// Interior or owned data is mutable if base is
@ -1731,7 +1731,7 @@ fn adjust_upvar_borrow_kind_for_unique<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, cmt: mc::c
cmt.repr(rcx.tcx()));
match cmt.cat.clone() {
mc::cat_deref(base, _, mc::UniquePtr) |
mc::cat_deref(base, _, mc::Unique) |
mc::cat_interior(base, _) |
mc::cat_downcast(base, _) => {
// Interior or owned data is unique if base is

View File

@ -23,7 +23,7 @@ use num::{Int, UnsignedInt};
use ops::{Deref, DerefMut, Drop};
use option::Option;
use option::Option::{Some, None};
use ptr::{UniquePtr, RawPtr, copy_nonoverlapping_memory, zero_memory};
use ptr::{Unique, RawPtr, copy_nonoverlapping_memory, zero_memory};
use ptr;
use rt::heap::{allocate, deallocate};
@ -69,7 +69,7 @@ const EMPTY_BUCKET: u64 = 0u64;
pub struct RawTable<K, V> {
capacity: uint,
size: uint,
hashes: UniquePtr<u64>,
hashes: Unique<u64>,
// Because K/V do not appear directly in any of the types in the struct,
// inform rustc that in fact instances of K and V are reachable from here.
marker: marker::CovariantType<(K,V)>,
@ -563,7 +563,7 @@ impl<K, V> RawTable<K, V> {
return RawTable {
size: 0,
capacity: 0,
hashes: UniquePtr::null(),
hashes: Unique::null(),
marker: marker::CovariantType,
};
}
@ -602,7 +602,7 @@ impl<K, V> RawTable<K, V> {
RawTable {
capacity: capacity,
size: 0,
hashes: UniquePtr(hashes),
hashes: Unique(hashes),
marker: marker::CovariantType,
}
}