Rename OwnedPtr
to UniquePtr
This commit is contained in:
parent
fb803a8570
commit
686ce664da
@ -19,7 +19,7 @@ use core::hash::{mod, Hash};
|
||||
use core::kinds::Sized;
|
||||
use core::mem;
|
||||
use core::option::Option;
|
||||
use core::ptr::OwnedPtr;
|
||||
use core::ptr::UniquePtr;
|
||||
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>(OwnedPtr<T>);
|
||||
pub struct Box<T>(UniquePtr<T>);
|
||||
|
||||
#[stable]
|
||||
impl<T: Default> Default for Box<T> {
|
||||
|
@ -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, OwnedPtr};
|
||||
use core::ptr::{mod, UniquePtr};
|
||||
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: OwnedPtr<T>,
|
||||
ptr: UniquePtr<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: OwnedPtr(EMPTY as *mut T), len: 0, cap: 0 }
|
||||
Vec { ptr: UniquePtr(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: OwnedPtr(EMPTY as *mut T), len: 0, cap: uint::MAX }
|
||||
Vec { ptr: UniquePtr(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: OwnedPtr(ptr as *mut T), len: 0, cap: capacity }
|
||||
Vec { ptr: UniquePtr(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: OwnedPtr(ptr), len: length, cap: capacity }
|
||||
Vec { ptr: UniquePtr(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 = OwnedPtr(reallocate(self.ptr.0 as *mut u8,
|
||||
self.ptr = UniquePtr(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 = OwnedPtr(alloc_or_realloc(self.ptr.0, old_size, size));
|
||||
self.ptr = UniquePtr(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 = OwnedPtr(alloc_or_realloc(self.ptr.0,
|
||||
self.ptr = UniquePtr(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: OwnedPtr(allocation), cap: cap, len: 0 }
|
||||
Vec { ptr: UniquePtr(allocation), cap: cap, len: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
/// `OwnedPtr<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
|
||||
/// `UniquePtr<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 OwnedPtr<T>(pub *mut T);
|
||||
pub struct UniquePtr<T>(pub *mut T);
|
||||
|
||||
/// `OwnedPtr` pointers are `Send` if `T` is `Send` because the data they
|
||||
/// `UniquePtr` 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
|
||||
/// `OwnedPtr` must enforce it.
|
||||
impl<T:Send> Send for OwnedPtr<T> { }
|
||||
/// `UniquePtr` must enforce it.
|
||||
impl<T:Send> Send for UniquePtr<T> { }
|
||||
|
||||
/// `OwnedPtr` pointers are `Sync` if `T` is `Sync` because the data they
|
||||
/// `UniquePtr` 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
|
||||
/// `OwnedPtr` must enforce it.
|
||||
impl<T:Sync> Sync for OwnedPtr<T> { }
|
||||
/// `UniquePtr` must enforce it.
|
||||
impl<T:Sync> Sync for UniquePtr<T> { }
|
||||
|
||||
impl<T> OwnedPtr<T> {
|
||||
/// Returns a null OwnedPtr.
|
||||
pub fn null() -> OwnedPtr<T> {
|
||||
OwnedPtr(RawPtr::null())
|
||||
impl<T> UniquePtr<T> {
|
||||
/// Returns a null UniquePtr.
|
||||
pub fn null() -> UniquePtr<T> {
|
||||
UniquePtr(RawPtr::null())
|
||||
}
|
||||
|
||||
/// Return an (unsafe) pointer into the memory owned by `self`.
|
||||
|
@ -29,7 +29,7 @@ extern crate libc;
|
||||
|
||||
use libc::{c_void, size_t, c_int};
|
||||
use std::c_vec::CVec;
|
||||
use std::ptr::OwnedPtr;
|
||||
use std::ptr::UniquePtr;
|
||||
|
||||
#[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 = OwnedPtr(res);
|
||||
let res = UniquePtr(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 = OwnedPtr(res);
|
||||
let res = UniquePtr(res);
|
||||
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0)))
|
||||
} else {
|
||||
None
|
||||
|
@ -113,7 +113,7 @@ pub struct Upvar {
|
||||
// different kinds of pointers:
|
||||
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)]
|
||||
pub enum PointerKind {
|
||||
OwnedPtr,
|
||||
UniquePtr,
|
||||
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(OwnedPtr))
|
||||
Some(deref_ptr(UniquePtr))
|
||||
}
|
||||
|
||||
ty::ty_rptr(r, mt) => {
|
||||
@ -315,7 +315,7 @@ impl MutabilityCategory {
|
||||
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
|
||||
ptr: PointerKind) -> MutabilityCategory {
|
||||
match ptr {
|
||||
OwnedPtr => {
|
||||
UniquePtr => {
|
||||
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()
|
||||
}
|
||||
OwnedPtr => format!("dereference of `{}`", ptr_sigil(pk)),
|
||||
UniquePtr => 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, _, OwnedPtr) => {
|
||||
cat_deref(ref b, _, UniquePtr) => {
|
||||
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, _, OwnedPtr) |
|
||||
cat_deref(ref b, _, UniquePtr) |
|
||||
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 {
|
||||
OwnedPtr => "Box",
|
||||
UniquePtr => "Box",
|
||||
BorrowedPtr(ty::ImmBorrow, _) |
|
||||
Implicit(ty::ImmBorrow, _) => "&",
|
||||
BorrowedPtr(ty::MutBorrow, _) |
|
||||
|
@ -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 OwnedPtr is removed from LoanPath.
|
||||
// Box. They should be removed when UniquePtr 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 OwnedPtr in
|
||||
//! `loan_path`. If there is no dereference of an OwnedPtr in `loan_path`,
|
||||
//! Returns the base of the leftmost dereference of an UniquePtr in
|
||||
//! `loan_path`. If there is no dereference of an UniquePtr 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::OwnedPtr)) => {
|
||||
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
|
||||
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::OwnedPtr)) => {
|
||||
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
|
||||
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::OwnedPtr) => {
|
||||
mc::cat_deref(b, _, mc::UniquePtr) => {
|
||||
assert_eq!(cmt.mutbl, mc::McInherited);
|
||||
cmt = b;
|
||||
}
|
||||
|
@ -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 OwnedPtr consumes the contents of the box (at
|
||||
// *LV for UniquePtr consumes the contents of the box (at
|
||||
// least when it is non-copy...), so propagate inward.
|
||||
LpExtend(ref loan_parent, _, LpDeref(mc::OwnedPtr)) => {
|
||||
LpExtend(ref loan_parent, _, LpDeref(mc::UniquePtr)) => {
|
||||
add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
||||
}
|
||||
}
|
||||
|
||||
mc::cat_deref(ref b, _, mc::OwnedPtr) => {
|
||||
mc::cat_deref(ref b, _, mc::UniquePtr) => {
|
||||
check_and_get_illegal_move_origin(bccx, b)
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
mc::cat_downcast(ref base, _) |
|
||||
mc::cat_deref(ref base, _, mc::OwnedPtr) | // L-Deref-Send
|
||||
mc::cat_deref(ref base, _, mc::UniquePtr) | // 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::OwnedPtr) |
|
||||
mc::cat_deref(ref cmt, _, mc::UniquePtr) |
|
||||
mc::cat_interior(ref cmt, _) => {
|
||||
self.scope(cmt)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
|
||||
|
||||
mc::cat_deref(cmt_base, _, pk) => {
|
||||
match pk {
|
||||
mc::OwnedPtr => {
|
||||
mc::UniquePtr => {
|
||||
// R-Deref-Send-Pointer
|
||||
//
|
||||
// When we borrow the interior of an owned pointer, we
|
||||
|
@ -1460,7 +1460,7 @@ fn link_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
|
||||
}
|
||||
|
||||
mc::cat_downcast(cmt_base, _) |
|
||||
mc::cat_deref(cmt_base, _, mc::OwnedPtr) |
|
||||
mc::cat_deref(cmt_base, _, mc::UniquePtr) |
|
||||
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::OwnedPtr) |
|
||||
mc::cat_deref(base, _, mc::UniquePtr) |
|
||||
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::OwnedPtr) |
|
||||
mc::cat_deref(base, _, mc::UniquePtr) |
|
||||
mc::cat_interior(base, _) |
|
||||
mc::cat_downcast(base, _) => {
|
||||
// Interior or owned data is unique if base is
|
||||
|
@ -23,7 +23,7 @@ use num::{Int, UnsignedInt};
|
||||
use ops::{Deref, DerefMut, Drop};
|
||||
use option::Option;
|
||||
use option::Option::{Some, None};
|
||||
use ptr::{OwnedPtr, RawPtr, copy_nonoverlapping_memory, zero_memory};
|
||||
use ptr::{UniquePtr, 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: OwnedPtr<u64>,
|
||||
hashes: UniquePtr<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: OwnedPtr::null(),
|
||||
hashes: UniquePtr::null(),
|
||||
marker: marker::CovariantType,
|
||||
};
|
||||
}
|
||||
@ -602,7 +602,7 @@ impl<K, V> RawTable<K, V> {
|
||||
RawTable {
|
||||
capacity: capacity,
|
||||
size: 0,
|
||||
hashes: OwnedPtr(hashes),
|
||||
hashes: UniquePtr(hashes),
|
||||
marker: marker::CovariantType,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user