Skip to main content

VTableEntry

Enum VTableEntry 

Source
pub enum VTableEntry {
    Direct {
        function_id: u16,
    },
    Closure {
        function_id: u32,
        type_id: u32,
    },
    BoxedReturn {
        thunk_id: u16,
        wrap_targets: SmallVec<[WrapTarget; 2]>,
    },
    SelfArg {
        thunk_id: u16,
        self_arg_positions: SmallVec<[u8; 4]>,
    },
    Generic {
        thunk_id: u16,
        type_param_count: u8,
    },
    Compound {
        thunk_id: u16,
        flags: VTableEntryFlags,
        wrap_targets: SmallVec<[WrapTarget; 2]>,
        self_arg_positions: SmallVec<[u8; 4]>,
        type_param_count: u8,
    },
}
Expand description

How a single trait method dispatches through dyn T.

Six variants cover the cross-product of (no rewriting / Self-in-return / Self-in-arg / method-generic) per ADR-006 §2.7.24 Q25.C.5. The plain (function_id) and (function_id + type_id) entries preserve the pre-§2.7.24 vtable shapes so existing emit-tier wiring continues to compile.

Thunks vs function ids: variants other than Direct / Closure carry a thunk_id rather than a raw function id. The compiler-side vtable-construction tier generates one thunk per (impl, method) pair whose Erase_T-rewritten signature differs from the underlying impl method; the thunk does the auto-boxing on return / vtable-identity check / TypeInfo dispatch / etc., then tail-calls the impl method.

Variants§

§

Direct

Direct call — no Erase_T rewriting needed (no Self in non-receiver position, no method-generic parameters). Dispatch is a simple function-id call. Preserves the pre-§2.7.24 VTableEntry::FunctionId(u16) shape (renamed function_id field for forward consistency).

Fields

§function_id: u16
§

Closure

Pre-existing closure entry (W7 closure trait impls).

VTable closure entries carry (function_id, type_id); dispatch allocates a fresh OwnedClosureBlock per call via the program’s closure_function_layouts registry so the call convention sees the same raw TypedClosureHeader shape that op_make_closure emits.

Fields

§function_id: u32
§type_id: u32
§

BoxedReturn

Self (or Self::A) appears in return position. The thunk wraps the impl’s concrete return value back into a dyn T carrier at each wrap_targets path before returning.

Fields

§thunk_id: u16
§wrap_targets: SmallVec<[WrapTarget; 2]>

One entry per place the impl’s signature names Self / Self::A inside its (possibly structural) return type. E.g. for fn try_clone(&self) -> Result<Self, Error>, wrap_targets = [WrapTarget { path: [0], wrap_as_trait_id }].

§

SelfArg

Self appears in argument position. The thunk checks vtable-identity (per §Q25.C.2) between self’s vtable and each Self-typed argument’s vtable before forwarding to the impl method.

Fields

§thunk_id: u16
§self_arg_positions: SmallVec<[u8; 4]>

Argument indices (0-based, excluding the receiver) at which the impl’s signature names Self directly. Each gets one Arc::ptr_eq check on its vtable before dispatch.

§

Generic

Method has type parameters (fn method<G: Bound>(&self, g: G)). The thunk consumes type_param_count &TypeInfo parameters alongside the regular arguments per §Q25.C.3 and dispatches on concrete_type_id for each.

Fields

§thunk_id: u16
§type_param_count: u8
§

Compound

Combination of BoxedReturn / SelfArg / Generic. The thunk dispatches per flags bit set.

Fields

§thunk_id: u16
§wrap_targets: SmallVec<[WrapTarget; 2]>
§self_arg_positions: SmallVec<[u8; 4]>
§type_param_count: u8

Trait Implementations§

Source§

impl Clone for VTableEntry

Source§

fn clone(&self) -> VTableEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for VTableEntry

Source§

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

Formats the value using the given formatter. Read more

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<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<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,