Struct rustc_resolve::Span [−][src]
Expand description
A compressed span.
Whereas SpanData is 12 bytes, which is a bit too big to stick everywhere, Span
is a form that only takes up 8 bytes, with less space for the length and
context. The vast majority (99.9%+) of SpanData instances will fit within
those 8 bytes; any SpanData whose fields don’t fit into a Span are
stored in a separate interner table, and the Span will index into that
table. Interning is rare enough that the cost is low, but common enough
that the code is exercised regularly.
An earlier version of this code used only 4 bytes for Span, but that was
slower because only 80–90% of spans could be stored inline (even less in
very large crates) and so the interner was used a lot more.
Inline (compressed) format:
span.base_or_index == span_data.lospan.len_or_tag == len == span_data.hi - span_data.lo(must be<= MAX_LEN)span.ctxt == span_data.ctxt(must be<= MAX_CTXT)
Interned format:
span.base_or_index == index(indexes into the interner table)span.len_or_tag == LEN_TAG(high bit set, all other bits are zero)span.ctxt == 0
The inline form uses 0 for the tag value (rather than 1) so that we don’t need to mask out the tag bit when getting the length, and so that the dummy span can be all zeroes.
Notes about the choice of field sizes:
baseis 32 bits in bothSpanandSpanData, which means thatbasevalues never cause interning. The number of bits needed forbasedepends on the crate size. 32 bits allows up to 4 GiB of code in a crate.lenis 15 bits inSpan(a u16, minus 1 bit for the tag) and 32 bits inSpanData, which means that largelenvalues will cause interning. The number of bits needed forlendoes not depend on the crate size. The most common numbers of bits forlenare from 0 to 7, with a peak usually at 3 or 4, and then it drops off quickly from 8 onwards. 15 bits is enough for 99.99%+ of cases, but larger values (sometimes 20+ bits) might occur dozens of times in a typical crate.ctxtis 16 bits inSpanand 32 bits inSpanData, which means that largectxtvalues will cause interning. The number of bits needed forctxtvalues depend partly on the crate size and partly on the form of the code. No crates inrustc-perfneed more than 15 bits forctxt, but larger crates might need more than 16 bits.
In order to reliably use parented spans in incremental compilation,
the dependency to the parent definition’s span. This is performed
using the callback SPAN_TRACK to access the query engine.
Fields
base_or_index: u32len_or_tag: u16ctxt_or_zero: u16Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn subst_spanned(
self,
tcx: TyCtxt<'tcx>,
substs: &[GenericArg<'tcx>],
span: Option<Span>
) -> T
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes