flow-span 0.1.0-rc.5

Source positions, source files, the identifier interner, and the places in a run.
Documentation
//! Source positions, source files, and interned identifiers.
//!
//! Five vocabularies that every later phase speaks, and nothing else:
//!
//! - [`Idx`] and [`IndexVec`], the typed indices and index-keyed vectors every
//!   phase artifact stores its nodes in; the `index` module says why.
//! - [`Span`], a byte extent that carries its [`FileId`]. Everything a
//!   diagnostic points at is one of these, and because the file travels inside
//!   the span, one [`SourceMap`] reads back a span from any file of a
//!   compilation.
//! - [`SourceMap`], the append-only owner of the text those spans index into,
//!   plus the line index a caret needs.
//! - [`Symbol`] and [`Interner`], so a name is a four-byte integer comparison
//!   rather than a string comparison.
//! - [`RunId`], [`TaskPath`], [`CallRef`] and [`Moment`], the places in a
//!   run, as a span is a place in source. The `place` module holds the one
//!   grammar they are written in, so a frame, a history, a diagnostic and a
//!   command line all read and write them the same way.
//!
//! # What is deliberately absent
//!
//! **No file loading.** This crate never reads a path. Turning a path into text
//! is an operating-system act, and one crate in this workspace owns those.
//!
//! **No `Symbol` serialization.** A symbol index means nothing without the
//! interner that produced it; a serialized one would be a number that reads
//! like a name. Code that persists an identifier persists its text.
//!
//! **No reserved-word table.** `flow-lexer` owns the reserved words and turns
//! those spellings into distinct token kinds before any interning happens.

#![cfg_attr(all(coverage, test), feature(coverage_attribute))]

mod index;
mod place;
mod source_map;
mod span;
mod spelled;
mod symbol;

#[cfg(any(test, feature = "test-support"))]
pub use place::count;
pub use place::{CallRef, Moment, ParsePlaceError, PlaceKind, RunId, TaskPath};
pub use source_map::{SourceFile, SourceMap, SourceName};
pub use span::{FileId, LineCol, Span};
pub use symbol::{Interner, Symbol};

pub use index::{Idx, IndexVec, MAX_INDEX};

const _: () = assert!(
    usize::BITS >= u32::BITS,
    "the workspace stores offsets and indices as u32 and widens them to usize",
);

/// Widens a `u32` offset, index or count to `usize`.
///
/// Every offset, index and count this workspace stores is a `u32`, and every
/// target it builds for has a `usize` at least as wide (the assertion above
/// refuses one that does not), so the conversion never loses a bit. It is a
/// `const fn` because indices are widened in `const` contexts, where
/// `usize::try_from` is unavailable.
#[expect(
    clippy::as_conversions,
    reason = "u32 to usize is lossless on every target, asserted at compile time above"
)]
pub const fn widen(value: u32) -> usize {
    value as usize
}