pub struct SmirCtxt<'tcx>(pub RefCell<Tables<'tcx>>);
Expand description
Provides direct access to rustc’s internal queries.
The crate::stable_mir::compiler_interface::SmirInterface
must go through
this context to obtain rustc-level information.
Tuple Fields§
§0: RefCell<Tables<'tcx>>
Implementations§
Source§impl<'tcx> SmirCtxt<'tcx>
impl<'tcx> SmirCtxt<'tcx>
pub fn target_info(&self) -> MachineInfo
pub fn entry_fn(&self) -> Option<CrateItem>
Sourcepub fn all_local_items(&self) -> CrateItems
pub fn all_local_items(&self) -> CrateItems
Retrieve all items of the local crate that have a MIR associated with them.
Sourcepub fn mir_body(&self, item: DefId) -> Body
pub fn mir_body(&self, item: DefId) -> Body
Retrieve the body of a function. This function will panic if the body is not available.
pub fn foreign_modules(&self, crate_num: CrateNum) -> Vec<ForeignModuleDef>
Sourcepub fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>
pub fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>
Retrieve all functions defined in this crate.
Sourcepub fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>
pub fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>
Retrieve all static items defined in this crate.
pub fn foreign_module(&self, mod_def: ForeignModuleDef) -> ForeignModule
pub fn foreign_items(&self, mod_def: ForeignModuleDef) -> Vec<ForeignDef>
pub fn all_trait_decls(&self) -> TraitDecls
pub fn trait_decls(&self, crate_num: CrateNum) -> TraitDecls
pub fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl
pub fn all_trait_impls(&self) -> ImplTraitDecls
pub fn trait_impls(&self, crate_num: CrateNum) -> ImplTraitDecls
pub fn trait_impl(&self, impl_def: &ImplDef) -> ImplTrait
pub fn generics_of(&self, def_id: DefId) -> Generics
pub fn predicates_of(&self, def_id: DefId) -> GenericPredicates
pub fn explicit_predicates_of(&self, def_id: DefId) -> GenericPredicates
Sourcepub fn local_crate(&self) -> Crate
pub fn local_crate(&self) -> Crate
Get information about the local crate.
Sourcepub fn external_crates(&self) -> Vec<Crate>
pub fn external_crates(&self) -> Vec<Crate>
Retrieve a list of all external crates.
Sourcepub fn find_crates(&self, name: &str) -> Vec<Crate>
pub fn find_crates(&self, name: &str) -> Vec<Crate>
Find a crate with the given name.
Sourcepub fn def_name(&self, def_id: DefId, trimmed: bool) -> Symbol
pub fn def_name(&self, def_id: DefId, trimmed: bool) -> Symbol
Returns the name of given DefId
.
Sourcepub fn tool_attrs(&self, def_id: DefId, attr: &[Symbol]) -> Vec<Attribute>
pub fn tool_attrs(&self, def_id: DefId, attr: &[Symbol]) -> Vec<Attribute>
Return registered tool attributes with the given attribute name.
FIXME(jdonszelmann): may panic on non-tool attributes. After more attribute work, non-tool attributes will simply return an empty list.
Single segmented name like #[clippy]
is specified as &["clippy".to_string()]
.
Multi-segmented name like #[rustfmt::skip]
is specified as &["rustfmt".to_string(), "skip".to_string()]
.
Sourcepub fn all_tool_attrs(&self, def_id: DefId) -> Vec<Attribute>
pub fn all_tool_attrs(&self, def_id: DefId) -> Vec<Attribute>
Get all tool attributes of a definition.
Sourcepub fn span_to_string(&self, span: Span) -> String
pub fn span_to_string(&self, span: Span) -> String
Returns printable, human readable form of Span
.
Sourcepub fn get_filename(&self, span: &Span) -> Filename
pub fn get_filename(&self, span: &Span) -> Filename
Return filename from given Span
, for diagnostic purposes.
Sourcepub fn is_foreign_item(&self, item: DefId) -> bool
pub fn is_foreign_item(&self, item: DefId) -> bool
Returns whether this is a foreign item.
Sourcepub fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind
pub fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind
Returns the kind of a given foreign item.
Sourcepub fn adt_kind(&self, def: AdtDef) -> AdtKind
pub fn adt_kind(&self, def: AdtDef) -> AdtKind
Returns the kind of a given algebraic data type.
Sourcepub fn adt_is_box(&self, def: AdtDef) -> bool
pub fn adt_is_box(&self, def: AdtDef) -> bool
Returns if the ADT is a box.
Sourcepub fn adt_is_simd(&self, def: AdtDef) -> bool
pub fn adt_is_simd(&self, def: AdtDef) -> bool
Returns whether this ADT is simd.
Sourcepub fn adt_is_cstr(&self, def: AdtDef) -> bool
pub fn adt_is_cstr(&self, def: AdtDef) -> bool
Returns whether this definition is a C string.
Sourcepub fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig
pub fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig
Retrieve the function signature for the given generic arguments.
Sourcepub fn intrinsic(&self, def: DefId) -> Option<IntrinsicDef>
pub fn intrinsic(&self, def: DefId) -> Option<IntrinsicDef>
Retrieve the intrinsic definition if the item corresponds one.
Sourcepub fn intrinsic_name(&self, def: IntrinsicDef) -> Symbol
pub fn intrinsic_name(&self, def: IntrinsicDef) -> Symbol
Retrieve the plain function name of an intrinsic.
Sourcepub fn closure_sig(&self, args: &GenericArgs) -> PolyFnSig
pub fn closure_sig(&self, args: &GenericArgs) -> PolyFnSig
Retrieve the closure signature for the given generic arguments.
Sourcepub fn adt_variants_len(&self, def: AdtDef) -> usize
pub fn adt_variants_len(&self, def: AdtDef) -> usize
The number of variants in this ADT.
Sourcepub fn variant_name(&self, def: VariantDef) -> Symbol
pub fn variant_name(&self, def: VariantDef) -> Symbol
The name of a variant.
pub fn variant_fields(&self, def: VariantDef) -> Vec<FieldDef>
Sourcepub fn eval_target_usize(&self, cnst: &MirConst) -> Result<u64, Error>
pub fn eval_target_usize(&self, cnst: &MirConst) -> Result<u64, Error>
Evaluate constant as a target usize.
pub fn eval_target_usize_ty(&self, cnst: &TyConst) -> Result<u64, Error>
Sourcepub fn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>
pub fn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>
Create a new zero-sized constant.
Sourcepub fn new_const_str(&self, value: &str) -> MirConst
pub fn new_const_str(&self, value: &str) -> MirConst
Create a new constant that represents the given string value.
Sourcepub fn new_const_bool(&self, value: bool) -> MirConst
pub fn new_const_bool(&self, value: bool) -> MirConst
Create a new constant that represents the given boolean value.
Sourcepub fn try_new_const_uint(
&self,
value: u128,
uint_ty: UintTy,
) -> Result<MirConst, Error>
pub fn try_new_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<MirConst, Error>
Create a new constant that represents the given value.
pub fn try_new_ty_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<TyConst, Error>
Sourcepub fn new_rigid_ty(&self, kind: RigidTy) -> Ty
pub fn new_rigid_ty(&self, kind: RigidTy) -> Ty
Create a new type from the given kind.
Sourcepub fn new_box_ty(&self, ty: Ty) -> Ty
pub fn new_box_ty(&self, ty: Ty) -> Ty
Create a new box type, Box<T>
, for the given inner type T
.
Sourcepub fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty
pub fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty
Returns the type of given definition instantiated with the given arguments.
Sourcepub fn mir_const_pretty(&self, cnst: &MirConst) -> String
pub fn mir_const_pretty(&self, cnst: &MirConst) -> String
Returns literal value of a const as a string.
Sourcepub fn span_of_an_item(&self, def_id: DefId) -> Span
pub fn span_of_an_item(&self, def_id: DefId) -> Span
Span
of an item.
pub fn ty_const_pretty(&self, ct: TyConstId) -> String
Sourcepub fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty
pub fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty
Get the discriminant Ty for this Ty if there’s one.
Sourcepub fn instance_body(&self, def: InstanceDef) -> Option<Body>
pub fn instance_body(&self, def: InstanceDef) -> Option<Body>
Get the body of an Instance which is already monomorphized.
Sourcepub fn instance_ty(&self, def: InstanceDef) -> Ty
pub fn instance_ty(&self, def: InstanceDef) -> Ty
Get the instance type with generic instantiations applied and lifetimes erased.
Sourcepub fn instance_args(&self, def: InstanceDef) -> GenericArgs
pub fn instance_args(&self, def: InstanceDef) -> GenericArgs
Get the instantiation types.
Sourcepub fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>
pub fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>
Get an instance ABI.
Sourcepub fn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>
pub fn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>
Get the ABI of a function pointer.
Sourcepub fn instance_def_id(&self, def: InstanceDef) -> DefId
pub fn instance_def_id(&self, def: InstanceDef) -> DefId
Get the instance.
Sourcepub fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol
pub fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol
Get the instance mangled name.
Sourcepub fn is_empty_drop_shim(&self, def: InstanceDef) -> bool
pub fn is_empty_drop_shim(&self, def: InstanceDef) -> bool
Check if this is an empty DropGlue shim.
Sourcepub fn mono_instance(&self, def_id: DefId) -> Instance
pub 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.
Sourcepub fn requires_monomorphization(&self, def_id: DefId) -> bool
pub fn requires_monomorphization(&self, def_id: DefId) -> bool
Item requires monomorphization.
Sourcepub fn resolve_instance(
&self,
def: FnDef,
args: &GenericArgs,
) -> Option<Instance>
pub fn resolve_instance( &self, def: FnDef, args: &GenericArgs, ) -> Option<Instance>
Resolve an instance from the given function definition and generic arguments.
Sourcepub fn resolve_drop_in_place(&self, ty: Ty) -> Instance
pub fn resolve_drop_in_place(&self, ty: Ty) -> Instance
Resolve an instance for drop_in_place for the given type.
Sourcepub fn resolve_for_fn_ptr(
&self,
def: FnDef,
args: &GenericArgs,
) -> Option<Instance>
pub fn resolve_for_fn_ptr( &self, def: FnDef, args: &GenericArgs, ) -> Option<Instance>
Resolve instance for a function pointer.
Sourcepub fn resolve_closure(
&self,
def: ClosureDef,
args: &GenericArgs,
kind: ClosureKind,
) -> Option<Instance>
pub fn resolve_closure( &self, def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Option<Instance>
Resolve instance for a closure with the requested type.
Sourcepub fn eval_instance(
&self,
def: InstanceDef,
const_ty: Ty,
) -> Result<Allocation, Error>
pub fn eval_instance( &self, def: InstanceDef, const_ty: Ty, ) -> Result<Allocation, Error>
Try to evaluate an instance into a constant.
Sourcepub fn eval_static_initializer(
&self,
def: StaticDef,
) -> Result<Allocation, Error>
pub fn eval_static_initializer( &self, def: StaticDef, ) -> Result<Allocation, Error>
Evaluate a static’s initializer.
Sourcepub fn global_alloc(&self, alloc: AllocId) -> GlobalAlloc
pub fn global_alloc(&self, alloc: AllocId) -> GlobalAlloc
Retrieve global allocation for the given allocation ID.
Sourcepub fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>
pub fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>
Retrieve the id for the virtual table.
pub fn krate(&self, def_id: DefId) -> Crate
Sourcepub fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol
pub fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol
Retrieve the instance name for diagnostic messages.
This will return the specialized name, e.g., Vec<char>::new
.
Sourcepub fn layout_shape(&self, id: Layout) -> LayoutShape
pub fn layout_shape(&self, id: Layout) -> LayoutShape
Get the layout shape.
Sourcepub fn place_pretty(&self, place: &Place) -> String
pub fn place_pretty(&self, place: &Place) -> String
Get a debug string representation of a place.
Sourcepub fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty
pub fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty
Get the resulting type of binary operation.
Sourcepub fn associated_items(&self, def_id: DefId) -> AssocItems
pub fn associated_items(&self, def_id: DefId) -> AssocItems
Get all associated items of a definition.
Auto Trait Implementations§
impl<'tcx> DynSend for SmirCtxt<'tcx>
impl<'tcx> !DynSync for SmirCtxt<'tcx>
impl<'tcx> !Freeze for SmirCtxt<'tcx>
impl<'tcx> !RefUnwindSafe for SmirCtxt<'tcx>
impl<'tcx> !Send for SmirCtxt<'tcx>
impl<'tcx> !Sync for SmirCtxt<'tcx>
impl<'tcx> Unpin for SmirCtxt<'tcx>
impl<'tcx> !UnwindSafe for SmirCtxt<'tcx>
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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
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: 464 bytes