pub struct AirModule {
pub id: ModuleId,
pub name: Option<String>,
pub functions: Vec<AirFunction>,
pub globals: Vec<AirGlobal>,
pub source_files: Vec<SourceFile>,
pub type_hierarchy: Vec<TypeHierarchyEntry>,
pub constants: BTreeMap<ValueId, Constant>,
pub types: BTreeMap<TypeId, AirType>,
pub target_pointer_width: u32,
pub function_index: BTreeMap<FunctionId, usize>,
pub name_index: BTreeMap<String, usize>,
}Expand description
An AIR module — the top-level container for a compilation unit.
Fields§
§id: ModuleIdUnique module identifier.
name: Option<String>Optional module name.
functions: Vec<AirFunction>Functions in this module.
globals: Vec<AirGlobal>Global variables/constants.
source_files: Vec<SourceFile>Source files referenced by spans.
type_hierarchy: Vec<TypeHierarchyEntry>Type hierarchy entries for CHA (Class Hierarchy Analysis).
constants: BTreeMap<ValueId, Constant>Inline constants: maps ValueId to constant value.
When a constant (like i32 0) appears as an instruction operand,
the frontend records the mapping here so analyses can look up
the constant value by ValueId.
types: BTreeMap<TypeId, AirType>Type table: maps TypeId to AirType definition.
Frontends intern types here during ingestion. Analyses look up
types by TypeId for precision improvements. Deterministic
ordering via BTreeMap ensures reproducible JSON output.
target_pointer_width: u32Target pointer width in bytes (4 for 32-bit, 8 for 64-bit). Used by layout computation. Defaults to 8.
function_index: BTreeMap<FunctionId, usize>Pre-computed index: FunctionId -> position in functions vec.
Skipped during serialization; rebuilt on deserialization.
name_index: BTreeMap<String, usize>Pre-computed index: function name -> position in functions vec.
Skipped during serialization; rebuilt on deserialization.
Implementations§
Source§impl AirModule
impl AirModule
Sourcepub fn rebuild_function_index(&mut self)
pub fn rebuild_function_index(&mut self)
Rebuild the function_index from the current functions vec.
Call this after bulk-modifying functions directly (e.g., assigning
a whole Vec<AirFunction>). Not needed when using add_function.
Sourcepub fn add_function(&mut self, func: AirFunction)
pub fn add_function(&mut self, func: AirFunction)
Add a function, updating the index.
Sourcepub fn function(&self, id: FunctionId) -> Option<&AirFunction>
pub fn function(&self, id: FunctionId) -> Option<&AirFunction>
Find a function by ID using the pre-computed index (O(log n)).
Falls back to linear scan if the index is empty (e.g., when the module was constructed via struct literal without rebuilding).
Sourcepub fn function_mut(&mut self, id: FunctionId) -> Option<&mut AirFunction>
pub fn function_mut(&mut self, id: FunctionId) -> Option<&mut AirFunction>
Find a function by ID (mutable) using the pre-computed index (O(log n)).
Falls back to linear scan if the index is empty.
Sourcepub fn function_by_name(&self, name: &str) -> Option<&AirFunction>
pub fn function_by_name(&self, name: &str) -> Option<&AirFunction>
Find a function by name using the pre-computed index (O(log n)).
Falls back to linear scan if the index is empty (e.g., when the module was constructed via struct literal without rebuilding).
Sourcepub fn global_by_name(&self, name: &str) -> Option<&AirGlobal>
pub fn global_by_name(&self, name: &str) -> Option<&AirGlobal>
Find a global by name.
Sourcepub fn is_pointer_type(&self, id: TypeId) -> bool
pub fn is_pointer_type(&self, id: TypeId) -> bool
Check if a TypeId resolves to a pointer-like type (Pointer or Reference).
Sourcepub fn instruction_type(&self, inst: &Instruction) -> Option<&AirType>
pub fn instruction_type(&self, inst: &Instruction) -> Option<&AirType>
Get the type of an instruction’s result, if available.
Sourcepub fn pointer_value_count(&self) -> usize
pub fn pointer_value_count(&self) -> usize
Count all values with pointer type in the module.
Uses the type table to determine pointer types. If no type entry exists for a value, it is conservatively not counted as a pointer.