pub struct InlineInternSite { /* private fields */ }Expand description
Everything generated code may bake in to answer an interned scalar inline, and nothing else (ADR-113).
§What this makes unrepresentable
The Cranelift backend’s inline sequence for Inst::Materialize { Int } is
four displacements and three immediates: where Heap hangs off the context,
where the two pacing words sit inside it, where the intern table’s base
pointer sits in the context, and the range and stride of the table itself.
Six of those seven numbers name a private field of a #[repr(C)] struct
in this crate. Handed to the backend as loose constants they would be six
independent chances to pair the Int table’s base with the Char table’s
bounds — a read past the end of a table whose length is the only thing
keeping the probe in bounds.
So they are one value with private fields, and there is exactly one of it:
crate::small_int::INLINE_INTERN_SITE. InlineInternSite::new is
pub(crate), so a site can only be minted inside this crate — and the one
place it is minted is beside the range constants it describes, in the module
whose doc already calls itself “the one statement of the range”. “Inline-probe
a table the backend has no right to probe” has no spelling, because there is
no second value to name; a future Char arm (P-4a) mints its own in
small_char.rs, next to its bounds, and cannot get Int’s by accident.
§And the half it cannot make unrepresentable
The pacing offsets are not arguments to new: it fills them from
PacingOffsets::new, which reads Heap’s own
Heap::BYTES_SINCE_COLLECT_OFFSET and
Heap::COLLECT_THRESHOLD_OFFSET, so a site cannot exist that describes an
intern table without also carrying the pacing predicate’s operands. That is
as far as a type can go. A type cannot force the backend to emit the
compare — that claim is about an instruction stream, and it is carried by
an_inline_int_box_tests_the_pacing_counter_before_it_reads_the_table in the
backend, which reads the emitted IR.
Implementations§
Source§impl InlineInternSite
impl InlineInternSite
Sourcepub const fn pacing(self) -> PacingOffsets
pub const fn pacing(self) -> PacingOffsets
The pacing predicate’s operands — the three displacements generated code emits the compare from, before it looks at the value at all.
The same value InlineClaimSite::pacing answers, which is what lets
the backend transcribe Heap::collection_is_due in one place. See
PacingOffsets.
Sourcepub const fn table_offset(self) -> usize
pub const fn table_offset(self) -> usize
Where the table’s base pointer sits in a RuntimeContext.
Sourcepub const fn min(self) -> i64
pub const fn min(self) -> i64
The lowest interned value — the addend that turns a value into an index.
Sourcepub const fn span(self) -> u64
pub const fn span(self) -> u64
max - min, as the unsigned bound of the one compare that decides
membership.
Generated code tests (value - min) as u64 <= span rather than comparing
against min and max separately: in two’s complement that single
unsigned compare is exactly min <= value <= max for every i64
including the wrapping ones, it reuses the subtract the index needs
anyway, and it costs one branch where the two-compare form costs two.
crate::small_int’s
the_unsigned_range_test_generated_code_emits_answers_index_of is the
proof, over the boundary values and both extremes of the type.
Sourcepub const fn stride_shift(self) -> u8
pub const fn stride_shift(self) -> u8
log2(stride) — the shift that scales an index to a byte offset.
A shift rather than a multiply because the stride is a pointer width and
a shift is the thing actually meant. new asserts the stride is a power
of two, so this is exact rather than approximate.
Trait Implementations§
Source§impl Clone for InlineInternSite
impl Clone for InlineInternSite
Source§fn clone(&self) -> InlineInternSite
fn clone(&self) -> InlineInternSite
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more