pub(crate) struct ItemTransCtx<'tcx, 'ctx> {
pub item_src: TransItemSource,
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§
§item_src: TransItemSource
The definition we are currently extracting.
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 ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
pub fn translate_closure_info( &mut self, span: Span, args: &ClosureArgs, ) -> Result<ClosureInfo, Error>
Sourcepub fn translate_closure_bound_type_ref(
&mut self,
span: Span,
closure: &ClosureArgs,
) -> Result<RegionBinder<TypeDeclRef>, Error>
pub fn translate_closure_bound_type_ref( &mut self, span: Span, closure: &ClosureArgs, ) -> Result<RegionBinder<TypeDeclRef>, Error>
Translate a reference to the closure ADT. The resulting type needs lifetime arguments for
the upvars (captured variables). If you don’t know what to do about the bound lifetimes,
use translate_closure_type_ref
instead.
Sourcepub fn translate_closure_type_ref(
&mut self,
span: Span,
closure: &ClosureArgs,
) -> Result<TypeDeclRef, Error>
pub fn translate_closure_type_ref( &mut self, span: Span, closure: &ClosureArgs, ) -> Result<TypeDeclRef, Error>
Translate a reference to the closure ADT.
Sourcepub fn translate_stateless_closure_as_fn_ref(
&mut self,
span: Span,
closure: &ClosureArgs,
) -> Result<RegionBinder<FunDeclRef>, Error>
pub fn translate_stateless_closure_as_fn_ref( &mut self, span: Span, closure: &ClosureArgs, ) -> Result<RegionBinder<FunDeclRef>, Error>
For stateless closures, translate a function reference to the top-level function that executes the closure code without taking the state as parameter.
Sourcepub fn translate_closure_bound_impl_ref(
&mut self,
span: Span,
closure: &ClosureArgs,
target_kind: ClosureKind,
) -> Result<RegionBinder<TraitImplRef>, Error>
pub fn translate_closure_bound_impl_ref( &mut self, span: Span, closure: &ClosureArgs, target_kind: ClosureKind, ) -> Result<RegionBinder<TraitImplRef>, Error>
Translate a reference to the chosen closure impl. The resulting value needs lifetime
arguments for late-bound lifetimes. If you don’t know what to do about the bound lifetimes,
use translate_closure_impl_ref
instead.
Sourcepub fn translate_closure_impl_ref(
&mut self,
span: Span,
closure: &ClosureArgs,
target_kind: ClosureKind,
) -> Result<TraitImplRef, Error>
pub fn translate_closure_impl_ref( &mut self, span: Span, closure: &ClosureArgs, target_kind: ClosureKind, ) -> Result<TraitImplRef, Error>
Translate a reference to the chosen closure impl.
pub fn get_closure_state_ty( &mut self, span: Span, args: &ClosureArgs, ) -> Result<Ty, Error>
pub fn translate_closure_adt( &mut self, _trans_id: TypeDeclId, span: Span, args: &ClosureArgs, ) -> Result<TypeDeclKind, Error>
Sourcefn translate_closure_method_sig(
&mut self,
def: &FullDef,
span: Span,
args: &ClosureArgs,
target_kind: ClosureKind,
) -> Result<FunSig, Error>
fn translate_closure_method_sig( &mut self, def: &FullDef, span: Span, args: &ClosureArgs, target_kind: ClosureKind, ) -> Result<FunSig, Error>
Given an item that is a closure, generate the signature of the
call_once
/call_mut
/call
method (depending on target_kind
).
fn translate_closure_method_body( self, span: Span, def: &FullDef, target_kind: ClosureKind, args: &ClosureArgs, signature: &FunSig, ) -> Result<Result<Body, Opaque>, Error>
Sourcepub fn translate_closure_method(
self,
def_id: FunDeclId,
item_meta: ItemMeta,
def: &FullDef,
target_kind: ClosureKind,
) -> Result<FunDecl, Error>
pub fn translate_closure_method( self, def_id: FunDeclId, item_meta: ItemMeta, def: &FullDef, target_kind: ClosureKind, ) -> Result<FunDecl, Error>
Given an item that is a closure, generate the call_once
/call_mut
/call
method
(depending on target_kind
).
pub fn translate_closure_trait_impl( self, def_id: TraitImplId, item_meta: ItemMeta, def: &FullDef, target_kind: ClosureKind, ) -> Result<TraitImpl, Error>
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
fn translate_constant_literal_to_raw_constant_expr( &mut self, span: Span, v: &ConstantLiteral, ) -> Result<RawConstantExpr, Error>
Sourcepub(crate) fn translate_constant_expr_to_constant_expr(
&mut self,
span: Span,
v: &ConstantExpr,
) -> Result<ConstantExpr, Error>
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.
Sourcepub(crate) fn translate_constant_expr_to_const_generic(
&mut self,
span: Span,
v: &ConstantExpr,
) -> Result<ConstGeneric, Error>
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>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
pub(crate) fn make_dep_source(&self, span: Span) -> Option<DepSource>
Sourcepub(crate) fn register_and_enqueue<T: TryFrom<AnyTransId>>(
&mut self,
span: Span,
item_src: TransItemSource,
) -> T
pub(crate) fn register_and_enqueue<T: TryFrom<AnyTransId>>( &mut self, span: Span, item_src: TransItemSource, ) -> T
Register this item source and enqueue it for translation.
pub(crate) fn register_no_enqueue<T: TryFrom<AnyTransId>>( &mut self, span: Span, src: &TransItemSource, ) -> T
Sourcepub(crate) fn register_item_maybe_enqueue<T: TryFrom<AnyTransId>>(
&mut self,
span: Span,
enqueue: bool,
item: &ItemRef,
kind: TransItemSourceKind,
) -> T
pub(crate) fn register_item_maybe_enqueue<T: TryFrom<AnyTransId>>( &mut self, span: Span, enqueue: bool, item: &ItemRef, kind: TransItemSourceKind, ) -> T
Register this item and maybe enqueue it for translation.
Sourcepub(crate) fn register_item<T: TryFrom<AnyTransId>>(
&mut self,
span: Span,
item: &ItemRef,
kind: TransItemSourceKind,
) -> T
pub(crate) fn register_item<T: TryFrom<AnyTransId>>( &mut self, span: Span, item: &ItemRef, kind: TransItemSourceKind, ) -> T
Register this item and enqueue it for translation.
Sourcepub(crate) fn register_item_no_enqueue<T: TryFrom<AnyTransId>>(
&mut self,
span: Span,
item: &ItemRef,
kind: TransItemSourceKind,
) -> T
pub(crate) fn register_item_no_enqueue<T: TryFrom<AnyTransId>>( &mut self, span: Span, item: &ItemRef, kind: TransItemSourceKind, ) -> T
Register this item without enqueueing it for translation.
Sourcepub(crate) fn translate_item_maybe_enqueue<T: TryFrom<ItemRef<AnyTransId>>>(
&mut self,
span: Span,
enqueue: bool,
item: &ItemRef,
kind: TransItemSourceKind,
) -> Result<T, Error>
pub(crate) fn translate_item_maybe_enqueue<T: TryFrom<ItemRef<AnyTransId>>>( &mut self, span: Span, enqueue: bool, item: &ItemRef, kind: TransItemSourceKind, ) -> Result<T, Error>
Register this item and maybe enqueue it for translation.
Sourcepub(crate) fn translate_item<T: TryFrom<ItemRef<AnyTransId>>>(
&mut self,
span: Span,
item: &ItemRef,
kind: TransItemSourceKind,
) -> Result<T, Error>
pub(crate) fn translate_item<T: TryFrom<ItemRef<AnyTransId>>>( &mut self, span: Span, item: &ItemRef, kind: TransItemSourceKind, ) -> Result<T, Error>
Register this item and enqueue it for translation.
Sourcepub(crate) fn translate_item_no_enqueue<T: TryFrom<ItemRef<AnyTransId>>>(
&mut self,
span: Span,
item: &ItemRef,
kind: TransItemSourceKind,
) -> Result<T, Error>
pub(crate) fn translate_item_no_enqueue<T: TryFrom<ItemRef<AnyTransId>>>( &mut self, span: Span, item: &ItemRef, kind: TransItemSourceKind, ) -> Result<T, Error>
Register this item and don’t enqueue it for translation.
Sourcepub(crate) fn translate_type_decl_ref(
&mut self,
span: Span,
item: &ItemRef,
) -> Result<TypeDeclRef, Error>
pub(crate) fn translate_type_decl_ref( &mut self, span: Span, item: &ItemRef, ) -> Result<TypeDeclRef, Error>
Translate a type def id
Sourcepub(crate) fn translate_fun_item(
&mut self,
span: Span,
item: &ItemRef,
) -> Result<MaybeBuiltinFunDeclRef, Error>
pub(crate) fn translate_fun_item( &mut self, span: Span, item: &ItemRef, ) -> Result<MaybeBuiltinFunDeclRef, Error>
Translate a function def id
Sourcepub(crate) fn translate_fn_ptr(
&mut self,
span: Span,
item: &ItemRef,
) -> Result<RegionBinder<FnPtr>, Error>
pub(crate) fn translate_fn_ptr( &mut self, span: Span, item: &ItemRef, ) -> Result<RegionBinder<FnPtr>, Error>
Auxiliary function to translate function calls and references to functions. Translate a function id applied with some substitutions.
pub(crate) fn translate_global_decl_ref( &mut self, span: Span, item: &ItemRef, ) -> Result<GlobalDeclRef, Error>
pub(crate) fn translate_trait_decl_ref( &mut self, span: Span, item: &ItemRef, ) -> Result<TraitDeclRef, Error>
pub(crate) fn translate_trait_impl_ref( &mut self, span: Span, item: &ItemRef, kind: TraitImplSource, ) -> Result<TraitImplRef, Error>
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
Sourcepub(crate) fn new(
item_src: TransItemSource,
item_id: Option<AnyTransId>,
t_ctx: &'ctx mut TranslateCtx<'tcx>,
) -> Self
pub(crate) fn new( item_src: TransItemSource, item_id: Option<AnyTransId>, t_ctx: &'ctx mut TranslateCtx<'tcx>, ) -> Self
Create a new ExecContext
.
Sourcepub fn monomorphize(&self) -> bool
pub fn monomorphize(&self) -> bool
Whether to monomorphize items we encounter.
pub fn span_err(&self, span: Span, msg: &str, level: Level<'_>) -> Error
pub fn hax_state(&self) -> &StateWithBase<'tcx>
pub fn hax_state_with_id(&self) -> StateWithOwner<'tcx>
Sourcepub fn hax_def(&mut self, item: &ItemRef) -> Result<Arc<FullDef>, Error>
pub fn hax_def(&mut self, item: &ItemRef) -> Result<Arc<FullDef>, Error>
Return the definition for this item. This uses the polymorphic or monomorphic definition depending on user choice.
pub(crate) fn poly_hax_def( &mut self, def_id: &DefId, ) -> Result<Arc<FullDef>, Error>
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
fn translate_drop_method_body( &mut self, span: Span, def: &FullDef, ) -> Result<Result<Body, Opaque>, Error>
Sourcepub fn translate_drop_method(
self,
def_id: FunDeclId,
item_meta: ItemMeta,
def: &FullDef,
) -> Result<FunDecl, Error>
pub fn translate_drop_method( self, def_id: FunDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<FunDecl, Error>
Given an item that is a closure, generate the call_once
/call_mut
/call
method
(depending on target_kind
).
pub fn translate_drop_impl( self, impl_id: TraitImplId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitImpl, Error>
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
Sourcepub(crate) fn translate_function_signature(
&mut self,
def: &FullDef,
item_meta: &ItemMeta,
) -> Result<FunSig, Error>
pub(crate) 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.
Sourcepub(crate) fn build_ctor_body(
&mut self,
span: Span,
def: &FullDef,
adt_def_id: &DefId,
ctor_of: &CtorOf,
variant_id: usize,
fields: &IndexVec<FieldIdx, FieldDef>,
output_ty: &Ty,
) -> Result<Body, Error>
pub(crate) fn build_ctor_body( &mut self, span: Span, def: &FullDef, 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.
Sourcepub(crate) fn recognize_builtin_fun(
&mut self,
item: &ItemRef,
) -> Result<Option<BuiltinFunId>, Error>
pub(crate) fn recognize_builtin_fun( &mut self, item: &ItemRef, ) -> Result<Option<BuiltinFunId>, Error>
Checks whether the given id corresponds to a built-in type.
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
Sourcepub(crate) fn the_only_binder(&self) -> &BindingLevel
pub(crate) fn the_only_binder(&self) -> &BindingLevel
Get the only binding level. Panics if there are other binding levels.
Sourcepub(crate) fn the_only_binder_mut(&mut self) -> &mut BindingLevel
pub(crate) fn the_only_binder_mut(&mut self) -> &mut BindingLevel
Get the only binding level. Panics if there are other binding levels.
pub(crate) fn outermost_binder(&self) -> &BindingLevel
pub(crate) fn innermost_binder(&self) -> &BindingLevel
pub(crate) fn innermost_binder_mut(&mut self) -> &mut BindingLevel
pub(crate) fn innermost_generics_mut(&mut self) -> &mut GenericParams
pub(crate) fn lookup_bound_region( &mut self, span: Span, dbid: DebruijnIndex, var: BoundVar, ) -> Result<RegionDbVar, Error>
pub(crate) 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>
pub(crate) fn lookup_early_region( &mut self, span: Span, region: &EarlyParamRegion, ) -> Result<RegionDbVar, Error>
pub(crate) fn lookup_type_var( &mut self, span: Span, param: &ParamTy, ) -> Result<TypeDbVar, Error>
pub(crate) fn lookup_const_generic_var( &mut self, span: Span, param: &ParamConst, ) -> Result<ConstGenericDbVar, Error>
pub(crate) fn lookup_clause_var( &mut self, span: Span, id: usize, ) -> Result<ClauseDbVar, Error>
pub(crate) fn push_generic_params( &mut self, generics: &TyGenerics, ) -> Result<(), Error>
pub(crate) fn push_generic_param( &mut self, param: &GenericParamDef, ) -> Result<(), Error>
Sourcefn push_generics_for_def(
&mut self,
span: Span,
def: &FullDef,
is_parent: bool,
) -> Result<(), Error>
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.
Sourcefn push_generics_for_def_without_parents(
&mut self,
_span: Span,
def: &FullDef,
include_late_bound: bool,
include_assoc_ty_clauses: bool,
) -> Result<(), Error>
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.
Sourcepub(crate) fn translate_def_generics(
&mut self,
span: Span,
def: &FullDef,
) -> Result<(), Error>
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.
This adds generic parameters and predicates to the current environment (as a binder in self.binding_levels
).
This is necessary to translate types that depend on these generics (such as Ty
and TraitRef
).
The constructed GenericParams
can be recovered at the end using self.into_generics()
and stored in the translated item.
Sourcepub(crate) fn translate_def_generics_without_parents(
&mut self,
span: Span,
def: &FullDef,
) -> Result<(), Error>
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.
Sourcepub(crate) fn translate_binder_for_def<F, U>(
&mut self,
span: Span,
kind: BinderKind,
def: &FullDef,
f: F,
) -> Result<Binder<U>, Error>
pub(crate) fn translate_binder_for_def<F, U>( &mut self, span: Span, kind: BinderKind, def: &FullDef, f: F, ) -> Result<Binder<U>, Error>
Push a new binding level corresponding to the provided def
for the duration of the inner
function call.
Sourcepub(crate) fn translate_region_binder<F, T, U>(
&mut self,
_span: Span,
binder: &Binder<T>,
f: F,
) -> Result<RegionBinder<U>, Error>
pub(crate) fn translate_region_binder<F, T, U>( &mut self, _span: Span, binder: &Binder<T>, f: F, ) -> Result<RegionBinder<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).
pub(crate) fn into_generics(self) -> GenericParams
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
Sourcepub(crate) fn register_module(&mut self, item_meta: ItemMeta, def: &FullDef)
pub(crate) fn register_module(&mut self, item_meta: ItemMeta, def: &FullDef)
Register the items inside this module or inherent impl.
pub(crate) fn get_item_kind( &mut self, span: Span, def: &FullDef, ) -> Result<ItemKind, Error>
Sourcepub fn translate_type_decl(
self,
trans_id: TypeDeclId,
item_meta: ItemMeta,
def: &FullDef,
) -> Result<TypeDecl, Error>
pub fn translate_type_decl( 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).
Sourcepub fn translate_function(
self,
def_id: FunDeclId,
item_meta: ItemMeta,
def: &FullDef,
) -> Result<FunDecl, Error>
pub fn translate_function( self, def_id: FunDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<FunDecl, Error>
Translate one function.
Sourcepub fn translate_global(
self,
def_id: GlobalDeclId,
item_meta: ItemMeta,
def: &FullDef,
) -> Result<GlobalDecl, Error>
pub fn translate_global( self, def_id: GlobalDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<GlobalDecl, Error>
Translate one global.
pub fn translate_trait_decl( self, def_id: TraitDeclId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitDecl, Error>
pub fn translate_trait_impl( self, def_id: TraitImplId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitImpl, Error>
Sourcepub fn translate_trait_alias_blanket_impl(
self,
def_id: TraitImplId,
item_meta: ItemMeta,
def: &FullDef,
) -> Result<TraitImpl, Error>
pub fn translate_trait_alias_blanket_impl( self, def_id: TraitImplId, item_meta: ItemMeta, def: &FullDef, ) -> Result<TraitImpl, Error>
Generate a blanket impl for this trait, as in:
trait Alias<U> = Trait<Option<U>, Item = u32> + Clone;
becomes:
trait Alias<U>: Trait<Option<U>, Item = u32> + Clone {}
impl<U, Self: Trait<Option<U>, Item = u32> + Clone> Alias<U> for Self {}
Sourcepub fn translate_virtual_trait_impl(
&mut self,
def_id: TraitImplId,
item_meta: ItemMeta,
vimpl: &VirtualTraitImpl,
) -> Result<TraitImpl, Error>
pub fn translate_virtual_trait_impl( &mut self, def_id: TraitImplId, item_meta: ItemMeta, vimpl: &VirtualTraitImpl, ) -> Result<TraitImpl, Error>
Make a trait impl from a hax VirtualTraitImpl
. Used for constructing fake trait impls for
builtin types like FnOnce
.
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
Sourcepub(crate) fn register_predicates(
&mut self,
preds: &GenericPredicates,
origin: PredicateOrigin,
location: &PredicateLocation,
) -> Result<(), Error>
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…).
pub(crate) fn translate_poly_trait_ref( &mut self, span: Span, bound_trait_ref: &Binder<TraitRef>, ) -> Result<PolyTraitDeclRef, Error>
pub(crate) fn translate_poly_trait_predicate( &mut self, span: Span, bound_trait_ref: &Binder<TraitPredicate>, ) -> Result<PolyTraitDeclRef, Error>
pub(crate) fn translate_trait_predicate( &mut self, span: Span, trait_pred: &TraitPredicate, ) -> Result<TraitDeclRef, Error>
pub(crate) fn translate_trait_ref( &mut self, span: Span, trait_ref: &TraitRef, ) -> Result<TraitDeclRef, Error>
pub(crate) fn register_predicate( &mut self, clause: &Clause, hspan: &Span, origin: PredicateOrigin, location: &PredicateLocation, ) -> Result<(), Error>
pub(crate) fn translate_trait_impl_exprs( &mut self, span: Span, impl_sources: &[ImplExpr], ) -> Result<Vector<TraitClauseId, TraitRef>, Error>
pub(crate) fn translate_trait_impl_expr( &mut self, span: Span, impl_expr: &ImplExpr, ) -> Result<TraitRef, Error>
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<'_, '_>
impl ItemTransCtx<'_, '_>
pub fn check_at_most_one_pred_has_methods( &mut self, span: Span, preds: &GenericPredicates, ) -> Result<(), Error>
pub fn translate_existential_predicates( &mut self, span: Span, self_ty: &ParamTy, preds: &GenericPredicates, region: &Region, ) -> Result<DynPredicate, Error>
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
Sourcepub fn trait_is_dyn_compatible(&mut self, def_id: &DefId) -> Result<bool, Error>
pub fn trait_is_dyn_compatible(&mut self, def_id: &DefId) -> Result<bool, Error>
Query whether a trait is dyn compatible.
TODO(dyn): for now we return false
if the trait has any associated types, as we don’t
handle associated types in vtables.
Sourcefn pred_is_for_self(&self, tref: &TraitRef) -> bool
fn pred_is_for_self(&self, tref: &TraitRef) -> bool
Check whether this trait ref is of the form Self: Trait<...>
.
Sourcepub fn translate_vtable_struct_ref(
&mut self,
span: Span,
tref: &TraitRef,
) -> Result<Option<TypeDeclRef>, Error>
pub fn translate_vtable_struct_ref( &mut self, span: Span, tref: &TraitRef, ) -> Result<Option<TypeDeclRef>, Error>
Given a trait ref, return a reference to its vtable struct, if it is dyn compatible.
Sourcefn add_method_to_vtable_def(
&mut self,
span: Span,
trait_def: &FullDef,
mk_field: impl FnMut(String, Ty),
item: &AssocItem,
) -> Result<(), Error>
fn add_method_to_vtable_def( &mut self, span: Span, trait_def: &FullDef, mk_field: impl FnMut(String, Ty), item: &AssocItem, ) -> Result<(), Error>
Add a method_name: fn(...) -> ...
field for the method.
Sourcefn add_supertraits_to_vtable_def(
&mut self,
span: Span,
mk_field: impl FnMut(String, Ty),
implied_predicates: &GenericPredicates,
) -> Result<(), Error>
fn add_supertraits_to_vtable_def( &mut self, span: Span, mk_field: impl FnMut(String, Ty), implied_predicates: &GenericPredicates, ) -> Result<(), Error>
Add super_trait_n: &'static SuperTraitNVTable
fields.
fn gen_vtable_struct_fields( &mut self, span: Span, trait_def: &FullDef, implied_predicates: &GenericPredicates, ) -> Result<Vector<FieldId, Field>, Error>
Sourcepub(crate) fn translate_vtable_struct(
self,
type_id: TypeDeclId,
item_meta: ItemMeta,
trait_def: &FullDef,
) -> Result<TypeDecl, Error>
pub(crate) fn translate_vtable_struct( self, type_id: TypeDeclId, item_meta: ItemMeta, trait_def: &FullDef, ) -> Result<TypeDecl, Error>
Construct the type of the vtable for this trait.
It’s a struct that has for generics the generics of the trait + one parameter for each associated type of the trait and its parents. TODO(dyn): add the associated types.
struct TraitVTable<TraitArgs.., AssocTys..> { size: usize, align: usize, drop: fn(*mut dyn Trait<…>), method_name: fn(&dyn Trait<…>, Args..) -> Output, … other methods super_trait_0: &’static SuperTrait0VTable … other supertraits }
Source§impl ItemTransCtx<'_, '_>
impl ItemTransCtx<'_, '_>
pub fn translate_vtable_instance_ref( &mut self, span: Span, trait_ref: &TraitRef, impl_ref: &ItemRef, ) -> Result<Option<GlobalDeclRef>, Error>
Sourcefn get_vtable_instance_info<'a>(
&mut self,
span: Span,
impl_def: &'a FullDef,
impl_kind: &TraitImplSource,
) -> Result<(TraitImplRef, TraitDeclRef, TypeDeclRef), Error>
fn get_vtable_instance_info<'a>( &mut self, span: Span, impl_def: &'a FullDef, impl_kind: &TraitImplSource, ) -> Result<(TraitImplRef, TraitDeclRef, TypeDeclRef), Error>
Local helper function to get the vtable struct reference and trait declaration reference
Sourcepub(crate) fn translate_vtable_instance(
self,
global_id: GlobalDeclId,
item_meta: ItemMeta,
impl_def: &FullDef,
impl_kind: &TraitImplSource,
) -> Result<GlobalDecl, Error>
pub(crate) fn translate_vtable_instance( self, global_id: GlobalDeclId, item_meta: ItemMeta, impl_def: &FullDef, impl_kind: &TraitImplSource, ) -> Result<GlobalDecl, Error>
E.g., global <T…, VT…> trait::{vtable_instance}::<ImplTy<T…>> : trait::{vtable}<VT…> = trait::{vtable}<VT…> { drop: &ignore / &<ImplTy<T…> as Drop>::drop, size: size_of(<ImplTy<T…>>), align: align_of(<ImplTy<T…>>), method_0: &<ImplTy<T…> as Trait>::method_0::{shim}, method_1: &<ImplTy<T…> as Trait>::method_1::{shim}, … super_trait_0: &SuperTrait0<VT…>::{vtable_instance}::<ImplTy<T…>>, super_trait_1: &SuperTrait1<VT…>::{vtable_instance}::<ImplTy<T…>>, … }
fn add_method_to_vtable_value( &mut self, span: Span, impl_def: &FullDef, item: &ImplAssocItem, mk_field: impl FnMut(RawConstantExpr), ) -> Result<(), Error>
fn add_supertraits_to_vtable_value( &mut self, span: Span, trait_def: &FullDef, impl_def: &FullDef, mk_field: impl FnMut(RawConstantExpr), ) -> Result<(), Error>
Sourcefn gen_vtable_instance_init_body(
&mut self,
span: Span,
impl_def: &FullDef,
vtable_struct_ref: TypeDeclRef,
) -> Result<Body, Error>
fn gen_vtable_instance_init_body( &mut self, span: Span, impl_def: &FullDef, vtable_struct_ref: TypeDeclRef, ) -> Result<Body, Error>
Generate the body of the vtable instance function.
This is for impl Trait for T
implementation, it does NOT handle builtin impls.
let ret@0 : VTable;
ret@0 = VTable { ... };
return;
pub(crate) fn translate_vtable_instance_init( self, init_func_id: FunDeclId, item_meta: ItemMeta, impl_def: &FullDef, impl_kind: &TraitImplSource, ) -> Result<FunDecl, Error>
Source§impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx>
pub(crate) fn translate_region( &mut self, span: Span, region: &Region, ) -> Result<Region, Error>
pub(crate) fn translate_hax_int_ty(int_ty: &IntTy) -> IntTy
pub(crate) fn translate_hax_uint_ty(uint_ty: &UintTy) -> UIntTy
Sourcepub(crate) fn translate_ty(&mut self, span: Span, ty: &Ty) -> Result<Ty, Error>
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.
fn translate_ty_inner(&mut self, span: Span, ty: &Ty) -> Result<Ty, Error>
pub fn translate_fun_sig( &mut self, span: Span, sig: &Binder<TyFnSig>, ) -> Result<RegionBinder<(Vec<Ty>, Ty)>, Error>
Sourcepub fn translate_generic_args(
&mut self,
span: Span,
substs: &[GenericArg],
trait_refs: &[ImplExpr],
) -> Result<GenericArgs, Error>
pub fn translate_generic_args( &mut self, span: Span, substs: &[GenericArg], trait_refs: &[ImplExpr], ) -> Result<GenericArgs, Error>
Translate generic args. Don’t call directly; use translate_xxx_ref
as much as possible.
Sourcepub fn append_late_bound_to_generics(
&mut self,
span: Span,
generics: GenericArgs,
late_bound: Option<Binder<()>>,
) -> Result<RegionBinder<GenericArgs>, Error>
pub fn append_late_bound_to_generics( &mut self, span: Span, generics: GenericArgs, late_bound: Option<Binder<()>>, ) -> Result<RegionBinder<GenericArgs>, Error>
Append the given late bound variables to the provided generics.
Sourcepub(crate) fn recognize_builtin_type(
&mut self,
item: &ItemRef,
) -> Result<Option<BuiltinTy>, Error>
pub(crate) fn recognize_builtin_type( &mut self, item: &ItemRef, ) -> Result<Option<BuiltinTy>, Error>
Checks whether the given id corresponds to a built-in type.
Sourcepub fn translate_ptr_metadata(&self, item: &ItemRef) -> Option<PtrMetadata>
pub fn translate_ptr_metadata(&self, item: &ItemRef) -> Option<PtrMetadata>
Translate a Dynamically Sized Type metadata kind.
Returns None
if the type is generic, or if it is not a DST.
Sourcepub fn translate_layout(&self, item: &ItemRef) -> Option<Layout>
pub fn translate_layout(&self, item: &ItemRef) -> Option<Layout>
Translate a type layout.
Translates the layout as queried from rustc into
the more restricted Layout
.
Sourcepub fn generate_naive_layout(
&self,
span: Span,
ty: &TypeDeclKind,
) -> Result<Layout, Error>
pub fn generate_naive_layout( &self, span: Span, ty: &TypeDeclKind, ) -> Result<Layout, Error>
Generate a naive layout for this type.
Sourcepub(crate) fn translate_adt_def(
&mut self,
trans_id: TypeDeclId,
def_span: Span,
item_meta: &ItemMeta,
def: &FullDef,
) -> Result<TypeDeclKind, Error>
pub(crate) fn translate_adt_def( &mut self, trans_id: TypeDeclId, def_span: Span, item_meta: &ItemMeta, def: &FullDef, ) -> 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).
fn translate_discriminant( &mut self, def_span: Span, discr: &DiscriminantValue, ) -> Result<ScalarValue, Error>
Trait Implementations§
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> 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
§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more