Skip to main content

Lowerer

Struct Lowerer 

Source
pub struct Lowerer<'gcx> {
    pub struct_storage_base_slots: FxHashMap<VariableId, u64>,
    pub struct_field_offsets: FxHashMap<(StructId, usize), u64>,
    pub struct_field_memory_offsets: FxHashMap<(StructId, usize), u64>,
    /* private fields */
}
Expand description

Lowering context for converting HIR to MIR.

Fields§

§struct_storage_base_slots: FxHashMap<VariableId, u64>

Mapping from struct state variable ID to base storage slot.

§struct_field_offsets: FxHashMap<(StructId, usize), u64>

Cached struct field slot offsets: (struct_type_id, field_index) -> slot offset from base.

§struct_field_memory_offsets: FxHashMap<(StructId, usize), u64>

Cached struct field memory offsets: (struct_type_id, field_index) -> byte offset from base.

Implementations§

Source§

impl<'gcx> Lowerer<'gcx>

Source

pub fn get_struct_field_slot_offset( &mut self, struct_id: StructId, field_index: usize, ) -> u64

Gets the storage slot offset for a struct field.

Source

pub fn calculate_memory_words_for_ty(&self, ty: Ty<'gcx>) -> u64

Calculates the number of 32-byte memory words needed for a type (flattened for structs).

Source

pub fn get_struct_field_memory_offset( &mut self, struct_id: StructId, field_index: usize, ) -> u64

Gets the memory byte offset for a struct field.

Source

pub fn copy_storage_to_memory( &mut self, builder: &mut FunctionBuilder<'_>, struct_id: StructId, base_slot: u64, mem_ptr: ValueId, mem_offset: u64, ) -> u64

Recursively copies a struct from storage to memory. Handles nested structs by flattening them into contiguous memory. Returns the next memory offset after all fields are copied.

Source

pub fn copy_memory_to_storage( &mut self, builder: &mut FunctionBuilder<'_>, struct_id: StructId, base_slot: u64, mem_ptr: ValueId, mem_offset: u64, ) -> u64

Recursively copies a struct from memory to storage. Handles nested structs by reading from flattened memory layout. Returns the next memory offset after all fields are read.

Source§

impl<'gcx> Lowerer<'gcx>

Source

pub fn new(gcx: Gcx<'gcx>, name: Ident) -> Self

Creates a new lowerer.

Source

pub fn push_loop(&mut self, ctx: LoopContext)

Pushes a loop context onto the stack.

Source

pub fn pop_loop(&mut self)

Pops a loop context from the stack.

Source

pub fn current_loop(&self) -> Option<&LoopContext>

Gets the current loop context, if any.

Source

pub fn alloc_local_memory(&mut self, var_id: VariableId) -> u64

Allocates a memory slot for a local variable. Returns the memory offset.

Source

pub fn get_local_memory_offset(&self, var_id: &VariableId) -> Option<u64>

Gets the memory offset for a local variable, if it’s stored in memory.

Source

pub fn local_memory_addr( &self, builder: &mut FunctionBuilder<'_>, offset: u64, ) -> ValueId

Returns the address for a local memory slot in the current lowering context.

Source

pub fn immutable_scratch_addr(offset: u32) -> u64

Returns the constructor scratch address for an immutable word.

Source

pub fn store_immutable_value( &self, builder: &mut FunctionBuilder<'_>, offset: u32, value: ValueId, )

Stages an immutable word in constructor memory.

Source

pub fn load_immutable_value( &self, builder: &mut FunctionBuilder<'_>, offset: u32, ) -> ValueId

Loads an immutable word.

Runtime code reads a PUSH32 placeholder that the constructor patches with the staged value before returning the runtime code. The running constructor’s own placeholders are never patched, so constructor-context reads load the staged scratch word instead.

Source

pub fn register_contract_bytecode( &mut self, contract_id: ContractId, bytecode: Vec<u8>, )

Registers a contract’s bytecode for use in new expressions.

Source

pub fn get_contract_bytecode( &self, contract_id: ContractId, ) -> Option<&(Vec<u8>, usize)>

Gets the bytecode for a contract, if registered.

Source

pub fn lower_contract(&mut self, contract_id: ContractId)

Lowers a contract to MIR.

Source

pub fn finish(self) -> Module

Returns the completed module.

Source

pub fn is_var_assigned(&self, var_id: &VariableId) -> bool

Returns true if a variable is assigned after declaration.

Source

pub fn has_external_call(&self, expr: &Expr<'_>) -> bool

Checks if an expression contains an external call. External calls write their return data to shared memory at offset 0, so variables initialized from them must be stored in memory to preserve the value across subsequent calls.

Auto Trait Implementations§

§

impl<'gcx> !RefUnwindSafe for Lowerer<'gcx>

§

impl<'gcx> !UnwindSafe for Lowerer<'gcx>

§

impl<'gcx> Freeze for Lowerer<'gcx>

§

impl<'gcx> Send for Lowerer<'gcx>

§

impl<'gcx> Sync for Lowerer<'gcx>

§

impl<'gcx> Unpin for Lowerer<'gcx>

§

impl<'gcx> UnsafeUnpin for Lowerer<'gcx>

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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

Source§

type Output = T

Should always be Self
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> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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