Skip to main content

Rir

Struct Rir 

Source
pub struct Rir { /* private fields */ }
Expand description

The complete RIR for a source file.

Implementations§

Source§

impl Rir

Source

pub fn new() -> Self

Create a new empty RIR.

Source

pub fn add_inst(&mut self, inst: Inst) -> InstRef

Add an instruction and return its reference.

Source

pub fn get(&self, inst_ref: InstRef) -> &Inst

Get an instruction by reference.

Source

pub fn get_mut(&mut self, inst_ref: InstRef) -> &mut Inst

Get a mutable reference to an instruction.

Source

pub fn len(&self) -> usize

The number of instructions.

Source

pub fn is_empty(&self) -> bool

Whether there are no instructions.

Source

pub fn iter(&self) -> impl Iterator<Item = (InstRef, &Inst)>

Iterate over all instructions with their references.

Source

pub fn add_extra(&mut self, data: &[u32]) -> u32

Add extra data and return the start index.

Source

pub fn get_extra(&self, start: u32, len: u32) -> &[u32]

Get extra data by index.

Source

pub fn add_inst_refs(&mut self, refs: &[InstRef]) -> (u32, u32)

Store a slice of InstRefs and return (start, len).

Source

pub fn get_inst_refs(&self, start: u32, len: u32) -> Vec<InstRef>

Retrieve InstRefs from the extra array.

Source

pub fn add_symbols(&mut self, symbols: &[Spur]) -> (u32, u32)

Store a slice of Spurs and return (start, len).

Source

pub fn get_symbols(&self, start: u32, len: u32) -> Vec<Spur>

Retrieve Spurs from the extra array.

Source

pub fn add_enum_variant_decls( &mut self, variants: &[(Spur, Vec<Spur>, Vec<Spur>)], ) -> (u32, u32)

Store enum variant declarations and return (start, variant_count).

Each variant is encoded as variable-length data in the extra array: [name_spur, field_count, is_struct, field_type_0, ..., field_type_n, field_name_0?, ..., field_name_n?]

  • is_struct: 0 for unit/tuple variants, 1 for struct variants.
  • For struct variants, field names follow field types.
  • Unit variants have field_count = 0.
Source

pub fn get_enum_variant_decls( &self, start: u32, variant_count: u32, ) -> Vec<(Spur, Vec<Spur>, Vec<Spur>)>

Retrieve enum variant declarations from the extra array. Returns a vec of (variant_name, field_types, field_names) triples. field_names is empty for unit/tuple variants.

Source

pub fn add_call_args(&mut self, args: &[RirCallArg]) -> (u32, u32)

Store RirCallArgs and return (start, len). Layout: [value: u32, mode: u32] per arg

Source

pub fn get_call_args(&self, start: u32, len: u32) -> Vec<RirCallArg>

Retrieve RirCallArgs from the extra array.

Source

pub fn add_params(&mut self, params: &[RirParam]) -> (u32, u32)

Store RirParams and return (start, len). Layout: [name: u32, ty: u32, mode: u32, is_comptime: u32] per param

Source

pub fn get_params(&self, start: u32, len: u32) -> Vec<RirParam>

Retrieve RirParams from the extra array.

Source

pub fn add_match_arms(&mut self, arms: &[(RirPattern, InstRef)]) -> (u32, u32)

Store match arms (pattern + body pairs) and return (start, arm_count). Each arm is stored with variable size depending on pattern kind.

Source

pub fn get_match_arms( &self, start: u32, arm_count: u32, ) -> Vec<(RirPattern, InstRef)>

Retrieve match arms from the extra array.

Source

pub fn add_field_inits(&mut self, fields: &[(Spur, InstRef)]) -> (u32, u32)

Store field initializers (name, value) and return (start, len). Layout: [name: u32, value: u32] per field

Source

pub fn get_field_inits(&self, start: u32, len: u32) -> Vec<(Spur, InstRef)>

Retrieve field initializers from the extra array.

Source

pub fn add_field_decls(&mut self, fields: &[(Spur, Spur)]) -> (u32, u32)

