Skip to main content

TypedObjectPtr

Struct TypedObjectPtr 

Source
#[repr(transparent)]
pub struct TypedObjectPtr(pub *const TypedObjectStorage);
Expand description

Owning newtype around *const TypedObjectStorage carrying one v2-raw refcount share on the pointed-to allocation’s HeapHeader.

Wave 2 Round 4 D4 ckpt-final (2026-05-14): redesigned to own its share. Previously a trivially-Copy transparent newtype; that shape leaks element refcounts when the enclosing Vec<TypedObjectPtr> drops because trivial bit-copy Drop never calls release_elem. Now the wrapper:

  • Owns one v2-raw HeapHeader-at-offset-0 refcount share.
  • Clone bumps the refcount via v2_retain.
  • Drop retires the share via TypedObjectStorage::release_elem.
  • Default is the null pointer (no refcount share owed).

#[repr(transparent)] so the in-memory layout is identical to *const TypedObjectStorage — zero ABI cost vs the raw pointer; the wrapper exists only to localize the manual Send/Sync impl + the Drop/Clone refcount discipline (Rust disables auto-Send/Sync for ALL instantiations of a generic struct as soon as ANY manual impl exists, so per-T newtypes are the canonical workaround for raw-ptr inner elements in generic buffers).

Used as the inner element type of:

  • HashMapValueBuf::TypedObject(Arc<TypedBuffer<TypedObjectPtr>>)
  • TypedArrayData::TypedObject(Arc<TypedBuffer<TypedObjectPtr>>)

Construction-side contract: callers transfer one strong-count share on the v2-raw HeapHeader to the new TypedObjectPtr. Reads via as_ptr() return the underlying pointer without bumping refcount.

Tuple Fields§

§0: *const TypedObjectStorage

Implementations§

Source§

impl TypedObjectPtr

Source

pub fn new(ptr: *const TypedObjectStorage) -> Self

Construct from a raw pointer obtained via TypedObjectStorage::_new. The caller transfers one strong-count share to the wrapper.

Source

pub fn as_ptr(&self) -> *const TypedObjectStorage

Recover the underlying raw pointer. Does NOT bump refcount; the returned pointer is borrowed for the wrapper’s lifetime.

Source

pub fn is_null(&self) -> bool

Whether the pointer is null. Construction-side contract permits null only for default-initialized cells.

Source

pub fn into_raw(self) -> *const TypedObjectStorage

Consume the wrapper without running Drop, returning the raw pointer. The caller takes over the one refcount share. Mirror of Arc::into_raw.

Methods from Deref<Target = TypedObjectStorage>§

Source

pub unsafe fn write_slot_in_place(&self, idx: usize, new_bits: u64) -> u64

In-place write of slot idx through a shared &TypedObjectStorage (i.e. through an Arc<TypedObjectStorage> with refcount > 1). Returns the prior (bits, kind) so the caller can run drop_with_kind on the released share. The caller transfers ownership of new_bits (one strong-count share for heap kinds) to the slot.

This is the Q14 / ADR-006 §2.7.13 in-place write path for RefTarget::TypedField projection writes — the receiver Arc is shared between the ref carrier and the originating binding, so Arc::get_mut / Arc::make_mut cannot apply (refcount > 1 by construction, and TypedObjectStorage is intentionally not Clone per the §2.5 documentation). The Box<[ValueSlot]> inside the storage is logically owned; the single-word u64 inside each ValueSlot is written atomically (single-word aligned store on every supported architecture).

§Safety

Callers must guarantee:

  1. Single-threaded write: the VM is single-threaded, and the refs that drive this path are constrained by the §3.1 ref-escape analysis to stay within their originating task (refs cannot cross task boundaries — error B0014 NonSendableAcrossTaskBoundary). No other thread may hold an &Arc<TypedObjectStorage> to the same storage at the same time the write executes.
  2. No aliased &mut ValueSlot: callers must NOT mint a &mut ValueSlot to slot idx from any path while this write is in flight. The Q14 dispatch in op_deref_store / op_set_index_ref is the only caller, and it operates on &TypedObjectStorage exclusively.
  3. Kind invariance: new_kind must equal self.field_kinds[idx]. The Q14 RefTarget carries the projected slot’s kind at construction (MakeFieldRef sources it from field_type_tag); the post-proof §2.7.5.1 contract forbids mid-life kind changes for typed fields. The caller debug_asserts this before calling.
  4. heap_mask bit consistency: for heap-kinded slots (NativeKind::String or Ptr(HeapKind::_)), the corresponding heap_mask bit must already be set per the TypedObjectStorage::new construction-side contract, AND the prior bits must be a valid Arc::into_raw::<T> for the slot’s kind. The returned prior_bits is exactly that share; the caller releases it via drop_with_kind after running the post-write barrier.

Q14 / ADR-006 §2.7.13. Mirror of the clone_with_kind / drop_with_kind symmetry used by RefTarget::Local and RefTarget::ModuleBinding writes (stack_write_kinded and module_binding_write_kinded already encapsulate this pattern for non-projected places; this is the projected-place mirror).

Trait Implementations§

Source§

impl Clone for TypedObjectPtr

Source§

fn clone(&self) -> Self

v2-raw refcount bump via v2_retain on the pointed-to HeapHeader. The clone owns its own share, retired at its own Drop.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypedObjectPtr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TypedObjectPtr

Source§

fn default() -> Self

Null pointer default — used by TypedBuffer::<TypedObjectPtr>::push_null and similar default-requiring construction sites. Callers must not dereference a default-constructed TypedObjectPtr. No refcount share is owed for a null wrapper; Drop on a null pointer is a no-op.

Source§

impl Deref for TypedObjectPtr

Source§

type Target = TypedObjectStorage

The resulting type after dereferencing.
Source§

fn deref(&self) -> &TypedObjectStorage

Dereferences the value.
Source§

impl Drop for TypedObjectPtr

Source§

fn drop(&mut self)

Retire the owned share via TypedObjectStorage::release_elem (HeapElement trait — calls v2_release and, on refcount=0, runs _drop to dealloc the allocation + retire heap-mask shares). No-op on null wrappers.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Hash for TypedObjectPtr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl HashMapValueElem for TypedObjectPtr

Source§

unsafe fn release_typed_array(ptr: *mut TypedArray<Self>)

TypedObjectPtr is #[repr(transparent)] over *const TypedObjectStorage but has a manual Drop impl (calls release_elem). Walk the buffer via ptr::read to invoke each element’s Drop (which retires the v2-raw HeapHeader share), then free the data allocation + struct.

Source§

unsafe fn share_clone(elem: &Self) -> Self

Clone a single element with proper refcount-share semantics. Read more
Source§

unsafe fn release_owned(_value: Self)

Release a single owned value (one refcount share). For POD V it is a no-op (byte copy falls out of scope). For HeapElement V the share is retired via release_elem on the pointer. For Ptr-newtype V the wrapper’s Drop runs automatically when the value drops. Read more
Source§

impl PartialEq for TypedObjectPtr

Source§

fn eq(&self, other: &TypedObjectPtr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TypedObjectPtr

Source§

impl Send for TypedObjectPtr

Source§

impl StructuralPartialEq for TypedObjectPtr

Source§

impl Sync for TypedObjectPtr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,