Skip to main content

## CompilerInterface

# Struct CompilerInterface

Source

    pub(crate) struct CompilerInterface<'tcx> {
        pub tables: RefCell<Tables<'tcx, BridgeTys>>,
        pub cx: RefCell<CompilerCtxt<'tcx, BridgeTys>>,
    }

Expand description

Public API for querying compiler information.

All queries are delegated to [`rustc_public_bridge::context::CompilerCtxt`] that provides similar APIs but based on internal rustc constructs.

Do not use this directly. This is currently used in the macro expansion.

## Fields§

§`tables: RefCell<Tables<'tcx, BridgeTys>>`§`cx: RefCell<CompilerCtxt<'tcx, BridgeTys>>`

## Implementations§

Source§

### impl<'tcx> CompilerInterface<'tcx>

Source

#### fn with_cx<R>( &self, f: impl FnOnce(&mut Tables<'tcx, BridgeTys>, &CompilerCtxt<'tcx, BridgeTys>) -> R, ) -> R

Source

#### pub(crate) fn entry_fn(&self) -> Option<CrateItem>

Source

#### pub(crate) fn all_local_items(&self) -> CrateItems

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

Source

#### pub(crate) fn mir_body(&self, item: DefId) -> Body

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

Source

#### pub(crate) fn has_body(&self, item: DefId) -> bool

Check whether the body of a function is available.

Source

#### pub(crate) fn foreign_modules( &self, crate_num: CrateNum, ) -> Vec<ForeignModuleDef>

Source

#### pub(crate) fn crate_functions(&self, crate_num: CrateNum) -> Vec<FnDef>

Retrieve all functions defined in this crate.

Source

#### pub(crate) fn crate_adts(&self, crate_num: CrateNum) -> Vec<AdtDef>

Source

#### pub(crate) fn crate_statics(&self, crate_num: CrateNum) -> Vec<StaticDef>

Retrieve all static items defined in this crate.

Source

#### pub(crate) fn foreign_module(&self, mod_def: ForeignModuleDef) -> ForeignModule

Source

#### pub(crate) fn foreign_items(&self, mod_def: ForeignModuleDef) -> Vec<ForeignDef>

Source

#### pub(crate) fn all_trait_decls(&self) -> TraitDecls

Source

#### pub(crate) fn trait_decls(&self, crate_num: CrateNum) -> TraitDecls

Source

#### pub(crate) fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl

Source

#### pub(crate) fn all_trait_impls(&self) -> ImplTraitDecls

Source

#### pub(crate) fn trait_impls(&self, crate_num: CrateNum) -> ImplTraitDecls

Source

#### pub(crate) fn trait_impl(&self, trait_impl: &ImplDef) -> ImplTrait

Source

#### pub(crate) fn generics_of(&self, def_id: DefId) -> Generics

Source

#### pub(crate) fn predicates_of(&self, def_id: DefId) -> GenericPredicates

Source

#### pub(crate) fn explicit_predicates_of(&self, def_id: DefId) -> GenericPredicates

Source

#### pub(crate) fn local_crate(&self) -> Crate

Get information about the local crate.

Source

#### pub(crate) fn external_crates(&self) -> Vec<Crate>

Retrieve a list of all external crates.

Source

#### pub(crate) fn find_crates(&self, name: &str) -> Vec<Crate>

Find a crate with the given name.

Source

#### pub(crate) fn def_name(&self, def_id: DefId, trimmed: bool) -> Symbol

Returns the name of given `DefId`.

Source

#### pub(crate) fn def_parent(&self, def_id: DefId) -> Option<DefId>

Returns the parent of the given `DefId`.

Source

#### pub(crate) 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()]`.

Source

#### pub(crate) fn all_tool_attrs(&self, def_id: DefId) -> Vec<Attribute>

Get all tool attributes of a definition.

Source

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

Returns printable, human readable form of `Span`.

Source

#### pub(crate) fn get_filename(&self, span: &Span) -> Filename

Return filename from given `Span`, for diagnostic purposes.

Source

#### pub(crate) fn get_lines(&self, span: &Span) -> LineInfo

Return lines corresponding to this `Span`.

Source

#### pub(crate) fn item_kind(&self, item: CrateItem) -> ItemKind

Returns the `kind` of given `DefId`.

Source

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

Returns whether this is a foreign item.

Source

#### pub(crate) fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind

Returns the kind of a given foreign item.

Source

