rename RcBox in other places too
This commit is contained in:
parent
159e67d446
commit
0a9c87b1f5
@ -992,10 +992,10 @@ fn codegen_call_terminator(
|
||||
match op.val {
|
||||
Pair(data_ptr, meta) => {
|
||||
// In the case of Rc<Self>, we need to explicitly pass a
|
||||
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
|
||||
// *mut RcInner<Self> with a Scalar (not ScalarPair) ABI. This is a hack
|
||||
// that is understood elsewhere in the compiler as a method on
|
||||
// `dyn Trait`.
|
||||
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
|
||||
// To get a `*mut RcInner<Self>`, we just keep unwrapping newtypes until
|
||||
// we get a value of a built-in pointer type.
|
||||
//
|
||||
// This is also relevant for `Pin<&mut Self>`, where we need to peel the
|
||||
|
@ -822,10 +822,10 @@ fn make_thin_self_ptr<'tcx>(
|
||||
_ => bug!("receiver type has unsupported layout: {:?}", layout),
|
||||
}
|
||||
|
||||
// In the case of Rc<Self>, we need to explicitly pass a *mut RcBox<Self>
|
||||
// In the case of Rc<Self>, we need to explicitly pass a *mut RcInner<Self>
|
||||
// with a Scalar (not ScalarPair) ABI. This is a hack that is understood
|
||||
// elsewhere in the compiler as a method on a `dyn Trait`.
|
||||
// To get the type `*mut RcBox<Self>`, we just keep unwrapping newtypes until we
|
||||
// To get the type `*mut RcInner<Self>`, we just keep unwrapping newtypes until we
|
||||
// get a built-in pointer type
|
||||
let mut wide_pointer_layout = layout;
|
||||
while !wide_pointer_layout.ty.is_unsafe_ptr() && !wide_pointer_layout.ty.is_ref() {
|
||||
@ -838,7 +838,7 @@ fn make_thin_self_ptr<'tcx>(
|
||||
wide_pointer_layout.ty
|
||||
};
|
||||
|
||||
// we now have a type like `*mut RcBox<dyn Trait>`
|
||||
// we now have a type like `*mut RcInner<dyn Trait>`
|
||||
// change its layout to that of `*mut ()`, a thin pointer, but keep the same type
|
||||
// this is understood as a special case elsewhere in the compiler
|
||||
let unit_ptr_ty = Ty::new_mut_ptr(tcx, tcx.types.unit);
|
||||
|
@ -319,7 +319,7 @@ pub struct Weak<
|
||||
// but it is not necessarily a valid pointer.
|
||||
// `Weak::new` sets this to `usize::MAX` so that it doesn’t need
|
||||
// to allocate space on the heap. That's not a value a real pointer
|
||||
// will ever have because RcBox has alignment at least 2.
|
||||
// will ever have because RcInner has alignment at least 2.
|
||||
// This is only possible when `T: Sized`; unsized `T` never dangle.
|
||||
ptr: NonNull<ArcInner<T>>,
|
||||
alloc: A,
|
||||
@ -1581,7 +1581,7 @@ pub fn into_raw_with_allocator(this: Self) -> (*const T, A) {
|
||||
pub fn as_ptr(this: &Self) -> *const T {
|
||||
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
|
||||
|
||||
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because
|
||||
// SAFETY: This cannot go through Deref::deref or RcInnerPtr::inner because
|
||||
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
|
||||
// write through the pointer after the Rc is recovered through `from_raw`.
|
||||
unsafe { &raw mut (*ptr).data }
|
||||
@ -2936,7 +2936,7 @@ pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self {
|
||||
// Otherwise, we're guaranteed the pointer came from a nondangling Weak.
|
||||
// SAFETY: data_offset is safe to call, as ptr references a real (potentially dropped) T.
|
||||
let offset = unsafe { data_offset(ptr) };
|
||||
// Thus, we reverse the offset to get the whole RcBox.
|
||||
// Thus, we reverse the offset to get the whole RcInner.
|
||||
// SAFETY: the pointer originated from a Weak, so this offset is safe.
|
||||
unsafe { ptr.byte_sub(offset) as *mut ArcInner<T> }
|
||||
};
|
||||
@ -3861,7 +3861,7 @@ impl<T: ?Sized, A: Allocator> Unpin for Arc<T, A> {}
|
||||
/// valid instance of T, but the T is allowed to be dropped.
|
||||
unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> usize {
|
||||
// Align the unsized value to the end of the ArcInner.
|
||||
// Because RcBox is repr(C), it will always be the last field in memory.
|
||||
// Because RcInner is repr(C), it will always be the last field in memory.
|
||||
// SAFETY: since the only unsized types possible are slices, trait objects,
|
||||
// and extern types, the input safety requirement is currently enough to
|
||||
// satisfy the requirements of align_of_val_raw; this is an implementation
|
||||
|
@ -193,11 +193,11 @@
|
||||
//! use std::marker::PhantomData;
|
||||
//!
|
||||
//! struct Rc<T: ?Sized> {
|
||||
//! ptr: NonNull<RcBox<T>>,
|
||||
//! phantom: PhantomData<RcBox<T>>,
|
||||
//! ptr: NonNull<RcInner<T>>,
|
||||
//! phantom: PhantomData<RcInner<T>>,
|
||||
//! }
|
||||
//!
|
||||
//! struct RcBox<T: ?Sized> {
|
||||
//! struct RcInner<T: ?Sized> {
|
||||
//! strong: Cell<usize>,
|
||||
//! refcount: Cell<usize>,
|
||||
//! value: T,
|
||||
@ -213,9 +213,9 @@
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! trait RcBoxPtr<T: ?Sized> {
|
||||
//! trait RcInnerPtr<T: ?Sized> {
|
||||
//!
|
||||
//! fn inner(&self) -> &RcBox<T>;
|
||||
//! fn inner(&self) -> &RcInner<T>;
|
||||
//!
|
||||
//! fn strong(&self) -> usize {
|
||||
//! self.inner().strong.get()
|
||||
@ -230,8 +230,8 @@
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
|
||||
//! fn inner(&self) -> &RcBox<T> {
|
||||
//! impl<T: ?Sized> RcInnerPtr<T> for Rc<T> {
|
||||
//! fn inner(&self) -> &RcInner<T> {
|
||||
//! unsafe {
|
||||
//! self.ptr.as_ref()
|
||||
//! }
|
||||
|
@ -670,11 +670,11 @@ def StdRcSummaryProvider(valobj, dict):
|
||||
class StdRcSyntheticProvider:
|
||||
"""Pretty-printer for alloc::rc::Rc<T> and alloc::sync::Arc<T>
|
||||
|
||||
struct Rc<T> { ptr: NonNull<RcBox<T>>, ... }
|
||||
struct Rc<T> { ptr: NonNull<RcInner<T>>, ... }
|
||||
rust 1.31.1: struct NonNull<T> { pointer: NonZero<*const T> }
|
||||
rust 1.33.0: struct NonNull<T> { pointer: *const T }
|
||||
struct NonZero<T>(T)
|
||||
struct RcBox<T> { strong: Cell<usize>, weak: Cell<usize>, value: T }
|
||||
struct RcInner<T> { strong: Cell<usize>, weak: Cell<usize>, value: T }
|
||||
struct Cell<T> { value: UnsafeCell<T> }
|
||||
struct UnsafeCell<T> { value: T }
|
||||
|
||||
|
@ -95,7 +95,7 @@
|
||||
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
|
||||
<ArrayItems>
|
||||
<Size>ptr.pointer.length</Size>
|
||||
<!-- We add +2 to the data_ptr in order to skip the ref count fields in the RcBox -->
|
||||
<!-- We add +2 to the data_ptr in order to skip the ref count fields in the RcInner -->
|
||||
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: memory leaked: ALLOC (Rust heap, SIZE, ALIGN), allocated here:
|
||||
--> RUSTLIB/alloc/src/rc.rs:LL:CC
|
||||
|
|
||||
LL | Box::leak(Box::new(RcBox { strong: Cell::new(1), weak: Cell::new(1), value }))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | Box::leak(Box::new(RcInner { strong: Cell::new(1), weak: Cell::new(1), value }))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: BACKTRACE:
|
||||
= note: inside `std::rc::Rc::<std::cell::RefCell<std::option::Option<Dummy>>>::new` at RUSTLIB/alloc/src/rc.rs:LL:CC
|
||||
|
@ -19,8 +19,7 @@
|
||||
// gdb-check:$4 = ("Hello", "World")
|
||||
|
||||
// gdb-command:print str_in_rc
|
||||
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<alloc::rc::RcBox<&str>> {pointer: 0x[...]}, phantom: core::marker::PhantomData<alloc::rc::RcBox<&str>>, alloc: alloc::alloc::Global}
|
||||
|
||||
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<alloc::rc::RcInner<&str>> {pointer: 0x[...]}, phantom: core::marker::PhantomData<alloc::rc::RcInner<&str>>, alloc: alloc::alloc::Global}
|
||||
|
||||
// === LLDB TESTS ==================================================================================
|
||||
// lldb-command:run
|
||||
|
@ -160,14 +160,14 @@ pub struct Unique<T: ?Sized> {
|
||||
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);
|
||||
|
||||
#[repr(C)]
|
||||
struct RcBox<T: ?Sized> {
|
||||
struct RcInner<T: ?Sized> {
|
||||
strong: UnsafeCell<usize>,
|
||||
weak: UnsafeCell<usize>,
|
||||
value: T,
|
||||
}
|
||||
pub struct Rc<T: ?Sized, A = Global> {
|
||||
ptr: NonNull<RcBox<T>>,
|
||||
phantom: PhantomData<RcBox<T>>,
|
||||
ptr: NonNull<RcInner<T>>,
|
||||
phantom: PhantomData<RcInner<T>>,
|
||||
alloc: A,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user