Skip to main content

Module self_desc_pointer

Module self_desc_pointer 

Source
Expand description

SelfDescPointer<T> - pointer carrying type ID + layout shape in stolen high bits.

Layout: a single u64 with the high 16 bits stolen:

  • bits 56..=63: type_id (u8)
  • bits 53..=55: layout shape (3 bits, LayoutShape)
  • bits 0..=52: the address (53-bit virtual; ample on x86_64 / Apple Silicon)

The architectural win: a heterogeneous container of SelfDescPointers can dispatch on type WITHOUT a vtable lookup. When the type universe is small enough to fit in 8 bits (256 distinct types), the dispatch is a switch on the high byte; the compiler can compile this to a jump table inline at the call site.

§Comparison vs Rust’s existing options

MechanismPer-call costType universe
dyn Trait vtable1 indirect callunbounded
enum with variantstag-matchbounded
SelfDescPointer<T>switch on byte<= 256

The architectural shape mirrors JVM compressed-klass pointers (where the klass is encoded in the top bits of an object ref) but at a lighter weight: only 8 bits + 3 layout-shape bits stolen, vs JVM’s full 32-bit compressed klass.

§Bit budget

  • 8 bits for type ID: 256 distinct types in the universe. For wider universes use Box<dyn Trait> or an enum.
  • 3 bits for layout shape: 8 shapes covered by LayoutShape.
  • 53 bits for address: 8 PiB virtual memory; well above any current process.

Structs§

SelfDescPointer
8-byte pointer with (type_id, layout_shape, address) packed.

Enums§

LayoutShape
Layout shape encoded in 3 bits.

Constants§

ADDR_MASK
Address mask: low 53 bits.
SHAPE_MASK
SHAPE_SHIFT
Shape field: 3 bits at positions 53..56.
TYPE_MASK
TYPE_SHIFT
Type ID field: 8 bits at positions 56..64.