#### pub(crate) fn adt_kind(&self, def: AdtDef) -> AdtKind

Returns the kind of a given algebraic data type.

Source

#### pub(crate) fn adt_is_box(&self, def: AdtDef) -> bool

Returns if the ADT is a box.

Source

#### pub(crate) fn adt_is_simd(&self, def: AdtDef) -> bool

Returns whether this ADT is simd.

Source

#### pub(crate) fn adt_is_cstr(&self, def: AdtDef) -> bool

Returns whether this definition is a C string.

Source

#### pub(crate) fn adt_repr(&self, def: AdtDef) -> ReprOptions

Returns the representation options for this ADT

Source

#### pub(crate) fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig

Retrieve the function signature for the given generic arguments.

Source

#### pub(crate) fn constness(&self, def: FnDef) -> Constness

Retrieve the constness for the given function definition.

Source

#### pub(crate) fn asyncness(&self, def: FnDef) -> Asyncness

Retrieve the asyncness for the given function definition.

Source

#### pub(crate) fn intrinsic(&self, item: DefId) -> Option<IntrinsicDef>

Retrieve the intrinsic definition if the item corresponds one.

Source

#### pub(crate) fn intrinsic_name(&self, def: IntrinsicDef) -> Symbol

Retrieve the plain function name of an intrinsic.

Source

#### pub(crate) fn closure_sig(&self, args: &GenericArgs) -> PolyFnSig

Retrieve the closure signature for the given generic arguments.

Source

#### pub(crate) fn adt_variants_len(&self, def: AdtDef) -> usize

The number of variants in this ADT.

Source

#### pub(crate) fn adt_discr_for_variant( &self, adt: AdtDef, variant: VariantIdx, ) -> Discr

Discriminant for a given variant index of AdtDef.

Source

#### pub(crate) fn coroutine_discr_for_variant( &self, coroutine: CoroutineDef, args: &GenericArgs, variant: VariantIdx, ) -> Discr

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

Source

#### pub(crate) fn variant_name(&self, def: VariantDef) -> Symbol

The name of a variant.

Source

#### pub(crate) fn variant_fields(&self, def: VariantDef) -> Vec<FieldDef>

Source

#### pub(crate) fn eval_target_usize( &self, mir_const: &MirConst, ) -> Result<u64, Error>

Evaluate constant as a target usize.

Source

#### pub(crate) fn eval_target_usize_ty( &self, ty_const: &TyConst, ) -> Result<u64, Error>

Source

#### pub(crate) fn try_new_const_zst(&self, ty: Ty) -> Result<MirConst, Error>

Create a new zero-sized constant.

Source

#### pub(crate) fn new_const_str(&self, value: &str) -> MirConst

Create a new constant that represents the given string value.

Source

#### pub(crate) fn new_const_bool(&self, value: bool) -> MirConst

Create a new constant that represents the given boolean value.

Source

#### pub(crate) fn try_new_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<MirConst, Error>

Create a new constant that represents the given value.

Source

#### pub(crate) fn try_new_ty_const_uint( &self, value: u128, uint_ty: UintTy, ) -> Result<TyConst, Error>

Source

#### pub(crate) fn new_rigid_ty(&self, kind: RigidTy) -> Ty

Create a new type from the given kind.

Source

#### pub(crate) fn new_box_ty(&self, ty: Ty) -> Ty

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

Source

#### pub(crate) fn def_ty(&self, item: DefId) -> Ty

Returns the type of given crate item.

Source

#### pub(crate) fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty

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

Source

#### pub(crate) fn mir_const_pretty(&self, cnst: &MirConst) -> String

Returns literal value of a const as a string.

Source

#### pub(crate) fn span_of_a_def(&self, def_id: DefId) -> Span

`Span` of a `DefId`.

Source

#### pub(crate) fn ty_const_pretty(&self, ct: TyConstId) -> String

Source

#### pub(crate) fn ty_pretty(&self, ty: Ty) -> String

Obtain the representation of a type.

Source

#### pub(crate) fn ty_kind(&self, ty: Ty) -> TyKind

Obtain the kind of a type.

Source

#### pub(crate) fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty

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

Source

#### pub(crate) fn instance_body(&self, instance: InstanceDef) -> Option<Body>

Get the body of an Instance which is already monomorphized.

Source

#### pub(crate) fn instance_ty(&self, instance: InstanceDef) -> Ty

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

Source

#### pub(crate) fn instance_args(&self, def: InstanceDef) -> GenericArgs

