1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Typed indices and the containers keyed by them.
//!
//! Every phase artifact in this workspace stores its nodes in a flat
//! [`IndexVec`] and names them by a typed index rather than by a pointer or a
//! hash key. That single decision buys four things at once:
//!
//! - **A node has one name.** [`IndexVec::push`] returns the index it just
//! assigned, so a producer never has to guess or recompute a node's identity.
//! - **The names are cheap and total.** An index is a `u32`, is `Copy`, and
//! carries no lifetime, so a side table is an ordinary `IndexVec` keyed by the
//! same index instead of a map with a hasher and an iteration order.
//! - **The names do not mix.** `newtype_index!` mints a distinct type per
//! domain, so passing a `BlockId` where an `ExprId` belongs is a compile
//! error rather than a silent out-of-bounds read.
//! - **Iteration order is positional.** Canonical order is *semantic* in Flow —
//! it reaches encodings, digests, and semantic history — so a container whose
//! order comes from a hash seed may never stand between a program and a
//! recorded fact. An `IndexVec` has no order to leak.
//!
//! # What is deliberately absent
//!
//! There is no borrowed `IndexSlice`. Producing one from a `&[T]` without a
//! transmute is not possible, and this workspace forbids `unsafe`. Code that
//! needs a sub-range takes a plain `&[T]`; code that needs indexed access takes
//! `&IndexVec`. The type that would have made that distinction ergonomic is not
//! worth an `unsafe` block here.
//!
//! There is no niche-optimized index either, for the same reason: reserving
//! `u32::MAX` as an invalid discriminant needs `unsafe` to be free, so
//! `Option<SomeId>` is eight bytes and that is fine.
pub use ;
pub use IndexVec;