stable_mir::mir::mono

Struct Instance

Source
pub struct Instance {
    pub kind: InstanceKind,
    pub def: InstanceDef,
}

Fields§

§kind: InstanceKind

The type of instance.

§def: InstanceDef

An ID used to get the instance definition from the compiler. Do not use this field directly.

Implementations§

Source§

impl Instance

Source

pub fn args(&self) -> GenericArgs

Get the arguments this instance was instantiated with.

Source

pub fn body(&self) -> Option<Body>

Get the body of an Instance.

The body will be eagerly monomorphized and all constants will already be evaluated.

This method will return the intrinsic fallback body if one was defined.

Source

pub fn has_body(&self) -> bool

Check whether this instance has a body available.

For intrinsics with fallback body, this will return true. It is up to the user to decide whether to specialize the intrinsic or to use its fallback body.

For more information on fallback body, see https://github.com/rust-lang/rust/issues/93145.

This call is much cheaper than instance.body().is_some(), since it doesn’t try to build the StableMIR body.

Source

pub fn is_foreign_item(&self) -> bool

Source

pub fn ty(&self) -> Ty

Get the instance type with generic instantiations applied and lifetimes erased.

Source

pub fn fn_abi(&self) -> Result<FnAbi, Error>

Retrieve information about this instance binary interface.

Source

pub fn mangled_name(&self) -> Symbol

Retrieve the instance’s mangled name used for calling the given instance.

This will also look up the correct name of instances from upstream crates.

Source

pub fn name(&self) -> Symbol

Retrieve the instance name for diagnostic messages.

This will return the specialized name, e.g., std::vec::Vec<u8>::new.

Source

pub fn trimmed_name(&self) -> Symbol

Return a trimmed name of the given instance including its args.

If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we trim its path and print only the name.

Source

pub fn intrinsic_name(&self) -> Option<Symbol>

Retrieve the plain intrinsic name of an instance if it’s an intrinsic.

The plain name does not include type arguments (as trimmed_name does), which is more convenient to match with intrinsic symbols.

Source

pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>

Resolve an instance starting from a function definition and generic arguments.

Source

pub fn resolve_drop_in_place(ty: Ty) -> Instance

Resolve the drop in place for a given type.

Source

pub fn resolve_for_fn_ptr( def: FnDef, args: &GenericArgs, ) -> Result<Instance, Error>

Resolve an instance for a given function pointer.

Source

pub fn resolve_closure( def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Result<Instance, Error>

Resolve a closure with the expected kind.

Source

pub fn is_empty_shim(&self) -> bool

Check whether this instance is an empty shim.

Allow users to check if this shim can be ignored when called directly.

We have decided not to export different types of Shims to StableMIR users, however, this is a query that can be very helpful for users when processing DropGlue.

When generating code for a Drop terminator, users can ignore an empty drop glue. These shims are only needed to generate a valid Drop call done via VTable.

Source

pub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error>

Try to constant evaluate the instance into a constant with the given type.

This can be used to retrieve a constant that represents an intrinsic return such as type_id.

Source

pub fn emit_mir<W: Write>(&self, w: &mut W) -> Result<()>

Emit the body of this instance if it has one.

Trait Implementations§

Source§

impl Clone for Instance

Source§

fn clone(&self) -> Instance

Returns a copy 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 Instance

Source§

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

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

impl From<Instance> for MonoItem

Source§

fn from(value: Instance) -> Self

Converts to this type from the input type.
Source§

impl From<StaticDef> for Instance

Source§

fn from(value: StaticDef) -> Self

Converts to this type from the input type.
Source§

impl Hash for Instance

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Instance

Source§

fn eq(&self, other: &Instance) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Instance

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

impl TryFrom<CrateItem> for Instance

Try to convert a crate item into an instance. The item cannot be generic in order to be converted into an instance.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(item: CrateItem) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Instance> for CrateItem

Try to convert an instance into a crate item. Only user defined instances can be converted.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Instance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Instance> for StaticDef

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Instance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Instance

Source§

impl Eq for Instance

Source§

impl StructuralPartialEq for Instance

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes