Struct ItemTransCtx

Source
pub(crate) struct ItemTransCtx<'tcx, 'ctx> {
    pub def_id: DefId,
    pub item_id: Option<AnyTransId>,
    pub t_ctx: &'ctx mut TranslateCtx<'tcx>,
    pub error_on_impl_expr_error: bool,
    pub binding_levels: BindingStack<BindingLevel>,
    pub parent_trait_clauses: Vector<TraitClauseId, TraitClause>,
    pub item_trait_clauses: HashMap<TraitItemName, Vector<TraitClauseId, TraitClause>>,
}
Expand description

A translation context for items. Augments the TranslateCtx with type-level variables.

Fields§

§def_id: DefId

The definition we are currently extracting. TODO: this duplicates the field of ErrorCtx

§item_id: Option<AnyTransId>

The id of the definition we are currently extracting, if there is one.

§t_ctx: &'ctx mut TranslateCtx<'tcx>

The translation context containing the top-level definitions/ids.

§error_on_impl_expr_error: bool

Whether to consider a ImplExprAtom::Error as an error for us. True except inside type aliases, because rust does not enforce correct trait bounds on type aliases.

§binding_levels: BindingStack<BindingLevel>

The stack of generic parameter binders for the current context. Each binder introduces an entry in this stack, with the entry as index 0 being the innermost binder. These parameters are referenced using DeBruijnVar; see there for details.

§parent_trait_clauses: Vector<TraitClauseId, TraitClause>

(For traits only) accumulated implied trait clauses.

§item_trait_clauses: HashMap<TraitItemName, Vector<TraitClauseId, TraitClause>>

(For traits only) accumulated trait clauses on associated types.

Implementations§

Source§

impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>

Source

fn translate_constant_literal_to_raw_constant_expr( &mut self, span: Span, v: &ConstantLiteral, ) -> Result<RawConstantExpr, Error>

Source

pub(crate) fn translate_constant_expr_to_constant_expr( &mut self, span: Span, v: &ConstantExpr, ) -> Result<ConstantExpr, Error>

