Expand description
A translation unit’s rendering, as bytes — what makes the second read of a unit a decode instead of a cook.
RenderedUnit is the whole program’s cooked text: a compiler’s view of the includes in order, with every macro
replaced by what it expands to. Producing one costs 899 ms on a real project (1 991 163 bytes of text, 590 135
tokens), and the walk it comes from is a fixed function of the files’ contents — which is why its key, computed in
Session::render_the_unit, is a hash over every (path, content hash) the closure entered. A rendering filed
under that key can be read back on the next start, and the second unit read pays a decode rather than a cook.
§What is stored, and what is not
text the cooked stream
files the paths the walk entered, in order — what a span's `file` indexes
file_lengths how long each file's own text is, parallel to `files`
dead_macros the `#define`s the walk decided a compiler would not read, by file
messages the `#error`/`#warning` lines the compilation would have said
spans one per token: where it is in `text`, which file it stands in, where to act on itEvery field is a function of the text and the closure, so the whole record is content-addressed by its key. There
is no Origin chain here, unlike a single file’s rendering: a unit span says which file a token stands in and
where, which is what a consumer of the unit needs; the invocation chain is a per-file question.
§Why a hand-written codec
The same reason crate::summary_codec is one: the format is a file on disk that an older binary may be handed,
so it needs a magic number, a version, and a decoder that rejects rather than misreads. 590 135 spans is 590 135 ×
20 bytes here, and a serde-derived format would spend more per field and version itself in a way this crate
cannot control.
Enums§
Constants§
- UNIT_
CODEC_ VERSION - Bumped when the layout changes; an older record is then unreachable rather than misread.
Functions§
- decode
- decode_
indexed_ unit - encode
- encode_
indexed_ unit - A unit’s facts, as bytes — the sweep’s output for every file the parse covered.