Skip to main content

Function

Struct Function 

Source
pub struct Function {
    pub name: Ident,
    pub selector: Option<[u8; 4]>,
    pub attributes: FunctionAttributes,
    pub params: Vec<MirType>,
    pub returns: Vec<MirType>,
    pub internal_frame_size: u64,
    pub external_static_return_size: u64,
    pub values: IndexVec<ValueId, Value>,
    pub instructions: IndexVec<InstId, Instruction>,
    pub blocks: IndexVec<BlockId, BasicBlock>,
    pub entry_block: BlockId,
}
Expand description

A function in the MIR.

Fields§

§name: Ident

Function name.

§selector: Option<[u8; 4]>

Function selector (4 bytes, for external functions).

§attributes: FunctionAttributes

Function attributes.

§params: Vec<MirType>

Parameter types.

§returns: Vec<MirType>

Return types.

§internal_frame_size: u64

Bytes reserved for lowered local memory slots.

Internal-call functions place these in the internal frame; external entries reserve the same space in their low-memory scratch layout.

§external_static_return_size: u64

Bytes reserved for the low-memory external ABI return buffer.

§values: IndexVec<ValueId, Value>

All values in this function.

§instructions: IndexVec<InstId, Instruction>

All instructions in this function.

§blocks: IndexVec<BlockId, BasicBlock>

All basic blocks in this function.

§entry_block: BlockId

The entry block.

Implementations§

Source§

impl Function

Source

pub fn new(name: Ident) -> Function

Creates a new function.

Source

pub fn value(&self, id: ValueId) -> &Value

Returns the value for the given ID.

Source

pub fn value_u256(&self, id: ValueId) -> Option<Uint<256, 4>>

Returns an immediate value as U256.

Source

pub fn value_u64(&self, id: ValueId) -> Option<u64>

Returns an immediate value as u64 when lossless.

Source

pub fn value_u256_after_replacements( &self, id: ValueId, replacements: &HashMap<ValueId, ValueId, FxBuildHasher>, ) -> Option<Uint<256, 4>>

Returns a possibly replaced immediate value as U256.

Source

pub fn memory_region_for_addr(&self, addr: ValueId) -> MemoryRegion

Returns the statically known memory region for an address value.

Source

pub fn instruction(&self, id: InstId) -> &Instruction

Returns the instruction for the given ID.

Source

pub fn inst_result_value(&self, id: InstId) -> Option<ValueId>

Returns the value produced by the given instruction, if it has one.

Source

pub fn inst_results(&self) -> HashMap<InstId, ValueId, FxBuildHasher>

Returns a map from each instruction to its result value.

Source

pub fn inst_blocks(&self) -> HashMap<InstId, BlockId, FxBuildHasher>

Returns a map from each instruction to the block containing it.

Source

pub fn unique_predecessors(&self, block: BlockId) -> Vec<BlockId>

Returns predecessors with duplicate CFG edges collapsed.

Source

pub fn block_has_phi(&self, block: BlockId) -> bool

Returns true if the block contains any phi instruction.

Source

pub fn block_has_only_phis(&self, block: BlockId) -> bool

Returns true if every instruction in the block is a phi instruction.

Source

pub fn block_phi_results( &self, block: BlockId, ) -> HashSet<ValueId, FxBuildHasher>

Returns the result values produced by phi instructions in the block.

Source

pub fn block(&self, id: BlockId) -> &BasicBlock

Returns the basic block for the given ID.

Source

pub fn block_mut(&mut self, id: BlockId) -> &mut BasicBlock

Returns a mutable reference to the basic block.

Source

pub fn entry(&self) -> &BasicBlock

Returns the entry block.

Source

pub fn alloc_value(&mut self, value: Value) -> ValueId

Allocates a new value.

Source

pub fn alloc_inst(&mut self, inst: Instruction) -> InstId

Allocates a new instruction.

Source

pub fn alloc_block(&mut self) -> BlockId

Allocates a new basic block.

Source

pub fn replace_uses( &mut self, replacements: &HashMap<ValueId, ValueId, FxBuildHasher>, )

Replaces all value uses according to a one-step replacement map.

Source

pub fn replace_uses_canonicalized( &mut self, replacements: &HashMap<ValueId, ValueId, FxBuildHasher>, )

Replaces all value uses according to a canonicalized replacement map.

Source

pub fn storage_alias(&self, inst_id: InstId, slot: ValueId) -> StorageAlias

Returns stored storage-alias metadata, or computes a conservative alias key.

Source

pub fn storage_alias_after_replacements( &self, inst_id: InstId, slot: ValueId, replacements: &HashMap<ValueId, ValueId, FxBuildHasher>, ) -> StorageAlias

Returns storage-alias metadata after applying value replacements.

Source

pub fn is_public(&self) -> bool

Returns true if this function is public or external.

Source

pub fn selector_hex(&self) -> Option<String>

Returns the function selector as a hex string.

Source

pub fn to_text(&self) -> impl Display

Returns the human-readable textual MIR representation of this function.

Source

pub fn to_dot(&self) -> impl Display

Returns this function’s DOT-format CFG.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

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 Debug for Function

Source§

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

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

impl Display for Function

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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> 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.
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