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
impl Instance
Sourcepub fn args(&self) -> GenericArgs
pub fn args(&self) -> GenericArgs
Get the arguments this instance was instantiated with.
Sourcepub fn body(&self) -> Option<Body>
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.
Sourcepub fn has_body(&self) -> bool
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.
pub fn is_foreign_item(&self) -> bool
Sourcepub fn ty(&self) -> Ty
pub fn ty(&self) -> Ty
Get the instance type with generic instantiations applied and lifetimes erased.
Sourcepub fn fn_abi(&self) -> Result<FnAbi, Error>
pub fn fn_abi(&self) -> Result<FnAbi, Error>
Retrieve information about this instance binary interface.
Sourcepub fn mangled_name(&self) -> Symbol
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.
Sourcepub fn name(&self) -> Symbol
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
.
Sourcepub fn trimmed_name(&self) -> Symbol
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.
Sourcepub fn intrinsic_name(&self) -> Option<Symbol>
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.
Sourcepub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>
Resolve an instance starting from a function definition and generic arguments.
Sourcepub fn resolve_drop_in_place(ty: Ty) -> Instance
pub fn resolve_drop_in_place(ty: Ty) -> Instance
Resolve the drop in place for a given type.
Sourcepub fn resolve_for_fn_ptr(
def: FnDef,
args: &GenericArgs,
) -> Result<Instance, Error>
pub fn resolve_for_fn_ptr( def: FnDef, args: &GenericArgs, ) -> Result<Instance, Error>
Resolve an instance for a given function pointer.
Sourcepub fn resolve_closure(
def: ClosureDef,
args: &GenericArgs,
kind: ClosureKind,
) -> Result<Instance, Error>
pub fn resolve_closure( def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Result<Instance, Error>
Resolve a closure with the expected kind.
Sourcepub fn is_empty_shim(&self) -> bool
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.
Sourcepub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error>
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
.
Trait Implementations§
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.
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§impl TryFrom<Instance> for CrateItem
Try to convert an instance into a crate item.
Only user defined instances can be converted.
impl TryFrom<Instance> for CrateItem
Try to convert an instance into a crate item. Only user defined instances can be converted.
impl Copy for Instance
impl Eq for Instance
impl StructuralPartialEq for Instance
Auto Trait Implementations§
impl Freeze for Instance
impl RefUnwindSafe for Instance
impl Send for Instance
impl Sync for Instance
impl Unpin for Instance
impl UnwindSafe for Instance
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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