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:
layoutshape (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
| Mechanism | Per-call cost | Type universe |
|---|---|---|
dyn Trait vtable | 1 indirect call | unbounded |
enum with variants | tag-match | bounded |
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§
- Self
Desc Pointer - 8-byte pointer with (type_id, layout_shape, address) packed.
Enums§
- Layout
Shape - 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.