Store field declarations (name, type, is_pub) and return (start, len). Layout: [name: u32, type: u32, is_pub: u32] per field. ADR-0073 added the is_pub slot; pre-ADR call sites pass false for compatibility.

Source

pub fn add_field_decls_with_vis( &mut self, fields: &[(Spur, Spur, bool)], ) -> (u32, u32)

Store field declarations including visibility (ADR-0073).

Source

pub fn get_field_decls(&self, start: u32, len: u32) -> Vec<(Spur, Spur)>

Retrieve field declarations (name, type) from the extra array.

Source

pub fn get_field_decls_with_vis( &self, start: u32, len: u32, ) -> Vec<(Spur, Spur, bool)>

Retrieve field declarations with visibility (ADR-0073).

Source

pub fn add_directives(&mut self, directives: &[RirDirective]) -> (u32, u32)

Store directives and return (start, directive_count). Layout: [name: u32, span_start: u32, span_len: u32, args_len: u32, args…] per directive

Source

pub fn get_directives( &self, start: u32, directive_count: u32, ) -> Vec<RirDirective>

Retrieve directives from the extra array.

Source

pub fn add_destructure_fields( &mut self, fields: &[RirDestructureField], ) -> (u32, u32)

Store destructure fields and return (start, field_count).

binding_name is Option<Spur>. None encodes as u32::MAX — using 0 as the sentinel was wrong because Spur::into_usize is 0-indexed (the first-interned Spur lives at index 0), so the very first name interned in the build would round-trip back as None and lose its binding. u32::MAX matches the encoding already used by encode_binding / decode_binding above.

Source

pub fn get_destructure_fields( &self, start: u32, count: u32, ) -> Vec<RirDestructureField>

Retrieve destructure fields from the extra array.

Source

pub fn add_extern_fn(&mut self, extern_fn: RirExternFn)

Add a function span to track function boundaries. ADR-0085: append an extern fn declaration (from inside a link_extern block).

Source

pub fn extern_fns(&self) -> &[RirExternFn]

ADR-0085: read-only view over all extern fns declared in this file.

ADR-0085: append an empty link_extern("lib") { } block.

ADR-0085: read-only view over link_extern blocks that declared no symbols. Sema validates the library name and emits the corresponding -l<lib> link flag.

Source

pub fn add_function_span(&mut self, span: FunctionSpan)

Source

pub fn function_spans(&self) -> &[FunctionSpan]

Get all function spans.

Source

pub fn functions(&self) -> impl Iterator<Item = &FunctionSpan>

Iterate over function spans.

Source

pub fn function_count(&self) -> usize

Get the number of functions.

Source

pub fn function_view(&self, fn_span: &FunctionSpan) -> RirFunctionView<'_>

Get a view of just one function’s instructions.

Source

pub fn find_function(&self, name: Spur) -> Option<&FunctionSpan>

Find a function span by name.

Source

pub fn current_inst_index(&self) -> u32

Get the current instruction count (useful for tracking body start).

Source

pub fn merge(rirs: &[Rir]) -> Rir

Merge multiple RIRs into a single RIR.

This is used for parallel per-file RIR generation. Each file generates its own RIR in parallel, then they are merged into a single RIR with all instruction references renumbered to be valid in the merged RIR.

§Arguments
  • rirs - Slice of RIRs to merge (typically one per source file)
§Returns

A new merged RIR containing all instructions from all input RIRs.

Trait Implementations§

Source§

impl Clone for Rir

Source§

fn clone(&self) -> Rir

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 Rir

Source§

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

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

impl Default for Rir

Source§

fn default() -> Rir

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Rir

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 Serialize for Rir

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§

§

impl Freeze for Rir

§

impl RefUnwindSafe for Rir

§

impl Send for Rir

§

impl Sync for Rir

§

impl Unpin for Rir

§

impl UnsafeUnpin for Rir

§

impl UnwindSafe for Rir

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.

§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a [MaybeRef].
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.
Source§

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

§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,