Skip to main content

Module repr_c_vec

Module repr_c_vec 

Source
Expand description

ReprCVec<T> — a growable vector whose field layout is a promise (ADR-118).

std::Vec<T> is #[repr(Rust)]. Its length and its element pointer live inside a private RawVec, so offset_of! cannot name them and the field order is not stable across compiler versions. That is fine for Rust code and fatal for generated code: a backend that wants to read a Vec[T]’s length inline has nothing it is allowed to read.

ReprCVec is a #[repr(C)] triple — pointer, length, capacity — that never holds anything a Vec did not hand it. Every construction goes through ReprCVec::from_vec and every mutation goes through ReprCVec::vec_mut, which reconstitutes a real Vec, lets Vec do the growth, and takes the parts back. No allocator logic is reimplemented here; RawVec’s amortized growth, its capacity-overflow checks and its allocation failure handling are all still the ones doing the work. What is new is only that the three words are somewhere the compiler is allowed to look.

§The measurement toggle

The std-vec-payload cargo feature replaces the #[repr(C)] triple with a #[repr(transparent)] newtype over std::Vec<T>, leaving every caller in the tree byte-for-byte unchanged. That is the arm A / arm B pair ADR-118 is measured with: the only thing that differs between the two binaries is the representation of this one struct. The change is expected to be performance neutral — it changes a container’s layout, not an algorithm — so the comparison is a regression check, not a win.

Structs§

InlineSliceSite
Everything generated code needs to walk one collection payload’s pinned ReprCVec inline, as one value with private fields (ADR-118 part 2).
ReprCVec
A growable vector with a pinned #[repr(C)] layout.
VecMut
A Vec borrowed out of a ReprCVec for the duration of a mutation.

Constants§

REPR_C_VEC_ELEMENTS_OFFSET
The displacement of the element pointer within a ReprCVec, for the two payloads generated code reads (VecPayload.items, BitSetPayload.words).
REPR_C_VEC_LEN_OFFSET
The displacement of the length word within a ReprCVec. See REPR_C_VEC_ELEMENTS_OFFSET.