gruel_air/
lib.rs

1//! Analyzed Intermediate Representation (AIR) - Typed IR.
2//!
3//! AIR is the second IR in the Gruel compiler pipeline. It is generated from
4//! RIR after semantic analysis and type checking.
5//!
6//! Key characteristics:
7//! - Fully typed: all types are resolved
8//! - Per-function: generated lazily for each function
9//! - Ready for codegen: can be lowered directly to machine code
10//!
11//! Inspired by Zig's AIR (Analyzed Intermediate Representation).
12
13mod analysis_state;
14mod function_analyzer;
15mod inference;
16mod inst;
17mod intern_pool;
18mod param_arena;
19mod scope;
20mod sema;
21mod sema_context;
22pub mod specialize;
23mod types;
24
25pub use analysis_state::{AnalysisStateRemapping, FunctionAnalysisState, MergedAnalysisState};
26pub use function_analyzer::{
27    FunctionAnalyzer, FunctionAnalyzerOutput, FunctionOutputRemapping, MergedFunctionOutput,
28};
29pub use inference::{
30    Constraint, ConstraintContext, ConstraintGenerator, ExprInfo, FunctionSig, InferType,
31    LocalVarInfo, MethodSig, ParamVarInfo, Substitution, TypeVarAllocator, TypeVarId,
32    UnificationError, Unifier, UnifyResult,
33};
34pub use inst::{
35    Air, AirArgMode, AirCallArg, AirInst, AirInstData, AirParamMode, AirPattern, AirPlace,
36    AirPlaceBase, AirPlaceRef, AirProjection, AirRef,
37};
38pub use intern_pool::{
39    EnumData, InternedType, StructData, TypeData, TypeInternPool, TypeInternPoolStats,
40};
41pub use param_arena::{ParamArena, ParamRange};
42pub use sema::{
43    AnalyzedFunction, ConstValue, FunctionInfo, GatherOutput, MethodInfo, Sema, SemaOutput,
44};
45// Note: FunctionInfo and MethodInfo are defined in sema and re-exported by sema_context.
46// We export InferenceContext and SemaContext from sema_context.
47pub use sema_context::{
48    InferenceContext as SemaContextInferenceContext, ModuleRegistry, SemaContext,
49};
50pub use types::{
51    ArrayTypeId, EnumDef, EnumId, ModuleDef, ModuleId, PtrConstTypeId, PtrMutTypeId, StructDef,
52    StructField, StructId, Type, TypeKind, parse_array_type_syntax,
53};
54
55/// Sentinel value used to encode parameter slots in AIR instructions.
56///
57/// When a slot value is >= this marker, it indicates a parameter slot rather than
58/// a local variable slot. The actual parameter index is `slot - PARAM_SLOT_MARKER`.
59///
60/// This allows sema to emit Store/Load instructions for parameters without knowing
61/// the total number of locals at analysis time.
62pub const PARAM_SLOT_MARKER: u32 = 0x4000_0000;