Skip to main content

AirModule

Struct AirModule 

Source
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: ModuleId

Unique 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: u32

Target 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

Source

pub fn new(id: ModuleId) -> Self

Create a new module.

Source

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.

Source

pub fn add_function(&mut self, func: AirFunction)

Add a function, updating the index.

Source

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).

Source

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.

Source

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).

Source

pub fn global_by_name(&self, name: &str) -> Option<&AirGlobal>

Find a global by name.

Source

pub fn get_type(&self, id: TypeId) -> Option<&AirType>

Look up a type by TypeId.

Source

pub fn is_pointer_type(&self, id: TypeId) -> bool

Check if a TypeId resolves to a pointer-like type (Pointer or Reference).

Source

pub fn instruction_type(&self, inst: &Instruction) -> Option<&AirType>

Get the type of an instruction’s result, if available.

Source

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.

Trait Implementations§

Source§

impl Clone for AirModule

Source§

fn clone(&self) -> AirModule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AirModule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AirModule

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for AirModule

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AirModule

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,