Struct Rir
pub struct Rir { /* private fields */ }Expand description
The complete RIR for a source file.
Implementations§
§impl Rir
impl Rir
pub fn add_inst(&mut self, inst: Inst) -> InstRef
pub fn add_inst(&mut self, inst: Inst) -> InstRef
Add an instruction and return its reference.
pub fn get(&self, inst_ref: InstRef) -> &Inst
pub fn get(&self, inst_ref: InstRef) -> &Inst
Get an instruction by reference.
pub fn get_mut(&mut self, inst_ref: InstRef) -> &mut Inst
pub fn get_mut(&mut self, inst_ref: InstRef) -> &mut Inst
Get a mutable reference to an instruction.
pub fn iter(&self) -> impl Iterator<Item = (InstRef, &Inst)>
pub fn iter(&self) -> impl Iterator<Item = (InstRef, &Inst)>
Iterate over all instructions with their references.
pub fn add_inst_refs(&mut self, refs: &[InstRef]) -> (u32, u32)
pub fn add_inst_refs(&mut self, refs: &[InstRef]) -> (u32, u32)
Store a slice of InstRefs and return (start, len).
pub fn get_inst_refs(&self, start: u32, len: u32) -> Vec<InstRef>
pub fn get_inst_refs(&self, start: u32, len: u32) -> Vec<InstRef>
Retrieve InstRefs from the extra array.
pub fn add_symbols(&mut self, symbols: &[Spur]) -> (u32, u32)
pub fn add_symbols(&mut self, symbols: &[Spur]) -> (u32, u32)
Store a slice of Spurs and return (start, len).
pub fn get_symbols(&self, start: u32, len: u32) -> Vec<Spur>
pub fn get_symbols(&self, start: u32, len: u32) -> Vec<Spur>
Retrieve Spurs from the extra array.
pub fn add_enum_variant_decls(
&mut self,
variants: &[(Spur, Vec<Spur>, Vec<Spur>)],
) -> (u32, u32)
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.
pub fn get_enum_variant_decls(
&self,
start: u32,
variant_count: u32,
) -> Vec<(Spur, Vec<Spur>, Vec<Spur>)>
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.
pub fn add_call_args(&mut self, args: &[RirCallArg]) -> (u32, u32)
pub fn add_call_args(&mut self, args: &[RirCallArg]) -> (u32, u32)
Store RirCallArgs and return (start, len). Layout: [value: u32, mode: u32] per arg
pub fn get_call_args(&self, start: u32, len: u32) -> Vec<RirCallArg>
pub fn get_call_args(&self, start: u32, len: u32) -> Vec<RirCallArg>
Retrieve RirCallArgs from the extra array.
pub fn add_params(&mut self, params: &[RirParam]) -> (u32, u32)
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
pub fn get_params(&self, start: u32, len: u32) -> Vec<RirParam>
pub fn get_params(&self, start: u32, len: u32) -> Vec<RirParam>
Retrieve RirParams from the extra array.
pub fn add_match_arms(&mut self, arms: &[(RirPattern, InstRef)]) -> (u32, u32)
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.
pub fn get_match_arms(
&self,
start: u32,
arm_count: u32,
) -> Vec<(RirPattern, InstRef)>
pub fn get_match_arms( &self, start: u32, arm_count: u32, ) -> Vec<(RirPattern, InstRef)>
Retrieve match arms from the extra array.
pub fn add_field_inits(&mut self, fields: &[(Spur, InstRef)]) -> (u32, u32)
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
pub fn get_field_inits(&self, start: u32, len: u32) -> Vec<(Spur, InstRef)>
pub fn get_field_inits(&self, start: u32, len: u32) -> Vec<(Spur, InstRef)>
Retrieve field initializers from the extra array.
pub fn add_field_decls(&mut self, fields: &[(Spur, Spur)]) -> (u32, u32)
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.
pub fn add_field_decls_with_vis(
&mut self,
fields: &[(Spur, Spur, bool)],
) -> (u32, u32)
pub fn add_field_decls_with_vis( &mut self, fields: &[(Spur, Spur, bool)], ) -> (u32, u32)
Store field declarations including visibility (ADR-0073).
pub fn get_field_decls(&self, start: u32, len: u32) -> Vec<(Spur, Spur)>
pub fn get_field_decls(&self, start: u32, len: u32) -> Vec<(Spur, Spur)>
Retrieve field declarations (name, type) from the extra array.
pub fn get_field_decls_with_vis(
&self,
start: u32,
len: u32,
) -> Vec<(Spur, Spur, bool)>
pub fn get_field_decls_with_vis( &self, start: u32, len: u32, ) -> Vec<(Spur, Spur, bool)>
Retrieve field declarations with visibility (ADR-0073).
pub fn add_directives(&mut self, directives: &[RirDirective]) -> (u32, u32)
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
pub fn get_directives(
&self,
start: u32,
directive_count: u32,
) -> Vec<RirDirective>
pub fn get_directives( &self, start: u32, directive_count: u32, ) -> Vec<RirDirective>
Retrieve directives from the extra array.
pub fn add_destructure_fields(
&mut self,
fields: &[RirDestructureField],
) -> (u32, u32)
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.
pub fn get_destructure_fields(
&self,
start: u32,
count: u32,
) -> Vec<RirDestructureField>
pub fn get_destructure_fields( &self, start: u32, count: u32, ) -> Vec<RirDestructureField>
Retrieve destructure fields from the extra array.
pub fn add_extern_fn(&mut self, extern_fn: RirExternFn)
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).
pub fn extern_fns(&self) -> &[RirExternFn]
pub fn extern_fns(&self) -> &[RirExternFn]
ADR-0085: read-only view over all extern fns declared in this file.
pub fn add_empty_link_extern_block(
&mut self,
library: Spur,
link_mode: RirLinkMode,
span: Span,
)
pub fn add_empty_link_extern_block( &mut self, library: Spur, link_mode: RirLinkMode, span: Span, )
ADR-0085: append an empty link_extern("lib") { } block.
pub fn empty_link_extern_blocks(&self) -> &[(Spur, RirLinkMode, Span)]
pub fn empty_link_extern_blocks(&self) -> &[(Spur, RirLinkMode, Span)]
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.
pub fn add_function_span(&mut self, span: FunctionSpan)
pub fn function_spans(&self) -> &[FunctionSpan]
pub fn function_spans(&self) -> &[FunctionSpan]
Get all function spans.
pub fn function_count(&self) -> usize
pub fn function_count(&self) -> usize
Get the number of functions.
pub fn function_view(&self, fn_span: &FunctionSpan) -> RirFunctionView<'_>
pub fn function_view(&self, fn_span: &FunctionSpan) -> RirFunctionView<'_>
Get a view of just one function’s instructions.
pub fn find_function(&self, name: Spur) -> Option<&FunctionSpan>
pub fn find_function(&self, name: Spur) -> Option<&FunctionSpan>
Find a function span by name.
pub fn current_inst_index(&self) -> u32
pub fn current_inst_index(&self) -> u32
Get the current instruction count (useful for tracking body start).
pub fn merge(rirs: &[Rir]) -> Rir
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§
§impl<'de> Deserialize<'de> for Rir
impl<'de> Deserialize<'de> for Rir
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rir, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rir, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl RemapSpurs for Rir
impl RemapSpurs for Rir
fn remap_spurs(&mut self, _table: &[Spur])
§impl Serialize for Rir
impl Serialize for Rir
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].