Skip to main content

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;
18pub mod layout;
19mod param_arena;
20mod scope;
21mod sema;
22mod sema_context;
23pub mod specialize;
24mod types;
25
26pub use analysis_state::{AnalysisStateRemapping, FunctionAnalysisState, MergedAnalysisState};
27pub use function_analyzer::{
28    FunctionAnalyzer, FunctionAnalyzerOutput, FunctionOutputRemapping, MergedFunctionOutput,
29};
30pub use inference::{
31    Constraint, ConstraintContext, ConstraintGenerator, ExprInfo, FunctionSig, InferType,
32    LocalVarInfo, MethodSig, ParamVarInfo, Substitution, TypeVarAllocator, TypeVarId,
33    UnificationError, Unifier, UnifyResult,
34};
35pub use inst::{
36    Air, AirArgMode, AirCallArg, AirInst, AirInstData, AirParamMode, AirPattern, AirPlace,
37    AirPlaceBase, AirPlaceRef, AirProjection, AirRef,
38};
39pub use intern_pool::{
40    EnumData, InternedType, StructData, TypeData, TypeInternPool, TypeInternPoolStats,
41};
42pub use layout::{DiscriminantStrategy, Layout, NicheRange, layout_of};
43pub use param_arena::{ParamArena, ParamRange};
44pub use sema::module_path::ModulePath;
45pub use sema::{
46    AnalyzedFunction, ConstValue, FunctionInfo, GatherOutput, InterfaceVtables, MethodInfo, Sema,
47    SemaOutput,
48};
49// Note: FunctionInfo and MethodInfo are defined in sema and re-exported by sema_context.
50// We export InferenceContext and SemaContext from sema_context.
51pub use sema_context::{
52    InferenceContext as SemaContextInferenceContext, ModuleRegistry, SemaContext,
53};
54pub use types::{
55    ArrayTypeId, EnumDef, EnumId, EnumVariantDef, IfaceTy, InterfaceDef, InterfaceId,
56    InterfaceMethodReq, ModuleDef, ModuleId, MutRefTypeId, MutSliceTypeId, PtrConstTypeId,
57    PtrMutTypeId, ReceiverMode, RefTypeId, SliceTypeId, StructDef, StructField, StructId, Type,
58    TypeKind, parse_array_type_syntax,
59};
60
61/// Sentinel value used to encode parameter slots in AIR instructions.
62///
63/// When a slot value is >= this marker, it indicates a parameter slot rather than
64/// a local variable slot. The actual parameter index is `slot - PARAM_SLOT_MARKER`.
65///
66/// This allows sema to emit Store/Load instructions for parameters without knowing
67/// the total number of locals at analysis time.
68pub const PARAM_SLOT_MARKER: u32 = 0x4000_0000;