Struct SmirCtxt

Source
pub struct SmirCtxt<'tcx, B: Bridge> {
    pub tcx: TyCtxt<'tcx>,
    _marker: PhantomData<B>,
}
Expand description

Provides direct access to rustc’s internal queries.

SmirInterface must go through this context to obtain rustc-level information.

Fields§

§tcx: TyCtxt<'tcx>§_marker: PhantomData<B>

Implementations§

Source§

impl<'tcx, B: Bridge> SmirCtxt<'tcx, B>

Source

pub fn lift<T: Lift<TyCtxt<'tcx>>>(&self, value: T) -> Option<T::Lifted>

Source

pub fn adt_def(&self, def_id: DefId) -> AdtDef<'tcx>

Source

pub fn coroutine_movability(&self, def_id: DefId) -> Movability

Source

pub fn valtree_to_const_val(&self, key: Value<'tcx>) -> ConstValue<'tcx>

Source

pub(crate) fn instance_has_body(&self, instance: Instance<'tcx>) -> bool

Return whether the instance as a body available.

Items and intrinsics may have a body available from its definition. Shims body may be generated depending on their type.

Source

pub(crate) fn item_has_body(&self, def_id: DefId) -> bool

Return whether the item has a body defined by the user.

Note that intrinsics may have a placeholder body that shouldn’t be used in practice. In StableMIR, we handle this case as if the body is not available.

Source

fn filter_fn_def(&self, def_id: DefId) -> Option<DefId>

Source

fn filter_static_def(&self, def_id: DefId) -> Option<DefId>

Source

pub fn target_endian(&self) -> Endian

Source

pub fn target_pointer_size(&self) -> usize

Source

pub fn entry_fn(&self) -> Option<DefId>

Source

pub fn all_local_items(&self) -> Vec<DefId>

Retrieve all items of the local crate that have a MIR associated with them.

Source

pub fn mir_body(&self, item: DefId) -> &'tcx Body<'tcx>

Retrieve the body of a function. This function will panic if the body is not available.

Source

pub fn has_body(&self, def: DefId) -> bool

Check whether the body of a function is available.

Source

pub fn foreign_modules(&self, crate_num: CrateNum) -> Vec<DefId>

Source

pub fn crate_functions(&self, crate_num: CrateNum) -> Vec<DefId>

Retrieve all functions defined in this crate.

Source

pub fn crate_statics(&self, crate_num: CrateNum) -> Vec<DefId>

Retrieve all static items defined in this crate.

Source

pub fn foreign_module(&self, mod_def: DefId) -> &ForeignModule

Source

pub fn foreign_items(&self, mod_def: DefId) -> Vec<DefId>

Source

pub fn all_trait_decls(&self) -> impl Iterator<Item = DefId>

Source

pub fn trait_decls(&self, crate_num: CrateNum) -> Vec<DefId>

Source

pub fn trait_decl(&self, trait_def: DefId) -> &'tcx TraitDef

Source

pub fn all_trait_impls(&self) -> Vec<DefId>

Source

pub fn trait_impls(&self, crate_num: CrateNum) -> Vec<DefId>

Source

pub fn trait_impl(&self, impl_def: DefId) -> EarlyBinder<'tcx, TraitRef<'tcx>>

Source

pub fn generics_of(&self, def_id: DefId) -> &'tcx Generics

Source

pub fn predicates_of( &self, def_id: DefId, ) -> (Option<DefId>, Vec<(PredicateKind<'tcx>, Span)>)

Source

pub fn explicit_predicates_of( &self, def_id: DefId, ) -> (Option<DefId>, Vec<(PredicateKind<'tcx>, Span)>)

Source

pub fn crate_name(&self, crate_num: CrateNum) -> String

Source

pub fn crate_is_local(&self, crate_num: CrateNum) -> bool

Source

pub fn crate_num_id(&self, crate_num: CrateNum) -> usize

Source

pub fn local_crate_num(&self) -> CrateNum

Source

pub fn external_crates(&self) -> Vec<CrateNum>

Retrieve a list of all external crates.

Source

pub fn find_crates(&self, name: &str) -> Vec<CrateNum>

Find a crate with the given name.

Source

pub fn def_name(&self, def_id: DefId, trimmed: bool) -> String

Returns the name of given DefId.

Source

pub fn tool_attrs(&self, def_id: DefId, attr: &[String]) -> Vec<(String, Span)>

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()].

Source

pub fn all_tool_attrs(&self, did: DefId) -> Vec<(String, Span)>

Get all tool attributes of a definition.

Source

pub fn span_to_string(&self, span: Span) -> String

Returns printable, human readable form of Span.

Source

pub fn get_filename(&self, span: Span) -> String

Return filename from given Span, for diagnostic purposes.

Source

pub fn get_lines(&self, span: Span) -> (usize, usize, usize, usize)

Return lines corresponding to this Span.

Source

pub fn def_kind(&self, item: DefId) -> DefKind

Returns the kind of given DefId.

Source

pub fn is_foreign_item(&self, item: DefId) -> bool

Returns whether this is a foreign item.

Source

pub fn foreign_item_kind(&self, def_id: DefId) -> DefKind

Returns the kind of a given foreign item.

Source

pub fn adt_kind(&self, def: AdtDef<'tcx>) -> AdtKind

Returns the kind of a given algebraic data type.

Source

pub fn adt_is_box(&self, def: AdtDef<'tcx>) -> bool

Returns if the ADT is a box.

Source

pub fn adt_is_simd(&self, def: AdtDef<'tcx>) -> bool

Returns whether this ADT is simd.

Source

pub fn adt_is_cstr(&self, def_id: DefId) -> bool

Returns whether this definition is a C string.

Source

pub fn adt_repr(&self, def: AdtDef<'tcx>) -> ReprOptions

Returns the representation options for this ADT.

Source

pub fn fn_sig( &self, def_id: DefId, args_ref: GenericArgsRef<'tcx>, ) -> Binder<'tcx, FnSig<'tcx>>

Retrieve the function signature for the given generic arguments.

Source

pub fn intrinsic(&self, def_id: DefId) -> Option<IntrinsicDef>

Retrieve the intrinsic definition if the item corresponds one.

Source

pub fn intrinsic_name(&self, def_id: DefId) -> String

Retrieve the plain function name of an intrinsic.

Source

pub fn closure_sig( &self, args_ref: GenericArgsRef<'tcx>, ) -> Binder<'tcx, FnSig<'tcx>>

Retrieve the closure signature for the given generic arguments.

Source

pub fn adt_variants_len(&self, def: AdtDef<'tcx>) -> usize

The number of variants in this ADT.

Source

pub fn adt_discr_for_variant( &self, adt: AdtDef<'tcx>, variant: VariantIdx, ) -> Discr<'tcx>

Discriminant for a given variant index of AdtDef.

Source

pub fn coroutine_discr_for_variant( &self, coroutine: DefId, args: GenericArgsRef<'tcx>, variant: VariantIdx, ) -> Discr<'tcx>

Discriminant for a given variand index and args of a coroutine.

Source

pub fn variant_name(&self, def: &'tcx VariantDef) -> String

The name of a variant.

Source

pub fn eval_target_usize(&self, cnst: MirConst<'tcx>) -> Result<u64, B::Error>

Evaluate constant as a target usize.

Source

pub fn eval_target_usize_ty(&self, cnst: Const<'tcx>) -> Result<u64, B::Error>

Source

pub fn try_new_const_zst( &self, ty_internal: Ty<'tcx>, ) -> Result<MirConst<'tcx>, B::Error>

Source

pub fn const_zero_sized(&self, ty_internal: Ty<'tcx>) -> Const<'tcx>

Source

pub fn new_const_str(&self, value: &str) -> MirConst<'tcx>

Create a new constant that represents the given string value.

Source

pub fn new_const_bool(&self, value: bool) -> MirConst<'tcx>

Create a new constant that represents the given boolean value.

Source

pub fn try_new_const_uint( &self, value: u128, ty_internal: Ty<'tcx>, ) -> Result<MirConst<'tcx>, B::Error>

Source

pub fn try_new_ty_const_uint( &self, value: u128, ty_internal: Ty<'tcx>, ) -> Result<Const<'tcx>, B::Error>

Source

pub fn ty_new_uint(&self, ty: UintTy) -> Ty<'tcx>

Source

pub fn mir_const_from_scalar(&self, s: Scalar, ty: Ty<'tcx>) -> MirConst<'tcx>

Source

pub fn ty_const_new_value( &self, valtree: ValTree<'tcx>, ty: Ty<'tcx>, ) -> Const<'tcx>

Source

pub fn ty_valtree_from_scalar_int(&self, i: ScalarInt) -> ValTree<'tcx>

Source

pub fn new_rigid_ty(&self, internal_kind: TyKind<'tcx>) -> Ty<'tcx>

Create a new type from the given kind.

Source

pub fn new_box_ty(&self, ty: Ty<'tcx>) -> Ty<'tcx>

Create a new box type, Box<T>, for the given inner type T.

Source

pub fn def_ty(&self, item: DefId) -> Ty<'tcx>

Returns the type of given crate item.

Source

pub fn def_ty_with_args( &self, item: DefId, args_ref: GenericArgsRef<'tcx>, ) -> Ty<'tcx>

Returns the type of given definition instantiated with the given arguments.

Source

pub fn span_of_an_item(&self, def_id: DefId) -> Span

Span of an item.

Source

pub fn ty_const_pretty(&self, ct: Const<'tcx>) -> String

Source

pub fn ty_pretty(&self, ty: Ty<'tcx>) -> String

Obtain the representation of a type.

Source

pub fn ty_kind(&self, ty: Ty<'tcx>) -> &'tcx TyKind<'tcx>

Obtain the kind of a type.

Source

pub fn rigid_ty_discriminant_ty(&self, internal_kind: TyKind<'tcx>) -> Ty<'tcx>

Get the discriminant Ty for this Ty if there’s one.

Source

pub fn instance_body(&self, instance: Instance<'tcx>) -> Option<Body<'tcx>>

Get the body of an Instance which is already monomorphized.

Source

pub fn instance_ty(&self, instance: Instance<'tcx>) -> Ty<'tcx>

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

Source

pub fn instance_args(&self, instance: Instance<'tcx>) -> GenericArgsRef<'tcx>

Get the instantiation types.

Source

pub fn instance_abi( &self, instance: Instance<'tcx>, ) -> Result<&FnAbi<'tcx, Ty<'tcx>>, B::Error>

Get an instance ABI.

Source

pub fn fn_ptr_abi( &self, sig: PolyFnSig<'tcx>, ) -> Result<&FnAbi<'tcx, Ty<'tcx>>, B::Error>

Get the ABI of a function pointer.

Source

pub fn instance_def_id( &self, instances: Instance<'tcx>, tables: &mut Tables<'_, B>, ) -> B::DefId

Get the instance.

Source

pub fn instance_mangled_name(&self, instance: Instance<'tcx>) -> String

Get the instance mangled name.

Source

pub fn is_empty_drop_shim(&self, instance: Instance<'tcx>) -> bool

Check if this is an empty DropGlue shim.

Source

pub fn mono_instance(&self, def_id: DefId) -> Instance<'tcx>

Convert a non-generic crate item into an instance. This function will panic if the item is generic.

Source

pub fn requires_monomorphization(&self, def_id: DefId) -> bool

Item requires monomorphization.

Source

pub fn resolve_instance( &self, def_id: DefId, args_ref: GenericArgsRef<'tcx>, ) -> Option<Instance<'tcx>>

Resolve an instance from the given function definition and generic arguments.

Source

pub fn resolve_drop_in_place(&self, internal_ty: Ty<'tcx>) -> Instance<'tcx>

Resolve an instance for drop_in_place for the given type.

Source

pub fn resolve_for_fn_ptr( &self, def_id: DefId, args_ref: GenericArgsRef<'tcx>, ) -> Option<Instance<'tcx>>

Resolve instance for a function pointer.

Source

pub fn resolve_closure( &self, def_id: DefId, args_ref: GenericArgsRef<'tcx>, closure_kind: ClosureKind, ) -> Option<Instance<'tcx>>

Resolve instance for a closure with the requested type.

Source

pub fn eval_instance( &self, instance: Instance<'tcx>, ) -> Result<ConstValue<'tcx>, ErrorHandled>

Try to evaluate an instance into a constant.

Source

pub fn eval_static_initializer( &self, def_id: DefId, ) -> Result<ConstAllocation<'tcx>, ErrorHandled>

Evaluate a static’s initializer.

Source

pub fn global_alloc(&self, alloc_id: AllocId) -> GlobalAlloc<'tcx>

Retrieve global allocation for the given allocation ID.

Source

pub fn vtable_allocation( &self, ty: Ty<'tcx>, trait_ref: Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>, ) -> AllocId

Retrieve the id for the virtual table.

Source

pub fn instance_name(&self, instance: Instance<'tcx>, trimmed: bool) -> String

Retrieve the instance name for diagnostic messages.

This will return the specialized name, e.g., Vec<char>::new.

Source

pub fn ty_layout(&self, ty: Ty<'tcx>) -> Result<Layout<'tcx>, B::Error>

Get the layout of a type.

Source

pub fn binop_ty(&self, bin_op: BinOp, rhs: Ty<'tcx>, lhs: Ty<'tcx>) -> Ty<'tcx>

Get the resulting type of binary operation.

Source

pub fn unop_ty(&self, un_op: UnOp, arg: Ty<'tcx>) -> Ty<'tcx>

Get the resulting type of unary operation.

Source

pub fn associated_items(&self, def_id: DefId) -> Vec<AssocItem>

Get all associated items of a definition.

Source§

impl<'tcx, B: Bridge> SmirCtxt<'tcx, B>

Source

pub fn new(tcx: TyCtxt<'tcx>) -> Self

Trait Implementations§

Source§

impl<'tcx, B: Bridge> FnAbiOfHelpers<'tcx> for SmirCtxt<'tcx, B>

Implement error handling for extracting function ABI information.

Source§

type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, <B as Bridge>::Error>

The &FnAbi-wrapping type (or &FnAbi itself), which will be returned from fn_abi_of_* (see also handle_fn_abi_err).
Source§

fn handle_fn_abi_err( &self, err: FnAbiError<'tcx>, _span: Span, fn_abi_request: FnAbiRequest<'tcx>, ) -> B::Error

Helper used for fn_abi_of_*, to adapt tcx.fn_abi_of_*(...) into a Self::FnAbiOfResult (which does not need to be a Result<...>). Read more
Source§

impl<'tcx, B: Bridge> HasDataLayout for SmirCtxt<'tcx, B>

Source§

impl<'tcx, B: Bridge> HasTyCtxt<'tcx> for SmirCtxt<'tcx, B>

Source§

fn tcx(&self) -> TyCtxt<'tcx>

Source§

impl<'tcx, B: Bridge> HasTypingEnv<'tcx> for SmirCtxt<'tcx, B>

Source§

fn typing_env(&self) -> TypingEnv<'tcx>

Source§

fn param_env(&self) -> ParamEnv<'tcx>

FIXME(#132279): This method should not be used as in the future everything should take a TypingEnv instead. Remove it as that point.
Source§

impl<'tcx, B: Bridge> LayoutOfHelpers<'tcx> for SmirCtxt<'tcx, B>

Source§

type LayoutOfResult = Result<TyAndLayout<'tcx, Ty<'tcx>>, <B as Bridge>::Error>

The TyAndLayout-wrapping type (or TyAndLayout itself), which will be returned from layout_of (see also handle_layout_err).
Source§

fn handle_layout_err( &self, err: LayoutError<'tcx>, _span: Span, ty: Ty<'tcx>, ) -> B::Error

Helper used for layout_of, to adapt tcx.layout_of(...) into a Self::LayoutOfResult (which does not need to be a Result<...>). Read more
Source§

fn layout_tcx_at_span(&self) -> Span

Span to use for tcx.at(span), from layout_of.
Source§

impl<'tcx, B: Bridge> SmirAllocRange<'tcx> for SmirCtxt<'tcx, B>

Source§

fn alloc_range(&self, offset: Size, size: Size) -> AllocRange

Source§

impl<'tcx, B: Bridge> SmirTy<'tcx> for SmirCtxt<'tcx, B>

Source§

fn new_foreign(&self, def_id: DefId) -> Ty<'tcx>

Source§

impl<'tcx, B: Bridge> SmirTypingEnv<'tcx> for SmirCtxt<'tcx, B>

Auto Trait Implementations§

§

impl<'tcx, B> DynSend for SmirCtxt<'tcx, B>
where B: DynSend,

§

impl<'tcx, B> DynSync for SmirCtxt<'tcx, B>
where B: DynSync,

§

impl<'tcx, B> Freeze for SmirCtxt<'tcx, B>

§

impl<'tcx, B> !RefUnwindSafe for SmirCtxt<'tcx, B>

§

impl<'tcx, B> !Send for SmirCtxt<'tcx, B>

§

impl<'tcx, B> !Sync for SmirCtxt<'tcx, B>

§

impl<'tcx, B> Unpin for SmirCtxt<'tcx, B>
where B: Unpin,

§

impl<'tcx, B> !UnwindSafe for SmirCtxt<'tcx, B>

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment

Alignment of Self.
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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<'tcx, C> FnAbiOf<'tcx> for C
where C: FnAbiOfHelpers<'tcx>,

Source§

fn fn_abi_of_fn_ptr( &self, sig: Binder<TyCtxt<'tcx>, FnSig<TyCtxt<'tcx>>>, extra_args: &'tcx RawList<(), Ty<'tcx>>, ) -> Self::FnAbiOfResult

Compute a FnAbi suitable for indirect calls, i.e. to fn pointers. Read more
Source§

fn fn_abi_of_instance( &self, instance: Instance<'tcx>, extra_args: &'tcx RawList<(), Ty<'tcx>>, ) -> Self::FnAbiOfResult

Compute a FnAbi suitable for declaring/defining an fn instance, and for direct calls to an fn. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<P> IntoQueryParam<P> for P

Source§

impl<'tcx, C> LayoutOf<'tcx> for C
where C: LayoutOfHelpers<'tcx>,

Source§

fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult

Computes the layout of a type. Note that this implicitly executes in TypingMode::PostAnalysis, and will normalize the input type.
Source§

fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::LayoutOfResult

Computes the layout of a type, at span. Note that this implicitly executes in TypingMode::PostAnalysis, and will normalize the input type.
Source§

impl<T> MaybeResult<T> for T

Source§

type Error = !

Source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

Source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PointerArithmetic for T
where T: HasDataLayout,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

Source§

fn upcast(self, interner: I) -> U

Source§

impl<I, T> UpcastFrom<I, T> for T

Source§

fn upcast_from(from: T, _tcx: I) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

Source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where 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: 8 bytes