Get the instantiation types.

Source

#### pub(crate) fn instance_def_id(&self, instance: InstanceDef) -> DefId

Get the instance.

Source

#### pub(crate) fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol

Get the instance mangled name.

Source

#### pub(crate) fn is_empty_drop_shim(&self, def: InstanceDef) -> bool

Check if this is an empty DropGlue shim.

Source

#### pub(crate) 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.

Source

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

Item requires monomorphization.

Source

#### pub(crate) fn resolve_instance( &self, def: FnDef, args: &GenericArgs, ) -> Option<Instance>

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

Source

#### pub(crate) fn resolve_drop_in_place(&self, ty: Ty) -> Instance

Resolve an instance for drop_in_place for the given type.

Source

#### pub(crate) fn resolve_for_fn_ptr( &self, def: FnDef, args: &GenericArgs, ) -> Option<Instance>

Resolve instance for a function pointer.

Source

#### pub(crate) fn resolve_closure( &self, def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Option<Instance>

Resolve instance for a closure with the requested type.

Source

#### pub(crate) fn eval_static_initializer( &self, def: StaticDef, ) -> Result<Allocation, Error>

Evaluate a static’s initializer.

Source

#### pub(crate) fn eval_instance( &self, def: InstanceDef, const_ty: Ty, ) -> Result<Allocation, Error>

Try to evaluate an instance into a constant.

Source

#### pub(crate) fn global_alloc(&self, id: AllocId) -> GlobalAlloc

Retrieve global allocation for the given allocation ID.

Source

#### pub(crate) fn vtable_allocation( &self, global_alloc: &GlobalAlloc, ) -> Option<AllocId>

Retrieve the id for the virtual table.

Source

#### pub(crate) fn krate(&self, def_id: DefId) -> Crate

Source

#### pub(crate) fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol

Source

#### pub(crate) fn target_info(&self) -> MachineInfo

Return information about the target machine.

Source

#### pub(crate) fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error>

Get an instance ABI.

Source

#### pub(crate) fn fn_ptr_abi(&self, fn_ptr: PolyFnSig) -> Result<FnAbi, Error>

Get the ABI of a function pointer.

Source

#### pub(crate) fn ty_layout(&self, ty: Ty) -> Result<Layout, Error>

Get the layout of a type.

Source

#### pub(crate) fn layout_shape(&self, id: Layout) -> LayoutShape

Get the layout shape.

Source

#### pub(crate) fn place_pretty(&self, place: &Place) -> String

Get a debug string representation of a place.

Source

#### pub(crate) fn binop_ty(&self, bin_op: BinOp, rhs: Ty, lhs: Ty) -> Ty

Get the resulting type of binary operation.

Source

#### pub(crate) fn unop_ty(&self, un_op: UnOp, arg: Ty) -> Ty

Get the resulting type of unary operation.

Source

#### pub(crate) fn associated_items(&self, def_id: DefId) -> AssocItems

Get all associated items of a definition.

Source

#### pub(crate) fn vtable_entries(&self, trait_ref: &TraitRef) -> Vec<VtblEntry>

Get all vtable entries of a trait.

Source

#### pub(crate) fn vtable_entry( &self, trait_ref: &TraitRef, idx: usize, ) -> Option<VtblEntry>

Returns the vtable entry at the given index.

Returns `None` if the index is out of bounds.

## Auto Trait Implementations§

§

### impl<'tcx> !DynSend for CompilerInterface<'tcx>

§

### impl<'tcx> !DynSync for CompilerInterface<'tcx>

§

### impl<'tcx> !Freeze for CompilerInterface<'tcx>

§

### impl<'tcx> !RefUnwindSafe for CompilerInterface<'tcx>

§

### impl<'tcx> !Send for CompilerInterface<'tcx>

§

### impl<'tcx> !Sync for CompilerInterface<'tcx>

§

### impl<'tcx> !UnwindSafe for CompilerInterface<'tcx>

§

### impl<'tcx> Unpin for CompilerInterface<'tcx>

§

### impl<'tcx> UnsafeUnpin for CompilerInterface<'tcx>

## 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> ErasedDestructor for T
where T: 'static,

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<K> IntoQueryKey<K> for K

Source§

#### fn into_query_key(self) -> K

Argument conversion from `Self` to `K`. This should always be a very cheap conversion, e.g. `LocalDefId::to_def_id`.
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> 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<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

## 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: 472 bytes