pub struct TranslatedCrate {Show 13 fields
pub crate_name: String,
pub options: CliOpts,
pub target_information: SeqHashMap<TargetTriple, TargetInfo>,
pub files: IndexVec<FileId, File>,
pub item_names: SeqHashMap<ItemId, Name>,
pub assoc_item_names: IndexMap<TraitDeclId, AssocItemNames>,
pub short_names: SeqHashMap<ItemId, Name>,
pub type_decls: IndexMap<TypeDeclId, TypeDecl>,
pub fun_decls: IndexMap<FunDeclId, FunDecl>,
pub global_decls: IndexMap<GlobalDeclId, GlobalDecl>,
pub trait_decls: IndexMap<TraitDeclId, TraitDecl>,
pub trait_impls: IndexMap<TraitImplId, TraitImpl>,
pub ordered_decls: Option<DeclarationsGroups>,
}Expand description
The complete data of a Rust crate.
A crate is mainly composed of 5 kinds of items:
- Functions;
- Type definitions;
- Globals (constants and statics);
- Trait declarations;
- Trait implementations.
These can each be found in the corresponding IndexVec. They are in an unspecified (though
deterministic) order.
If you need a more robust order, see ordered_decls.
To get a TranslatedCrate, run charon cargo inside a Rust crate, then deserialize
the resulting crate_name.llbc file using crate::deserialize_llbc.
Fields§
§crate_name: StringThe name of the crate.
options: CliOptsThe options used when calling Charon. Can be used to check that Charon was called with the options that a given consumer requires.
target_information: SeqHashMap<TargetTriple, TargetInfo>Information about each target platform for which the crate was translated. When translating
a crate normally this will have a single entry; when using --targets this will have one
entry per chosen target.
files: IndexVec<FileId, File>The source files composing the crate and its dependencies. Each Span refers to a byte
range within one of these files.
item_names: SeqHashMap<ItemId, Name>The names of all registered items. Available so we can know the names even of items that
failed to translate.
Invariant: after translation, any existing ItemId must have an associated name, even
if the corresponding item wasn’t translated.
assoc_item_names: IndexMap<TraitDeclId, AssocItemNames>The names of all the registered associated items. Available so we can know the names even
of items that failed to translate.
Invariant: after translation, any existing AssocItemId must have an associated name, even
if the corresponding item wasn’t translated.
short_names: SeqHashMap<ItemId, Name>Short names, for items whose last PathElem is unique.
type_decls: IndexMap<TypeDeclId, TypeDecl>The type definitions (structs, enums, …).
fun_decls: IndexMap<FunDeclId, FunDecl>The function definitions.
Each item with a body becomes a function: actual functions, methods, and unevaluated consts/statics.
global_decls: IndexMap<GlobalDeclId, GlobalDecl>The global definitions, which are constants, statics, and thread locals.
trait_decls: IndexMap<TraitDeclId, TraitDecl>The trait declarations.
trait_impls: IndexMap<TraitImplId, TraitImpl>The trait implementations.
ordered_decls: Option<DeclarationsGroups>This contains a list of all the reachable items in the crate in a stable, logical order based on crate and file order, then further grouped and sorted such that every item comes after the items it depends on. Mutually-dependent groups of items are identified as such. This is meant for code-generation tools that want a stable output order.
Not all the items in the TranslatedCrate are included: some trait impls are never
referred to by reachable items so could in principle be removed from the crate, but we keep
them around to be able to tell method implementations apart.
Always Some after translation.
Implementations§
Source§impl TranslatedCrate
impl TranslatedCrate
pub fn item_name(&self, id: impl Into<ItemId>) -> &Name
pub fn assoc_item_name( &self, trait_id: TraitDeclId, id: impl Into<AssocItemId>, ) -> TraitItemName
pub fn item_short_name(&self, id: impl Into<ItemId>) -> &Name
pub fn get_item(&self, trans_id: impl Into<ItemId>) -> Option<ItemRef<'_>>
pub fn get_item_mut(&mut self, trans_id: ItemId) -> Option<ItemRefMut<'_>>
Sourcepub fn remove_item(&mut self, trans_id: ItemId) -> Option<ItemByVal>
pub fn remove_item(&mut self, trans_id: ItemId) -> Option<ItemByVal>
Remove this item from the crate, including the name information about it.
See also TranslatedCrate::remove_item_temporarily.
Sourcepub fn set_new_item_slot(&mut self, id: ItemId, item: impl Into<ItemByVal>)
pub fn set_new_item_slot(&mut self, id: ItemId, item: impl Into<ItemByVal>)
Insert a new item into a slot, and record its name in the name map.
Sourcepub fn remove_item_temporarily(&mut self, trans_id: ItemId) -> Option<ItemByVal>
pub fn remove_item_temporarily(&mut self, trans_id: ItemId) -> Option<ItemByVal>
Remove this item from the crate without touching the name maps.
Useful for modifying items whilst being able to access the rest of the crate.
Put the item back using TranslatedCrate::put_item_back.
See also TranslatedCrate::remove_item.
Sourcepub fn put_item_back(&mut self, id: ItemId, item: impl Into<ItemByVal>)
pub fn put_item_back(&mut self, id: ItemId, item: impl Into<ItemByVal>)
Insert the item into the corresponding slot without recording its name in the name map.
Only use if the item already has its name registered, e.g. if you got it using
TranslatedCrate::remove_item_temporarily.
pub fn all_ids(&self) -> impl Iterator<Item = ItemId> + use<>
pub fn all_items(&self) -> impl Iterator<Item = ItemRef<'_>>
pub fn all_items_mut(&mut self) -> impl Iterator<Item = ItemRefMut<'_>>
pub fn all_items_with_ids(&self) -> impl Iterator<Item = (ItemId, ItemRef<'_>)>
Sourcepub fn the_target_information(&self) -> &TargetInfo
pub fn the_target_information(&self) -> &TargetInfo
When translating without --target, there’s only one target information; this method
retrieves it.
Panics if this crate was translated in multi-target mode.
Trait Implementations§
Source§impl AstVisitable for TranslatedCrate
impl AstVisitable for TranslatedCrate
Source§fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
self, in pre-order traversal.Source§fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
self, in pre-order traversal.Source§impl Clone for TranslatedCrate
impl Clone for TranslatedCrate
Source§fn clone(&self) -> TranslatedCrate
fn clone(&self) -> TranslatedCrate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for TranslatedCrate
impl Default for TranslatedCrate
Source§fn default() -> TranslatedCrate
fn default() -> TranslatedCrate
Source§impl<'de, __State: ?Sized + HashConsSerializerState> DeserializeState<'de, __State> for TranslatedCrate
impl<'de, __State: ?Sized + HashConsSerializerState> DeserializeState<'de, __State> for TranslatedCrate
fn deserialize_state<__D>(
__state: &__State,
__deserializer: __D,
) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for TranslatedCrate
impl Display for TranslatedCrate
Source§impl<'s, V> Drive<'s, V> for TranslatedCratewhere
V: Visitor + Visit<'s, IndexVec<FileId, File>> + Visit<'s, SeqHashMap<ItemId, Name>> + Visit<'s, IndexMap<TraitDeclId, AssocItemNames>> + Visit<'s, IndexMap<TypeDeclId, TypeDecl>> + Visit<'s, IndexMap<FunDeclId, FunDecl>> + Visit<'s, IndexMap<GlobalDeclId, GlobalDecl>> + Visit<'s, IndexMap<TraitDeclId, TraitDecl>> + Visit<'s, IndexMap<TraitImplId, TraitImpl>>,
impl<'s, V> Drive<'s, V> for TranslatedCratewhere
V: Visitor + Visit<'s, IndexVec<FileId, File>> + Visit<'s, SeqHashMap<ItemId, Name>> + Visit<'s, IndexMap<TraitDeclId, AssocItemNames>> + Visit<'s, IndexMap<TypeDeclId, TypeDecl>> + Visit<'s, IndexMap<FunDeclId, FunDecl>> + Visit<'s, IndexMap<GlobalDeclId, GlobalDecl>> + Visit<'s, IndexMap<TraitDeclId, TraitDecl>> + Visit<'s, IndexMap<TraitImplId, TraitImpl>>,
Source§fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, V> DriveMut<'s, V> for TranslatedCratewhere
V: Visitor + VisitMut<'s, IndexVec<FileId, File>> + VisitMut<'s, SeqHashMap<ItemId, Name>> + VisitMut<'s, IndexMap<TraitDeclId, AssocItemNames>> + VisitMut<'s, IndexMap<TypeDeclId, TypeDecl>> + VisitMut<'s, IndexMap<FunDeclId, FunDecl>> + VisitMut<'s, IndexMap<GlobalDeclId, GlobalDecl>> + VisitMut<'s, IndexMap<TraitDeclId, TraitDecl>> + VisitMut<'s, IndexMap<TraitImplId, TraitImpl>>,
impl<'s, V> DriveMut<'s, V> for TranslatedCratewhere
V: Visitor + VisitMut<'s, IndexVec<FileId, File>> + VisitMut<'s, SeqHashMap<ItemId, Name>> + VisitMut<'s, IndexMap<TraitDeclId, AssocItemNames>> + VisitMut<'s, IndexMap<TypeDeclId, TypeDecl>> + VisitMut<'s, IndexMap<FunDeclId, FunDecl>> + VisitMut<'s, IndexMap<GlobalDeclId, GlobalDecl>> + VisitMut<'s, IndexMap<TraitDeclId, TraitDecl>> + VisitMut<'s, IndexMap<TraitImplId, TraitImpl>>,
Source§fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl HasIdxMapOf<FunDeclId> for TranslatedCrate
impl HasIdxMapOf<FunDeclId> for TranslatedCrate
Source§impl HasIdxMapOf<GlobalDeclId> for TranslatedCrate
impl HasIdxMapOf<GlobalDeclId> for TranslatedCrate
fn get_idx_map(&self) -> &IndexMap<GlobalDeclId, Self::Output>
fn get_idx_map_mut(&mut self) -> &mut IndexMap<GlobalDeclId, Self::Output>
Source§impl HasIdxMapOf<TraitDeclId> for TranslatedCrate
impl HasIdxMapOf<TraitDeclId> for TranslatedCrate
fn get_idx_map(&self) -> &IndexMap<TraitDeclId, Self::Output>
fn get_idx_map_mut(&mut self) -> &mut IndexMap<TraitDeclId, Self::Output>
Source§impl HasIdxMapOf<TraitImplId> for TranslatedCrate
impl HasIdxMapOf<TraitImplId> for TranslatedCrate
fn get_idx_map(&self) -> &IndexMap<TraitImplId, Self::Output>
fn get_idx_map_mut(&mut self) -> &mut IndexMap<TraitImplId, Self::Output>
Source§impl HasIdxMapOf<TypeDeclId> for TranslatedCrate
impl HasIdxMapOf<TypeDeclId> for TranslatedCrate
fn get_idx_map(&self) -> &IndexMap<TypeDeclId, Self::Output>
fn get_idx_map_mut(&mut self) -> &mut IndexMap<TypeDeclId, Self::Output>
Source§impl Index<FunDeclId> for TranslatedCrate
impl Index<FunDeclId> for TranslatedCrate
Source§impl Index<GlobalDeclId> for TranslatedCrate
impl Index<GlobalDeclId> for TranslatedCrate
Source§type Output = GlobalDecl
type Output = GlobalDecl
Source§impl Index<TraitDeclId> for TranslatedCrate
impl Index<TraitDeclId> for TranslatedCrate
Source§impl Index<TraitImplId> for TranslatedCrate
impl Index<TraitImplId> for TranslatedCrate
Source§impl Index<TypeDeclId> for TranslatedCrate
impl Index<TypeDeclId> for TranslatedCrate
Source§impl IndexMut<FunDeclId> for TranslatedCrate
impl IndexMut<FunDeclId> for TranslatedCrate
Source§impl IndexMut<GlobalDeclId> for TranslatedCrate
impl IndexMut<GlobalDeclId> for TranslatedCrate
Source§impl IndexMut<TraitDeclId> for TranslatedCrate
impl IndexMut<TraitDeclId> for TranslatedCrate
Source§impl IndexMut<TraitImplId> for TranslatedCrate
impl IndexMut<TraitImplId> for TranslatedCrate
Source§impl IndexMut<TypeDeclId> for TranslatedCrate
impl IndexMut<TypeDeclId> for TranslatedCrate
Source§impl<'a> IntoFormatter for &'a TranslatedCrate
impl<'a> IntoFormatter for &'a TranslatedCrate
Source§impl<__State: ?Sized + HashConsSerializerState> SerializeState<__State> for TranslatedCrate
impl<__State: ?Sized + HashConsSerializerState> SerializeState<__State> for TranslatedCrate
fn serialize_state<__S>(
&self,
__state: &__State,
__serializer: __S,
) -> Result<__S::Ok, __S::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for TranslatedCrate
impl RefUnwindSafe for TranslatedCrate
impl Send for TranslatedCrate
impl Sync for TranslatedCrate
impl Unpin for TranslatedCrate
impl UnsafeUnpin for TranslatedCrate
impl UnwindSafe for TranslatedCrate
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> Indentable for Twhere
T: Display,
impl<T> Indentable for Twhere
T: Display,
§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§impl<I> RecreateContext<I> for I
impl<I> RecreateContext<I> for I
§fn recreate_context(_original_input: I, tail: I) -> I
fn recreate_context(_original_input: I, tail: I) -> I
Source§impl<T> TyVisitable for Twhere
T: AstVisitable,
impl<T> TyVisitable for Twhere
T: AstVisitable,
Source§fn visit_vars(&mut self, v: &mut impl VarsVisitor)
fn visit_vars(&mut self, v: &mut impl VarsVisitor)
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen De Bruijn indices
will count from the outside of self.Source§fn substitute(self, generics: &GenericArgs) -> Self
fn substitute(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
Note: if self is an item that comes from a TraitDecl, you must use
substitute_with_self or substitute_inner_binder, otherwise you’ll get panics.Source§fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
This is appropriate when substituting an inner binder.Source§fn substitute_explicits(self, generics: &GenericArgs) -> Self
fn substitute_explicits(self, generics: &GenericArgs) -> Self
Source§fn substitute_with_self(
self,
generics: &GenericArgs,
self_ref: &TraitRefKind,
) -> Self
fn substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Self
TraitRefKind::SelfId trait ref.Source§fn substitute_with_tref(self, tref: &TraitRef) -> Self
fn substitute_with_tref(self, tref: &TraitRef) -> Self
TraitRefKind::SelfId trait ref.Source§fn try_substitute_with_tref(
self,
tref: &TraitRef,
) -> Result<Self, GenericsMismatch>
fn try_substitute_with_tref( self, tref: &TraitRef, ) -> Result<Self, GenericsMismatch>
TraitRefKind::SelfId trait ref.fn try_substitute( self, generics: &GenericArgs, ) -> Result<Self, GenericsMismatch>
fn try_substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Result<Self, GenericsMismatch>
Source§fn move_under_binder(self) -> Self
fn move_under_binder(self) -> Self
Source§fn move_under_binders(self, depth: DeBruijnId) -> Self
fn move_under_binders(self, depth: DeBruijnId) -> Self
depth binders.Source§fn move_from_under_binder(self) -> Option<Self>
fn move_from_under_binder(self) -> Option<Self>
Source§fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
depth binders. Returns None if it contains a variable bound in
one of these depth binders.Source§fn visit_db_id<B>(
&mut self,
f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen indices will count
from the outside of self.