Remark: [hax::ConstantExpr] contains span information, but it is often the default span (i.e., it is useless), hence the additional span argument. TODO: the user_ty might be None because hax doesn’t extract it (because we are translating a ConstantExpr instead of a [Constant]. We need to update hax.

Source

pub(crate) fn translate_constant_expr_to_const_generic( &mut self, span: Span, v: &ConstantExpr, ) -> Result<ConstGeneric, Error>

Remark: [hax::ConstantExpr] contains span information, but it is often the default span (i.e., it is useless), hence the additional span argument.

Source§

impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>

Source

pub(crate) fn new( def_id: DefId, item_id: Option<AnyTransId>, t_ctx: &'ctx mut TranslateCtx<'tcx>, ) -> Self

Create a new ExecContext.

Source

pub fn span_err(&self, span: Span, msg: &str, level: Level<'_>) -> Error

Source

pub(crate) fn translate_span_from_hax(&mut self, rspan: &Span) -> Span

Source

pub(crate) fn hax_def(&mut self, def_id: &DefId) -> Result<Arc<FullDef>, Error>

Source

pub(crate) fn def_span(&mut self, def_id: &DefId) -> Span

Source

pub(crate) fn register_id_no_enqueue( &mut self, span: Span, id: TransItemSource, ) -> AnyTransId

Source

pub(crate) fn register_type_decl_id( &mut self, span: Span, id: &DefId, ) -> TypeDeclId

Source

pub(crate) fn register_fun_decl_id( &mut self, span: Span, id: &DefId, ) -> FunDeclId

Source

pub(crate) fn register_fun_decl_id_no_enqueue( &mut self, span: Span, id: &DefId, ) -> FunDeclId

Source

pub(crate) fn register_global_decl_id( &mut self, span: Span, id: &DefId, ) -> GlobalDeclId

Source

pub(crate) fn register_trait_decl_id( &mut self, span: Span, id: &DefId, ) -> TraitDeclId

Returns an Option because we may ignore some builtin or auto traits like core::marker::Sized or core::marker::Sync.

Source

pub(crate) fn register_trait_impl_id( &mut self, span: Span, id: &DefId, ) -> TraitImplId

Returns an Option because we may ignore some builtin or auto traits like core::marker::Sized or core::marker::Sync.

Source

pub(crate) fn the_only_binder(&self) -> &BindingLevel

Get the only binding level. Panics if there are other binding levels.

Source

pub(crate) fn outermost_binder(&self) -> &BindingLevel

Source

pub(crate) fn innermost_binder(&self) -> &BindingLevel

Source

pub(crate) fn innermost_binder_mut(&mut self) -> &mut BindingLevel

Source

pub(crate) fn innermost_generics_mut(&mut self) -> &mut GenericParams

Source

pub(crate) fn lookup_bound_region( &mut self, span: Span, dbid: DebruijnIndex, var: BoundVar, ) -> Result<RegionDbVar, Error>

Source

fn lookup_param<Id: Copy>( &mut self, span: Span, f: impl for<'a> Fn(&'a BindingLevel) -> Option<Id>, mk_err: impl FnOnce() -> String, ) -> Result<DeBruijnVar<Id>, Error>

Source

pub(crate) fn lookup_early_region( &mut self, span: Span, region: &EarlyParamRegion, ) -> Result<RegionDbVar, Error>

Source

pub(crate) fn lookup_type_var( &mut self, span: Span, param: &ParamTy, ) -> Result<TypeDbVar, Error>

Source

pub(crate) fn lookup_const_generic_var( &mut self, span: Span, param: &ParamConst, ) -> Result<ConstGenericDbVar, Error>

Source

pub(crate) fn lookup_clause_var( &mut self, span: Span, id: usize, ) -> Result<ClauseDbVar, Error>

Source

pub(crate) fn lookup_cached_type( &self, cache_key: &HashByAddr<Arc<TyKind>>, ) -> Option<Ty>

Source

pub(crate) fn translate_region_binder<F, T, U>( &mut self, _span: Span, binder: &Binder<T>, f: F, ) -> Result<RegionBinder<U>, Error>
where F: FnOnce(&mut Self, &T) -> Result<U, Error>,

Push a group of bound regions and call the continuation. We use this when diving into a for<'a>, or inside an arrow type (because it contains universally quantified regions).

Source

pub(crate) fn translate_binder_for_def<F, U>( &mut self, span: Span, kind: BinderKind, def: &FullDef, f: F, ) -> Result<Binder<U>, Error>
where F: FnOnce(&mut Self) -> Result<U, Error>,

Push a new binding level corresponding to the provided def for the duration of the inner function call.

Source

pub(crate) fn make_dep_source(&self, span: Span) -> Option<DepSource>

Source§

impl ItemTransCtx<'_, '_>

Source

pub(crate) fn get_item_kind( &mut self, span: Span, def: &FullDef, ) -> Result<ItemKind, Error>

Source

fn translate_function_signature( &mut self, def: &FullDef, item_meta: &ItemMeta, ) -> Result<FunSig, Error>

Translate a function’s signature, and initialize a body translation context at the same time - the function signature gives us the list of region and type parameters, that we put in the translation context.

Source

fn build_ctor_body( &mut self, span: Span, signature: &FunSig, adt_def_id: &DefId, ctor_of: &CtorOf, variant_id: usize, fields: &IndexVec<FieldIdx, FieldDef>, output_ty: &Ty, ) -> Result<Body, Error>

Generate a fake function body for ADT constructors.

Source

pub(crate) fn translate_fn_ptr( &mut self, span: Span, def_id: &DefId, substs: &Vec<GenericArg>, trait_refs: &Vec<ImplExpr>, trait_info: &Option<ImplExpr>, ) -> Result<FnPtr, Error>

Auxiliary function to translate function calls and references to functions. Translate a function id applied with some substitutions.

TODO: should we always erase the regions?

Source

pub fn translate_function( self, def_id: FunDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<FunDecl, Error>

Translate one function.

Source

pub fn translate_global( self, def_id: GlobalDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<GlobalDecl, Error>

Translate one global.

Source§

impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>

Source

pub(crate) fn register_predicates( &mut self, preds: &GenericPredicates, origin: PredicateOrigin, location: &PredicateLocation, ) -> Result<(), Error>

This function should be called after we translated the generics (type parameters, regions…).

Source

pub(crate) fn translate_poly_trait_ref( &mut self, span: Span, bound_trait_ref: &Binder<TraitRef>, ) -> Result<PolyTraitDeclRef, Error>

Source

pub(crate) fn translate_trait_predicate( &mut self, span: Span, trait_pred: &TraitPredicate, ) -> Result<TraitDeclRef, Error>

Source

pub(crate) fn translate_trait_ref( &mut self, span: Span, trait_ref: &TraitRef, ) -> Result<TraitDeclRef, Error>

Source

pub(crate) fn register_predicate( &mut self, clause: &Clause, hspan: &Span, origin: PredicateOrigin, location: &PredicateLocation, ) -> Result<(), Error>

Source

pub(crate) fn translate_trait_impl_exprs( &mut self, span: Span, impl_sources: &[ImplExpr], ) -> Result<Vector<TraitClauseId, TraitRef>, Error>

Source

pub(crate) fn translate_trait_impl_expr( &mut self, span: Span, impl_expr: &ImplExpr, ) -> Result<TraitRef, Error>

Source

pub(crate) fn translate_trait_impl_expr_aux( &mut self, span: Span, impl_source: &ImplExpr, trait_decl_ref: PolyTraitDeclRef, ) -> Result<TraitRef, Error>

Source§

impl ItemTransCtx<'_, '_>

Source

pub fn translate_trait_decl( self, def_id: TraitDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitDecl, Error>

Source

pub fn translate_trait_impl( self, def_id: TraitImplId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitImpl, Error>

Source§

impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>

Source

pub(crate) fn translate_region( &mut self, span: Span, region: &Region, ) -> Result<Region, Error>

Source

pub(crate) fn translate_ty(&mut self, span: Span, ty: &Ty) -> Result<Ty, Error>

Translate a Ty.

Typically used in this module to translate the fields of a structure/ enumeration definition, or later to translate the type of a variable.

Note that we take as parameter a function to translate regions, because regions can be translated in several manners (non-erased region or erased regions), in which case the return type is different.

Source

pub fn translate_generic_args( &mut self, span: Span, substs: &[GenericArg], trait_refs: &[ImplExpr], late_bound: Option<Binder<()>>, target: GenericsSource, ) -> Result<GenericArgs, Error>

Source

fn recognize_builtin_type( &mut self, def_id: &DefId, ) -> Result<Option<BuiltinTy>, Error>

Checks whether the given id corresponds to a built-in type.

Source

pub(crate) fn translate_type_id( &mut self, span: Span, def_id: &DefId, ) -> Result<TypeId, Error>

Translate a type def id

Source

fn translate_adt_def( &mut self, trans_id: TypeDeclId, def_span: Span, item_meta: &ItemMeta, adt: &AdtDef, ) -> Result<TypeDeclKind, Error>

Translate the body of a type declaration.

Note that the type may be external, in which case we translate the body only if it is public (i.e., it is a public enumeration, or it is a struct with only public fields).

Source

fn translate_discriminant( &mut self, def_span: Span, discr: &DiscriminantValue, ) -> Result<ScalarValue, Error>

Source

pub(crate) fn translate_def_generics( &mut self, span: Span, def: &FullDef, ) -> Result<(), Error>

Translate the generics and predicates of this item and its parents.

Source

pub(crate) fn translate_def_generics_without_parents( &mut self, span: Span, def: &FullDef, ) -> Result<(), Error>

Translate the generics and predicates of this item without its parents.

Source

pub(crate) fn into_generics(self) -> GenericParams

Source

fn push_generics_for_def( &mut self, span: Span, def: &FullDef, is_parent: bool, ) -> Result<(), Error>

Add the generics and predicates of this item and its parents to the current context.

Source

fn push_generics_for_def_without_parents( &mut self, span: Span, def: &FullDef, include_late_bound: bool, include_assoc_ty_clauses: bool, ) -> Result<(), Error>

Add the generics and predicates of this item. This does not include the parent generics; use push_generics_for_def to get the full list.

Source

pub(crate) fn push_generic_params( &mut self, generics: &TyGenerics, ) -> Result<(), Error>

Source

pub(crate) fn push_generic_param( &mut self, param: &GenericParamDef, ) -> Result<(), Error>

Source§

impl ItemTransCtx<'_, '_>

Source

pub fn translate_type( self, trans_id: TypeDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TypeDecl, Error>

Translate a type definition.

Note that we translate the types one by one: we don’t need to take into account the fact that some types are mutually recursive at this point (we will need to take that into account when generating the code in a file).

Trait Implementations§

Source§

impl<'a> IntoFormatter for &'a ItemTransCtx<'_, '_>

Source§

type C = FmtCtx<'a>

Source§

fn into_fmt(self) -> Self::C

Auto Trait Implementations§

§

impl<'tcx, 'ctx> Freeze for ItemTransCtx<'tcx, 'ctx>

§

impl<'tcx, 'ctx> !RefUnwindSafe for ItemTransCtx<'tcx, 'ctx>

§

impl<'tcx, 'ctx> !Send for ItemTransCtx<'tcx, 'ctx>

§

impl<'tcx, 'ctx> !Sync for ItemTransCtx<'tcx, 'ctx>

§

impl<'tcx, 'ctx> Unpin for ItemTransCtx<'tcx, 'ctx>

§

impl<'tcx, 'ctx> !UnwindSafe for ItemTransCtx<'tcx, 'ctx>

Blanket Implementations§

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
§

impl<I, T> ExtractContext<I, ()> for T

§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<I> RecreateContext<I> for I

§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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