Files
rust/compiler/rustc_data_structures
Nicholas Nethercote d25eebbfb7 Overhaul span compression
Currently there are span representations if you have a context and no
parent, or a parent and no context. But if you have both a context *and*
a parent, the span is always interned. In incremental builds this is
something like 20-40% of all spans.

This commit uses a new compression scheme that gives small perf wins for
non-incremental and bigger perf wins for incremental. The following table
briefly summarizes the formats.

```
-----------------------------------------------------------------
              old                        new
-----------------------------------------------------------------
InlineCtxt    lo32,len15,ctxt16,parent0  lo32,len15,ctxt16,parent0
InlineParent  lo32,len15,ctxt0,parent16  lo32,len14,ctxt0,parent15
InlinePair    n/a                        lo24,len7,ctxt15,parent16
PartialInt.   ctxt16                     everything else
FullInt.      everything else            n/a
```

Things to note.

- The old scheme had a 32-bit field and two 16-bit fields. The new scheme has
  one 64-bit field and uses `repr(packed(4))`. (Keeping the alignment at
  4 is important to keep AST node sizes low.)

- The new scheme distinguishes the four formats with a single variable-length
  prefix in the high bits. This is simpler than the old combination of tag bits
  and special values.

- The new `SpanField` type is used to describe the various field widths
  for each format, and provide operations on them.

- The new `InlineParent` is very slightly worse than the old one, with one less
  bit for each of len and parent. This doesn't affect many spans.

- The new `InlinePair` format handles most cases where both a context and a
  parent are present. It has to compromise some on `lo` and `len`, but still
  gets a lot of them. This is the big performance win.

- The partially/fully interned cases are merged, because the Interned format
  can now always hold a full context inline, and the new `Interned` is
  equivalent to the old PartiallyInterned format. (This requires
  limiting ctxts to 29 bits, but we'll hit other problems, such as OOM,
  long before that limit is reached.) This also means we don't need to
  store the ctxt field in the interner, and we use the new
  `SpanDataNoCtxt` type for that.
2026-10-13 10:01:48 +11:00
..
2026-10-13 10:01:48 +11:00