pub struct Lowerer<'gcx> {
pub struct_storage_base_slots: HashMap<VariableId, u64, FxBuildHasher>,
pub struct_field_offsets: HashMap<(StructId, usize), u64, FxBuildHasher>,
pub struct_field_memory_offsets: HashMap<(StructId, usize), u64, FxBuildHasher>,
/* private fields */
}Expand description
Lowering context for converting HIR to MIR.
Fields§
§struct_storage_base_slots: HashMap<VariableId, u64, FxBuildHasher>Mapping from struct state variable ID to base storage slot.
struct_field_offsets: HashMap<(StructId, usize), u64, FxBuildHasher>Cached struct field slot offsets: (struct_type_id, field_index) -> slot offset from base.
struct_field_memory_offsets: HashMap<(StructId, usize), u64, FxBuildHasher>Cached struct field memory offsets: (struct_type_id, field_index) -> byte offset from base.
Implementations§
Source§impl<'gcx> Lowerer<'gcx>
impl<'gcx> Lowerer<'gcx>
Sourcepub fn get_struct_field_slot_offset(
&mut self,
struct_id: StructId,
field_index: usize,
) -> u64
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.
Sourcepub fn calculate_memory_words_for_ty(&self, ty: Ty<'gcx>) -> u64
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).
Sourcepub fn get_struct_field_memory_offset(
&mut self,
struct_id: StructId,
field_index: usize,
) -> u64
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.
Sourcepub fn copy_storage_to_memory(
&mut self,
builder: &mut FunctionBuilder<'_>,
struct_id: StructId,
base_slot: u64,
mem_ptr: ValueId,
mem_offset: u64,
) -> u64
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.
Sourcepub fn copy_memory_to_storage(
&mut self,
builder: &mut FunctionBuilder<'_>,
struct_id: StructId,
base_slot: u64,
mem_ptr: ValueId,
mem_offset: u64,
) -> u64
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>
impl<'gcx> Lowerer<'gcx>
Sourcepub fn push_loop(&mut self, ctx: LoopContext)
pub fn push_loop(&mut self, ctx: LoopContext)
Pushes a loop context onto the stack.
Sourcepub fn current_loop(&self) -> Option<&LoopContext>
pub fn current_loop(&self) -> Option<&LoopContext>
Gets the current loop context, if any.
Sourcepub fn alloc_local_memory(&mut self, var_id: VariableId) -> u64
pub fn alloc_local_memory(&mut self, var_id: VariableId) -> u64
Allocates a memory slot for a local variable. Returns the memory offset.
Sourcepub fn get_local_memory_offset(&self, var_id: &VariableId) -> Option<u64>
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.
Sourcepub fn local_memory_addr(
&self,
builder: &mut FunctionBuilder<'_>,
offset: u64,
) -> ValueId
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.
Sourcepub fn immutable_scratch_addr(offset: u32) -> u64
pub fn immutable_scratch_addr(offset: u32) -> u64
Returns the constructor scratch address for an immutable word.
Sourcepub fn store_immutable_value(
&self,
builder: &mut FunctionBuilder<'_>,
offset: u32,
value: ValueId,
)
pub fn store_immutable_value( &self, builder: &mut FunctionBuilder<'_>, offset: u32, value: ValueId, )
Stages an immutable word in constructor memory.
Sourcepub fn load_immutable_value(
&self,
builder: &mut FunctionBuilder<'_>,
offset: u32,
) -> ValueId
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.
Sourcepub fn register_contract_bytecode(
&mut self,
contract_id: ContractId,
bytecode: Vec<u8>,
)
pub fn register_contract_bytecode( &mut self, contract_id: ContractId, bytecode: Vec<u8>, )
Registers a contract’s bytecode for use in new expressions.
Sourcepub fn get_contract_bytecode(
&self,
contract_id: ContractId,
) -> Option<&(Vec<u8>, usize)>
pub fn get_contract_bytecode( &self, contract_id: ContractId, ) -> Option<&(Vec<u8>, usize)>
Gets the bytecode for a contract, if registered.
Sourcepub fn lower_contract(&mut self, contract_id: ContractId)
pub fn lower_contract(&mut self, contract_id: ContractId)
Lowers a contract to MIR.
Sourcepub fn is_var_assigned(&self, var_id: &VariableId) -> bool
pub fn is_var_assigned(&self, var_id: &VariableId) -> bool
Returns true if a variable is assigned after declaration.
Sourcepub fn has_external_call(&self, expr: &Expr<'_>) -> bool
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> 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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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