Equivalent to a generic parameter but more concise for simple cases.
Arena / Arena Allocation
A large memory buffer from which other memory allocations are made. This allocation strategy improves performance by:
Reducing allocation overhead
Enabling bulk deallocation
Improving cache locality
The compiler uses arenas extensively to manage AST and HIR data structures.
AST (Abstract Syntax Tree)
The abstract syntax tree produced by the rustc_ast crate that closely reflects user syntax. It’s the first major representation of code after parsing.Example: The code let x = 5; is parsed into an AST node representing a let-binding with pattern x and expression 5.
An identifier that refers to a specific body (definition of a function or constant) in the crate. Used internally by the compiler to reference function implementations.
Bound Variable
A variable declared within an expression or term. In the closure |a| a * 2, the variable a is bound.Contrast with: Free variables, which are used but not declared within the expression.
The process of translating MIR (Mid-level Intermediate Representation) into LLVM IR for final compilation to machine code.Pipeline: HIR → MIR → LLVM IR → Machine Code
Codegen Unit (CGU)
When producing LLVM IR, Rust code is grouped into codegen units. Each unit:
Is processed by LLVM independently (enables parallelism)
Serves as the unit of incremental reuse
Can be controlled with compiler flags for optimization
Control-Flow Graph (CFG)
A representation of the control flow in a program, showing all paths that might be traversed during execution. Used for:
Dataflow analysis
Optimization passes
Borrow checking
CTFE (Compile-Time Function Evaluation)
The compiler’s ability to evaluate const fn functions at compile time.
const fn square(x: i32) -> i32 { x * x}const RESULT: i32 = square(5); // Evaluated at compile time
Part of Rust’s constant evaluation system.
cx / tcx / infcx
Common abbreviations for “context” in the compiler:
cx: Generic context
tcx: Typing context (TyCtxt), the main compiler data structure
Used during compilation to track dependencies between queries in the query system. Ensures no circular dependencies exist.
Data-Flow Analysis
A static analysis technique that determines what properties hold true at each point in a program’s control flow. Used for:
Borrow checking
Initialization analysis
Dead code detection
De Bruijn Index
A technique for representing bound variables using only integers, making variable references independent of naming.Benefit: Invariant under variable renaming, simplifying compiler operations.
DefId (Definition ID)
An index uniquely identifying a definition in the crate (function, type, constant, etc.). Fundamental to the compiler’s type system and name resolution.
Discriminant
The underlying value associated with an enum variant that indicates which variant is “active” at runtime.
enum Status { Success = 0, Error = 1,}// Discriminant values: 0 and 1
Not to be confused with variant index, which is internal to the compiler.
Drop Glue
Compiler-generated code that handles calling destructors (Drop trait implementations) for data types when they go out of scope.
DST (Dynamically-Sized Type)
A type whose size cannot be known at compile time.Examples:
A lifetime region substituted at its definition site. Bound in an item’s Generics and substituted using GenericArgs.Contrast with: Late-bound lifetime (substituted at call site)
Effects
Currently refers to const traits and ~const bounds, allowing trait bounds to be used in const contexts.
Created by lowering and desugaring the AST. More suitable for type checking and analysis than the AST.Transformation: Source Code → AST → HIR → MIR → LLVM IR
HirId
Identifies a particular node in the HIR by combining a def-id with an “intra-definition offset”.
Fingerprints (hashes) for HIR, crate metadata, and other compiler artifacts. Used to detect changes and enable incremental compilation.
Inference Variable
A special type/region/const representing an unknown value during type inference. Think of it as “X” in algebra.Example: When inferring let x = vec![];, the compiler creates an inference variable for the vector’s element type.
Intern / Interning
Storing frequently-used constant data (like strings) once and referring to it by identifier rather than copying it repeatedly.Benefits:
Reduced memory usage
Fewer allocations
Fast equality comparisons (compare identifiers, not content)
Interpreter
The heart of const evaluation, executing MIR code at compile time to compute constant values.
Intrinsic
Special functions implemented in the compiler itself but exposed to users (often as unstable features). They perform “magical” low-level operations.Examples:
std::intrinsics::transmute
SIMD operations
Atomic operations
Intrinsics are often unsafe and unstable. Use with caution.
IR (Intermediate Representation)
A general compiler term for transformed code representations between source and machine code.Rust’s IRs:
AST - Reflects source syntax
HIR - Desugared, suitable for type checking
MIR - Control-flow graph, suitable for borrow checking
LLVM IR - Low-level, suitable for optimization and codegen
Items representing concepts intrinsic to the language itself.Examples:
Built-in traits: Sync, Send, Copy
Operator traits: Add, Deref
Special types: Box, String
Compiler-called functions
Marked with #[lang = "..."] attribute.
Late-Bound Lifetime
A lifetime region substituted at its call site. Used in Higher-Rank Trait Bounds (HRTB).
fn apply<F>(f: F) where F: for<'a> Fn(&'a str) -> &'a str{ // 'a is late-bound}
Contrast with: Early-bound lifetime
LLVM
An open-source compiler backend that accepts LLVM IR and outputs native binaries. Rust compiles to LLVM IR, enabling support for all platforms LLVM supports.
Local Crate
The crate currently being compiled. Contrast with: Upstream crates (dependencies).
LTO (Link-Time Optimization)
Optimizations performed just before final binary linking:
FatLTO: Full optimization across all code
ThinLTO: Scalable variant with some trade-offs
Benefits: Removes unused code, inlines across crates, better optimization opportunities.
Storing results of pure computations to avoid repeating them. Trade-off between execution speed and memory usage.Used extensively in the compiler’s query system.
MIR (Mid-Level Intermediate Representation)
Created after type-checking, used for borrow checking and codegen. Represents code as a control-flow graph with basic blocks.Advantages:
Easier to analyze than HIR
Explicit control flow
Suitable for optimizations
Miri
An interpreter for Rust’s MIR that can detect Undefined Behavior in unsafe code.
cargo +nightly miri test
Extremely useful for validating unsafe code correctness.
Monomorphization
The process of creating concrete implementations from generic code.
fn generic<T>(x: T) -> T { x }let _a = generic(5i32); // Generates generic::<i32>let _b = generic("hello"); // Generates generic::<&str>
Each generic instantiation gets its own machine code copy.
A wrapper around another type, usually a single-field tuple struct.
struct UserId(u64);struct Meters(f64);
Benefits:
Type safety (can’t mix up UserId and other u64s)
Zero runtime cost
Can implement traits specifically for the newtype
Niche
Invalid bit patterns for a type that can be used for layout optimizations.Example:Option<&T> uses the same size as &T because &T cannot be null (null is the niche representing None).
Something that must be proven by the trait system during type checking.Example: When you call a generic function with a trait bound, the compiler creates an obligation to prove that bound is satisfied.
A way of handling subtyping around “for-all” types. Replaced the older skolemization approach.Used for higher-ranked trait bounds and lifetime inference.
Point
In NLL analysis, a location in the MIR, typically a node in the control-flow graph.
Projection
A “relative path” to a type or value:
Field projection:x.field
Associated type projection:T::Item, <Vec<T> as IntoIterator>::Item
Promoted Constants
Constants extracted from functions and lifted to static scope for compile-time evaluation.
const fn helper() -> i32 { 42 }fn example() { let x = &helper(); // helper() promoted to static}
Provider
The function that executes a query in the query system.
Handling invalid syntax during parsing and continuing to parse. Avoids cascading spurious errors.Example: If a struct definition has a syntax error, the parser recovers and continues, avoiding “missing field” errors that would be misleading.
Region
Another term for “lifetime,” commonly used in academic literature and the borrow checker implementation.
Rib
A data structure in name resolution tracking a single scope for names. Ribs form a stack representing nested scopes.
The expression matched in pattern matching constructs.
match expression { // 'expression' is the scrutinee Pattern1 => ..., Pattern2 => ...,}
Sess (Session)
The compiler session storing global data used throughout compilation. Accessed via tcx.sess.
Side Tables
Hashtables storing extra information about AST/HIR nodes (which are immutable). Indexed by node ID.Examples: Type information, resolution data, lint levels.
Sigil
A keyword-like symbol composed of non-alphanumeric characters.Examples:
& - reference sigil
* - dereference/raw pointer sigil
! - macro sigil
Soundness
A type system property: if a program type-checks, it is type-safe and cannot cause undefined behavior in safe code.Rust’s guarantee: Safe Rust is sound (cannot cause UB without unsafe).
Span
A location in source code used for error reporting. Contains:
File name
Start and end positions
Macro expansion tracking
Compiler desugaring information
All while being compactly stored.
Substs / Subst (Substitution)
Replacing generic parameters with concrete types.Modern terminology: “Instantiation” or “generic arguments”
HashMap<String, i32> // i32, String are substitutions/generic args
Sysroot
The directory containing build artifacts loaded by the compiler at runtime (standard library, core, etc.).View with: rustc --print sysroot