pub trait Context {
Show 85 methods
// Required methods
fn entry_fn(&self) -> Option<CrateItem>;
fn all_local_items(&self) -> CrateItems;
fn mir_body(&self, item: DefId) -> Body;
fn has_body(&self, item: DefId) -> bool;
fn foreign_modules(&self, crate_num: CrateNum) -> Vec<ForeignModuleDef>;
fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>;
fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>;
fn foreign_module(&self, mod_def: ForeignModuleDef) -> ForeignModule;
fn foreign_items(&self, mod_def: ForeignModuleDef) -> Vec<ForeignDef>;
fn all_trait_decls(&self) -> TraitDecls;
fn trait_decls(&self, crate_num: CrateNum) -> TraitDecls;
fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl;
fn all_trait_impls(&self) -> ImplTraitDecls;
fn trait_impls(&self, crate_num: CrateNum) -> ImplTraitDecls;
fn trait_impl(&self, trait_impl: &ImplDef) -> ImplTrait;
fn generics_of(&self, def_id: DefId) -> Generics;
fn predicates_of(&self, def_id: DefId) -> GenericPredicates;
fn explicit_predicates_of(&self, def_id: DefId) -> GenericPredicates;
fn local_crate(&self) -> Crate;
fn external_crates(&self) -> Vec<Crate>;
fn find_crates(&self, name: &str) -> Vec<Crate>;
fn def_name(&self, def_id: DefId, trimmed: bool) -> Symbol;
fn get_attrs_by_path(
&self,
def_id: DefId,
attr: &[Symbol],
) -> Vec<Attribute>;
fn get_all_attrs(&self, def_id: DefId) -> Vec<Attribute>;
fn span_to_string(&self, span: Span) -> String;
fn get_filename(&self, span: &Span) -> Filename;
fn get_lines(&self, span: &Span) -> LineInfo;
fn item_kind(&self, item: CrateItem) -> ItemKind;
fn is_foreign_item(&self, item: DefId) -> bool;
fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind;
fn adt_kind(&self, def: AdtDef) -> AdtKind;
fn adt_is_box(&self, def: AdtDef) -> bool;
fn adt_is_simd(&self, def: AdtDef) -> bool;
fn adt_is_cstr(&self, def: AdtDef) -> bool;
fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig;
fn intrinsic(&self, item: DefId) -> Option<IntrinsicDef>;
fn intrinsic_name(&self, def: IntrinsicDef) -> Symbol;
fn closure_sig(&self, args: &GenericArgs) -> PolyFnSig;
fn adt_variants_len(&self, def: AdtDef) -> usize;
fn variant_name(&self, def: VariantDef) -> Symbol;
fn variant_fields(&self, def: VariantDef) -> Vec<FieldDef>;
fn eval_target_usize(&self, cnst: &MirConst) -> Result<u64, Error>;
fn eval_target_usize_ty(&self, cnst: &TyConst) -> Result<u64, Error>;
fn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>;
fn new_const_str(&self, value: &str) -> MirConst;
fn new_const_bool(&self, value: bool) -> MirConst;
fn try_new_const_uint(
&self,
value: u128,
uint_ty: UintTy,
) -> Result<MirConst, Error>;
fn try_new_ty_const_uint(
&self,
value: u128,
uint_ty: UintTy,
) -> Result<TyConst, Error>;
fn new_rigid_ty(&self, kind: RigidTy) -> Ty;
fn new_box_ty(&self, ty: Ty) -> Ty;
fn def_ty(&self, item: DefId) -> Ty;
fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty;
fn mir_const_pretty(&self, cnst: &MirConst) -> String;
fn span_of_an_item(&self, def_id: DefId) -> Span;
fn ty_const_pretty(&self, ct: TyConstId) -> String;
fn ty_pretty(&self, ty: Ty) -> String;
fn ty_kind(&self, ty: Ty) -> TyKind;
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty;
fn instance_body(&self, instance: InstanceDef) -> Option<Body>;
fn instance_ty(&self, instance: InstanceDef) -> Ty;
fn instance_args(&self, def: InstanceDef) -> GenericArgs;
fn instance_def_id(&self, instance: InstanceDef) -> DefId;
fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol;
fn is_empty_drop_shim(&self, def: InstanceDef) -> bool;
fn is_empty_async_drop_ctor_shim(&self, def: InstanceDef) -> bool;
fn mono_instance(&self, def_id: DefId) -> Instance;
fn requires_monomorphization(&self, def_id: DefId) -> bool;
fn resolve_instance(
&self,
def: FnDef,
args: &GenericArgs,
) -> Option<Instance>;
fn resolve_drop_in_place(&self, ty: Ty) -> Instance;
fn resolve_for_fn_ptr(
&self,
def: FnDef,
args: &GenericArgs,
) -> Option<Instance>;
fn resolve_closure(
&self,
def: ClosureDef,
args: &GenericArgs,
kind: ClosureKind,
) -> Option<Instance>;
fn eval_static_initializer(
&self,
def: StaticDef,
) -> Result<Allocation, Error>;
fn eval_instance(
&self,
def: InstanceDef,
const_ty: Ty,
) -> Result<Allocation, Error>;
fn global_alloc(&self, id: AllocId) -> GlobalAlloc;
fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>;
fn krate(&self, def_id: DefId) -> Crate;
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol;
fn target_info(&self) -> MachineInfo;
fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>;
fn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>;
fn ty_layout(&self, ty: Ty) -> Result<Layout, Error>;
fn layout_shape(&self, id: Layout) -> LayoutShape;
fn place_pretty(&self, place: &Place) -> String;
fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty;
fn unop_ty(&self, un_op: UnOp, arg: Ty) -> Ty;
}
Expand description
This trait defines the interface between stable_mir and the Rust compiler. Do not use this directly.
Required Methods§
fn entry_fn(&self) -> Option<CrateItem>
Sourcefn all_local_items(&self) -> CrateItems
fn all_local_items(&self) -> CrateItems
Retrieve all items of the local crate that have a MIR associated with them.
Sourcefn mir_body(&self, item: DefId) -> Body
fn mir_body(&self, item: DefId) -> Body
Retrieve the body of a function. This function will panic if the body is not available.
fn foreign_modules(&self, crate_num: CrateNum) -> Vec<ForeignModuleDef>
Sourcefn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>
fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>
Retrieve all functions defined in this crate.
Sourcefn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>
fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>
Retrieve all static items defined in this crate.
fn foreign_module(&self, mod_def: ForeignModuleDef) -> ForeignModule
fn foreign_items(&self, mod_def: ForeignModuleDef) -> Vec<ForeignDef>
fn all_trait_decls(&self) -> TraitDecls
fn trait_decls(&self, crate_num: CrateNum) -> TraitDecls
fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl
fn all_trait_impls(&self) -> ImplTraitDecls
fn trait_impls(&self, crate_num: CrateNum) -> ImplTraitDecls
fn trait_impl(&self, trait_impl: &ImplDef) -> ImplTrait
fn generics_of(&self, def_id: DefId) -> Generics
fn predicates_of(&self, def_id: DefId) -> GenericPredicates
fn explicit_predicates_of(&self, def_id: DefId) -> GenericPredicates
Sourcefn local_crate(&self) -> Crate
fn local_crate(&self) -> Crate
Get information about the local crate.
Sourcefn external_crates(&self) -> Vec<Crate>
fn external_crates(&self) -> Vec<Crate>
Retrieve a list of all external crates.
Sourcefn find_crates(&self, name: &str) -> Vec<Crate>
fn find_crates(&self, name: &str) -> Vec<Crate>
Find a crate with the given name.
Sourcefn get_attrs_by_path(&self, def_id: DefId, attr: &[Symbol]) -> Vec<Attribute>
fn get_attrs_by_path(&self, def_id: DefId, attr: &[Symbol]) -> Vec<Attribute>
Return attributes with the given attribute name.
Single segmented name like #[inline]
is specified as &["inline".to_string()]
.
Multi-segmented name like #[rustfmt::skip]
is specified as &["rustfmt".to_string(), "skip".to_string()]
.
Sourcefn get_all_attrs(&self, def_id: DefId) -> Vec<Attribute>
fn get_all_attrs(&self, def_id: DefId) -> Vec<Attribute>
Get all attributes of a definition.
Sourcefn span_to_string(&self, span: Span) -> String
fn span_to_string(&self, span: Span) -> String
Returns printable, human readable form of Span
Sourcefn get_filename(&self, span: &Span) -> Filename
fn get_filename(&self, span: &Span) -> Filename
Return filename from given Span
, for diagnostic purposes
Sourcefn is_foreign_item(&self, item: DefId) -> bool
fn is_foreign_item(&self, item: DefId) -> bool
Returns whether this is a foreign item.
Sourcefn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind
fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind
Returns the kind of a given foreign item.
Sourcefn adt_is_box(&self, def: AdtDef) -> bool
fn adt_is_box(&self, def: AdtDef) -> bool
Returns if the ADT is a box.
Sourcefn adt_is_simd(&self, def: AdtDef) -> bool
fn adt_is_simd(&self, def: AdtDef) -> bool
Returns whether this ADT is simd.
Sourcefn adt_is_cstr(&self, def: AdtDef) -> bool
fn adt_is_cstr(&self, def: AdtDef) -> bool
Returns whether this definition is a C string.
Sourcefn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig
fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig
Retrieve the function signature for the given generic arguments.
Sourcefn intrinsic(&self, item: DefId) -> Option<IntrinsicDef>
fn intrinsic(&self, item: DefId) -> Option<IntrinsicDef>
Retrieve the intrinsic definition if the item corresponds one.
Sourcefn intrinsic_name(&self, def: IntrinsicDef) -> Symbol
fn intrinsic_name(&self, def: IntrinsicDef) -> Symbol
Retrieve the plain function name of an intrinsic.
Sourcefn closure_sig(&self, args: &GenericArgs) -> PolyFnSig
fn closure_sig(&self, args: &GenericArgs) -> PolyFnSig
Retrieve the closure signature for the given generic arguments.
Sourcefn adt_variants_len(&self, def: AdtDef) -> usize
fn adt_variants_len(&self, def: AdtDef) -> usize
The number of variants in this ADT.
Sourcefn variant_name(&self, def: VariantDef) -> Symbol
fn variant_name(&self, def: VariantDef) -> Symbol
The name of a variant.
fn variant_fields(&self, def: VariantDef) -> Vec<FieldDef>
Sourcefn eval_target_usize(&self, cnst: &MirConst) -> Result<u64, Error>
fn eval_target_usize(&self, cnst: &MirConst) -> Result<u64, Error>
Evaluate constant as a target usize.
fn eval_target_usize_ty(&self, cnst: &TyConst) -> Result<u64, Error>
Sourcefn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>
fn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>
Create a new zero-sized constant.
Sourcefn new_const_str(&self, value: &str) -> MirConst
fn new_const_str(&self, value: &str) -> MirConst
Create a new constant that represents the given string value.
Sourcefn new_const_bool(&self, value: bool) -> MirConst
fn new_const_bool(&self, value: bool) -> MirConst
Create a new constant that represents the given boolean value.
Sourcefn try_new_const_uint(
&self,
value: u128,
uint_ty: UintTy,
) -> Result<MirConst, Error>
fn try_new_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<MirConst, Error>
Create a new constant that represents the given value.
fn try_new_ty_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<TyConst, Error>
Sourcefn new_rigid_ty(&self, kind: RigidTy) -> Ty
fn new_rigid_ty(&self, kind: RigidTy) -> Ty
Create a new type from the given kind.
Sourcefn new_box_ty(&self, ty: Ty) -> Ty
fn new_box_ty(&self, ty: Ty) -> Ty
Create a new box type, Box<T>
, for the given inner type T
.
Sourcefn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty
fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty
Returns the type of given definition instantiated with the given arguments.
Sourcefn mir_const_pretty(&self, cnst: &MirConst) -> String
fn mir_const_pretty(&self, cnst: &MirConst) -> String
Returns literal value of a const as a string.
Sourcefn span_of_an_item(&self, def_id: DefId) -> Span
fn span_of_an_item(&self, def_id: DefId) -> Span
Span
of an item
fn ty_const_pretty(&self, ct: TyConstId) -> String
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty
Sourcefn instance_body(&self, instance: InstanceDef) -> Option<Body>
fn instance_body(&self, instance: InstanceDef) -> Option<Body>
Get the body of an Instance which is already monomorphized.
Sourcefn instance_ty(&self, instance: InstanceDef) -> Ty
fn instance_ty(&self, instance: InstanceDef) -> Ty
Get the instance type with generic instantiations applied and lifetimes erased.
Sourcefn instance_args(&self, def: InstanceDef) -> GenericArgs
fn instance_args(&self, def: InstanceDef) -> GenericArgs
Get the instantiation types.
Sourcefn instance_def_id(&self, instance: InstanceDef) -> DefId
fn instance_def_id(&self, instance: InstanceDef) -> DefId
Get the instance.
Sourcefn instance_mangled_name(&self, instance: InstanceDef) -> Symbol
fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol
Get the instance mangled name.
Sourcefn is_empty_drop_shim(&self, def: InstanceDef) -> bool
fn is_empty_drop_shim(&self, def: InstanceDef) -> bool
Check if this is an empty DropGlue shim.
Sourcefn is_empty_async_drop_ctor_shim(&self, def: InstanceDef) -> bool
fn is_empty_async_drop_ctor_shim(&self, def: InstanceDef) -> bool
Check if this is an empty AsyncDropGlueCtor shim.
Sourcefn mono_instance(&self, def_id: DefId) -> Instance
fn mono_instance(&self, def_id: DefId) -> Instance
Convert a non-generic crate item into an instance. This function will panic if the item is generic.
Sourcefn requires_monomorphization(&self, def_id: DefId) -> bool
fn requires_monomorphization(&self, def_id: DefId) -> bool
Item requires monomorphization.
Sourcefn resolve_instance(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>
fn resolve_instance(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>
Resolve an instance from the given function definition and generic arguments.
Sourcefn resolve_drop_in_place(&self, ty: Ty) -> Instance
fn resolve_drop_in_place(&self, ty: Ty) -> Instance
Resolve an instance for drop_in_place for the given type.
Sourcefn resolve_for_fn_ptr(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>
fn resolve_for_fn_ptr(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>
Resolve instance for a function pointer.
Sourcefn resolve_closure(
&self,
def: ClosureDef,
args: &GenericArgs,
kind: ClosureKind,
) -> Option<Instance>
fn resolve_closure( &self, def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Option<Instance>
Resolve instance for a closure with the requested type.
Sourcefn eval_static_initializer(&self, def: StaticDef) -> Result<Allocation, Error>
fn eval_static_initializer(&self, def: StaticDef) -> Result<Allocation, Error>
Evaluate a static’s initializer.
Sourcefn eval_instance(
&self,
def: InstanceDef,
const_ty: Ty,
) -> Result<Allocation, Error>
fn eval_instance( &self, def: InstanceDef, const_ty: Ty, ) -> Result<Allocation, Error>
Try to evaluate an instance into a constant.
Sourcefn global_alloc(&self, id: AllocId) -> GlobalAlloc
fn global_alloc(&self, id: AllocId) -> GlobalAlloc
Retrieve global allocation for the given allocation ID.
Sourcefn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>
fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>
Retrieve the id for the virtual table.
fn krate(&self, def_id: DefId) -> Crate
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol
Sourcefn target_info(&self) -> MachineInfo
fn target_info(&self) -> MachineInfo
Return information about the target machine.
Sourcefn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>
fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>
Get an instance ABI.
Sourcefn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>
fn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>
Get the ABI of a function pointer.
Sourcefn layout_shape(&self, id: Layout) -> LayoutShape
fn layout_shape(&self, id: Layout) -> LayoutShape
Get the layout shape.
Sourcefn place_pretty(&self, place: &Place) -> String
fn place_pretty(&self, place: &Place) -> String
Get a debug string representation of a place.