Skip to main content

SsaVariable

Struct SsaVariable 

Source
pub struct SsaVariable<T: Target> {
    id: SsaVarId,
    origin: VariableOrigin,
    version: u32,
    def_site: DefSite,
    var_type: T::Type,
    uses: Vec<UseSite>,
    address_taken: bool,
}
Expand description

Complete metadata for an SSA variable.

Each SSA variable has exactly one definition and zero or more uses. This structure bundles all metadata needed for analysis, optimization, and code generation.

§Invariants

  • id.index() equals the variable’s position in SsaFunction::variables (maintained by create_variable and compact_variables)
  • Version 0 of arguments/locals is typically the value at function entry
  • def_site is None-instruction for phi nodes (definition at block entry)

§Construction

Variables are created through SsaFunction::create_variable(), which ensures dense ID allocation, origin registration, and type tracking.

Fields§

§id: SsaVarId

Dense unique identifier within the owning function. Invariant: id.index() == position in SsaFunction.variables.

§origin: VariableOrigin

CIL origin of this variable: method argument, local, or phi node result. Used for rename grouping and debug display.

§version: u32

SSA version number for this variable.

For arguments and locals, each assignment creates a new version. Version 0 is the initial value at method entry (argument values, zero-initialized locals). Higher versions correspond to later assignments.

§def_site: DefSite

Location in the SSA function where this variable is defined.

  • DefSite::instruction(block, idx) for instruction-defined variables
  • DefSite::phi(block) for phi node results
  • DefSite::entry() for arguments and initialized locals (implicit def)
§var_type: T::Type

The type of this variable, resolved during SSA construction.

Inferred from the defining instruction’s result type or the origin’s canonical type. T::unknown_type() if type inference is pending.

§uses: Vec<UseSite>

All use sites where this variable is referenced as an operand.

Populated during SSA construction by [SsaFunction::recompute_uses]. Enables dead code elimination (empty uses = dead) and use-based analyses.

§address_taken: bool

Whether this variable’s address has been taken via ldarga/ldloca.

Address-taken variables may be modified through pointers, making them ineligible for copy propagation, dead store elimination, and other optimizations that assume single-assignment immutability.

Implementations§

Source§

impl<T: Target> SsaVariable<T>

Source

pub fn new( id: SsaVarId, origin: VariableOrigin, version: u32, def_site: DefSite, var_type: T::Type, ) -> Self

Creates a new SSA variable with a pre-allocated ID and type.

Note: prefer creating variables through SsaFunction::create_variable (in the host crate), which ensures dense ID allocation via FunctionVarAllocator. This constructor is pub only because the host crate’s SsaFunction lives outside analyssa and needs to call it.

§Arguments
  • id - The dense variable ID from FunctionVarAllocator
  • origin - Where this variable came from in the host
  • version - SSA version number
  • def_site - Where this variable is defined
  • var_type - The type of this variable
Source

pub const fn id(&self) -> SsaVarId

Returns the variable’s unique identifier.

Source

pub const fn origin(&self) -> VariableOrigin

Returns where this variable originated in the CIL.

Source

pub const fn version(&self) -> u32

Returns the SSA version number.

Source

pub const fn def_site(&self) -> DefSite

Returns where this variable is defined.

Source

pub fn var_type(&self) -> &T::Type

Returns the type of this variable.

Returns the host’s “unknown” type if type inference hasn’t been performed.

Source

pub fn set_def_site(&mut self, site: DefSite)

Updates where this variable is defined.

Source

pub fn set_type(&mut self, var_type: T::Type)

Sets the type of this variable.

This is typically called during type inference or when resolving phi node types.

Source

pub fn has_known_type(&self) -> bool

Returns true if the variable’s type is known (not the host’s “unknown” type).

Source

pub fn uses(&self) -> &[UseSite]

Returns all use sites for this variable.

Source

pub const fn is_address_taken(&self) -> bool

Returns true if this variable’s address has been taken.

Source

pub fn is_dead(&self) -> bool

Returns true if this variable has no uses (dead).

Source

pub fn use_count(&self) -> usize

Returns the number of uses for this variable.

Source

pub fn add_use(&mut self, use_site: UseSite)

Adds a use site for this variable.

Source

pub fn clear_uses(&mut self)

Clears all use sites for this variable.

This is used when recomputing use information after SSA transformations that may have invalidated the use tracking.

Source

pub fn set_address_taken(&mut self)

Marks this variable as having its address taken.

Source

pub fn set_origin(&mut self, origin: VariableOrigin)

Sets the origin of this variable.

This is used during local variable optimization to update indices after unused locals are removed.

Source

pub fn set_id(&mut self, id: SsaVarId)

Sets the variable’s ID.

Used during variable compaction to reassign dense IDs.

Trait Implementations§

Source§

impl<T: Clone + Target> Clone for SsaVariable<T>
where T::Type: Clone,

Source§

fn clone(&self) -> SsaVariable<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Target> Debug for SsaVariable<T>
where T::Type: Debug,

Source§

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

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

impl<T: Target> Display for SsaVariable<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SsaVariable<T>
where <T as Target>::Type: Freeze,

§

impl<T> RefUnwindSafe for SsaVariable<T>
where <T as Target>::Type: RefUnwindSafe,

§

impl<T> Send for SsaVariable<T>
where <T as Target>::Type: Send,

§

impl<T> Sync for SsaVariable<T>
where <T as Target>::Type: Sync,

§

impl<T> Unpin for SsaVariable<T>
where <T as Target>::Type: Unpin,

§

impl<T> UnsafeUnpin for SsaVariable<T>
where <T as Target>::Type: UnsafeUnpin,

§

impl<T> UnwindSafe for SsaVariable<T>
where <T as Target>::Type: UnwindSafe,

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.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.