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).
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.
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
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
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.
Compound
Combination of BoxedReturn / SelfArg / Generic. The thunk
dispatches per flags bit set.
Trait Implementations§
Source§impl Clone for VTableEntry
impl Clone for VTableEntry
Source§fn clone(&self) -> VTableEntry
fn clone(&self) -> VTableEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more