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§
- Inline
Slice Site - Everything generated code needs to walk one collection payload’s pinned
ReprCVecinline, as one value with private fields (ADR-118 part 2). - ReprC
Vec - A growable vector with a pinned
#[repr(C)]layout. - VecMut
- A
Vecborrowed out of aReprCVecfor 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. SeeREPR_C_VEC_ELEMENTS_OFFSET.