Struct TranslateCtx

Source
pub struct TranslateCtx<'tcx> {
Show 13 fields pub tcx: TyCtxt<'tcx>, pub sysroot: PathBuf, pub hax_state: StateWithBase<'tcx>, pub options: TranslateOptions, pub translated: TranslatedCrate, pub id_map: HashMap<TransItemSource, AnyTransId>, pub reverse_id_map: HashMap<AnyTransId, TransItemSource>, pub file_to_id: HashMap<FileName, FileId>, pub errors: RefCell<ErrorCtx>, pub items_to_translate: BTreeSet<TransItemSource>, pub processed: HashSet<TransItemSource>, pub cached_names: HashMap<DefId, Name>, pub cached_item_metas: HashMap<DefId, ItemMeta>,
}
Expand description

Translation context used while translating the crate data into our representation.

Fields§

§tcx: TyCtxt<'tcx>

The Rust compiler type context

§sysroot: PathBuf

Path to the toolchain root.

§hax_state: StateWithBase<'tcx>

The Hax context

§options: TranslateOptions

The options that control translation.

§translated: TranslatedCrate

The translated data.

§id_map: HashMap<TransItemSource, AnyTransId>

The map from rustc id to translated id.

§reverse_id_map: HashMap<AnyTransId, TransItemSource>

The reverse map of ids.

§file_to_id: HashMap<FileName, FileId>

The reverse filename map.

§errors: RefCell<ErrorCtx>

Context for tracking and reporting errors.

§items_to_translate: BTreeSet<TransItemSource>

The declarations we came accross and which we haven’t translated yet. We keep them sorted to make the output order a bit more stable.

§processed: HashSet<TransItemSource>

The declaration we’ve already processed (successfully or not).

§cached_names: HashMap<DefId, Name>

Cache the names to compute them only once each.

§cached_item_metas: HashMap<DefId, ItemMeta>

Cache the ItemMetas to compute them only once each.

Implementations§

Source§

impl TranslateCtx<'_>

Source

pub fn get_mir( &mut self, def_id: &DefId, span: Span, ) -> Result<Option<MirBody<()>>, Error>

Source§

impl<'tcx, 'ctx> TranslateCtx<'tcx>

Source

fn register_module_item(&mut self, def_id: &DefId)

Register a HIR item and all its children. We call this on the crate root items and end up exploring the whole crate.

Source

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

Register the items inside this module.

Source

pub(crate) fn translate_item(&mut self, item_src: &TransItemSource)

Source

pub(crate) fn translate_item_aux( &mut self, def_id: &DefId, trans_id: Option<AnyTransId>, ) -> Result<(), Error>

Source§

impl<'tcx, 'ctx> TranslateCtx<'tcx>

Source

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

Span an error and register the error.

Source

fn register_file(&mut self, filename: FileName, span: Span) -> FileId

Register a file if it is a “real” file and was not already registered span must be a span from which we obtained that filename.

Source

fn path_elem_for_def( &mut self, span: Span, def_id: &DefId, ) -> Result<Option<PathElem>, Error>

Source

pub fn hax_def_id_to_name(&mut self, def_id: &DefId) -> Result<Name, Error>

Retrieve an item name from a [DefId]. We lookup the path associated to an id, and convert it to a name. Paths very precisely identify where an item is. There are important subcases, like the items in an Impl block:

impl<T> List<T> {
  fn new() ...
}

One issue here is that “List” doesn’t appear in the path, which would look like the following:

TypeNS("Crate") :: Impl :: ValueNs("new") ^^^ This is where “List” should be

For this reason, whenever we find an Impl path element, we actually lookup the type of the sub-path, from which we can derive a name.

Besides, as there may be several “impl” blocks for one type, each impl block is identified by a unique number (rustc calls this a “disambiguator”), which we grab.

§Example:

For instance, if we write the following code in crate test and module bla:

impl<T> Foo<T> {
  fn foo() { ... }
}

impl<T> Foo<T> {
  fn bar() { ... }
}

The names we will generate for foo and bar are: [Ident("test"), Ident("bla"), Ident("Foo"), Impl(impl<T> Ty<T>, Disambiguator(0)), Ident("foo")] [Ident("test"), Ident("bla"), Ident("Foo"), Impl(impl<T> Ty<T>, Disambiguator(1)), Ident("bar")]

