Struct stable_mir::mir::mono::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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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.

§

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.

§

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

§

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

§

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

§

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

§

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