Source

pub fn catch_sinto<S, T, U>( &mut self, s: &S, span: Span, x: &T, ) -> Result<U, Error>
where T: Debug + SInto<S, U>,

Translates T into U using hax’s SInto trait, catching any hax panics.

Source

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

Source

pub(crate) fn translate_attr_info(&mut self, def: &FullDef) -> AttrInfo

Source

pub(crate) fn translate_item_meta( &mut self, def: &FullDef, name: Name, name_opacity: ItemOpacity, ) -> ItemMeta

Compute the meta information for a Rust item.

Source

pub fn translate_filename(&mut self, name: &FileName) -> FileName

Source

pub fn translate_raw_span(&mut self, rspan: &Span) -> RawSpan

Source

pub fn translate_span_from_source_info( &mut self, source_scopes: &IndexVec<SourceScope, SourceScopeData>, source_info: &SourceInfo, ) -> Span

Compute span data from a Rust source scope

Source

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

Source

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

Source

pub(crate) fn translate_attribute( &mut self, attr: &Attribute, ) -> Option<Attribute>

Translates a rust attribute. Returns None if the attribute is a doc comment (rustc encodes them as attributes). For now we use Strings for Attributes.

Source

pub(crate) fn translate_inline(&self, def: &FullDef) -> Option<InlineAttr>

Source

pub(crate) fn is_extern_item(&mut self, def: &FullDef) -> bool

Whether this item is in an extern { .. } block, in which case it has no body.

Source

pub(crate) fn opacity_for_name(&self, name: &Name) -> ItemOpacity

Source

pub(crate) fn register_id_no_enqueue( &mut self, src: &Option<DepSource>, id: TransItemSource, ) -> AnyTransId

Source

pub(crate) fn register_and_enqueue_id( &mut self, src: &Option<DepSource>, id: TransItemSource, ) -> AnyTransId

Register this id and enqueue it for translation.

Source

pub(crate) fn register_type_decl_id( &mut self, src: &Option<DepSource>, id: &DefId, ) -> TypeDeclId

Source

pub(crate) fn register_fun_decl_id( &mut self, src: &Option<DepSource>, id: &DefId, ) -> FunDeclId

Source

pub(crate) fn register_trait_decl_id( &mut self, src: &Option<DepSource>, id: &DefId, ) -> TraitDeclId

Source

pub(crate) fn register_trait_impl_id( &mut self, src: &Option<DepSource>, id: &DefId, ) -> TraitImplId

Source

pub(crate) fn register_global_decl_id( &mut self, src: &Option<DepSource>, id: &DefId, ) -> GlobalDeclId

Source

pub(crate) fn with_def_id<F, T>( &mut self, def_id: &DefId, item_id: Option<AnyTransId>, f: F, ) -> T
where F: FnOnce(&mut Self) -> T,

Source§

impl<'tcx, 'ctx> TranslateCtx<'tcx>

Source

pub(crate) fn translate_trait_item_name( &mut self, def_id: &DefId, ) -> Result<TraitItemName, Error>

Remark: this doesn’t register the def id (on purpose)

Trait Implementations§

Source§

impl<'tcx, 'ctx> Display for TranslateCtx<'tcx>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoFormatter for &'a TranslateCtx<'_>

Source§

type C = FmtCtx<'a>

Source§

fn into_fmt(self) -> Self::C

Auto Trait Implementations§

§

impl<'tcx> !Freeze for TranslateCtx<'tcx>

§

impl<'tcx> !RefUnwindSafe for TranslateCtx<'tcx>

§

impl<'tcx> !Send for TranslateCtx<'tcx>

§

impl<'tcx> !Sync for TranslateCtx<'tcx>

§

impl<'tcx> Unpin for TranslateCtx<'tcx>

§

impl<'tcx> !UnwindSafe for TranslateCtx<'tcx>

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> Indentable for T
where T: Display,

§

fn indented(self, indent: &str) -> Indented<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line of the formatted output will be prefixed with the indent. Read more
§

fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line except for the first of the formatted output will be prefixed with the indent. Read more
§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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