paralegal_flow::ann::db

Struct MarkerCtx

Source
pub struct MarkerCtx<'tcx>(Rc<MarkerDatabase<'tcx>>);
Expand description

The marker context is a database which can be queried as to whether functions or types carry markers, whether markers are reachable in bodies, etc.

The idea is that this struct provides basic information about the presence of markers and takes care of memoizing and caching such information efficiently but it does not interpret what this information means. Interpretation is done by [crate::ana::inline::InlineJudge].

This is a smart-pointer wrapper around the actual payload (MarkerDatabase).

Tuple Fields§

§0: Rc<MarkerDatabase<'tcx>>

Implementations§

Source§

impl<'tcx> MarkerCtx<'tcx>

Source

fn tcx(&self) -> TyCtxt<'tcx>

Source

fn db(&self) -> &MarkerDatabase<'tcx>

Source

pub fn source_annotations(&self, def_id: DefId) -> &[Annotation]

Retrieves the local annotations for this item. If no such annotations are present an empty slice is returned.

Query is cached.

Source

pub fn external_markers<D: IntoDefId>(&self, did: D) -> &[MarkerAnnotation]

Retrieves any external markers on this item. If there are not such markers an empty slice is returned.

THe external marker database is populated at construction.

Source

pub fn combined_markers( &self, def_id: DefId, ) -> impl Iterator<Item = &MarkerAnnotation>

All markers reachable for this item (local and external).

Queries are cached/precomputed so calling this repeatedly is cheap.

Source

fn defid_rewrite(&self, def_id: DefId) -> DefId

For async handling. If this id corresponds to an async closure we try to resolve its parent item which the markers would actually be placed on.

Source

pub fn is_externally_marked<D: IntoDefId>(&self, did: D) -> bool

Are there any external markers on this item?

Source

pub fn is_locally_marked(&self, def_id: DefId) -> bool

Are there any local markers on this item?

Source

pub fn is_marked<D: IntoDefId + Copy>(&self, did: D) -> bool

Are there any markers (local or external) on this item?

This is in contrast to Self::marker_is_reachable which also reports if markers are reachable from the body of this function (if it is one).

Source

pub fn source_annotations_found(&self) -> Vec<(DefId, &[Annotation])>

Return a complete set of local annotations that were discovered.

Crucially this is a “readout” from the marker cache, which means only items reachable from the paralegal_flow::analyze will end up in this collection.

Source

pub fn external_annotations(&self) -> &HashMap<DefId, Vec<MarkerAnnotation>>

Direct access to the loaded database of external markers.

Source

pub fn marker_is_reachable(&self, res: Instance<'tcx>) -> bool

Are there markers reachable from this (function)?

Returns true if the item itself carries a marker or if one of the functions called in its body are marked.

XXX Does not take into account reachable type markers

Source

pub fn has_transitive_reachable_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> bool

Queries the transitive marker cache.

Source

pub fn get_reachable_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> &[Identifier]

Source

fn get_reachable_and_self_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> impl Iterator<Item = Identifier> + '_

Source

fn compute_reachable_markers( &self, res: MaybeMonomorphized<'tcx>, ) -> Box<[Identifier]>

If the transitive marker cache did not contain the answer, this is what computes it.

Source

fn span_err(&self, span: Span, msg: impl Into<DiagMessage>)

Source

fn terminator_reachable_markers( &self, local_decls: &LocalDecls<'_>, terminator: &Terminator<'tcx>, expect_resolve: bool, ) -> impl Iterator<Item = Identifier> + '_

Does this terminator carry a marker?

Source

pub fn all_type_markers<'a>( &'a self, ty: Ty<'tcx>, ) -> impl Iterator<Item = (&'a MarkerAnnotation, (Ty<'tcx>, DefId))>

All the markers applied to this type and its subtypes.

Returns (ann, (ty, did)) tuples which are the marker annotation ann, the specific type ty that it was applied to and the did [Defid] of that type that was used to look up the annotations.

Source

pub fn shallow_type_markers<'a>( &'a self, key: Ty<'tcx>, ) -> impl Iterator<Item = TypeMarkerElem> + 'a

Source

pub fn deep_type_markers<'a>(&'a self, key: Ty<'tcx>) -> &'a TypeMarkers

Source

fn type_markers_for_adt<'a>( &'a self, adt: &'a AdtDef<'tcx>, generics: &'tcx List<GenericArg<'tcx>>, ) -> impl Iterator<Item = &'a TypeMarkerElem> + use<'tcx, 'a>

Source

pub fn type_has_surface_markers(&self, ty: Ty<'_>) -> Option<DefId>

Source

pub fn all_function_markers<'a>( &'a self, function: MaybeMonomorphized<'tcx>, ) -> impl Iterator<Item = (&'a MarkerAnnotation, Option<(Ty<'tcx>, DefId)>)>

All markers placed on this function, directly or through the type plus the type that was marked (if any).

Source

pub fn all_annotations( &self, ) -> impl Iterator<Item = (DefId, Either<&Annotation, &MarkerAnnotation>)>

Iterate over all discovered annotations, whether local or external

Source

pub fn functions_seen(&self) -> Vec<MaybeMonomorphized<'tcx>>

Source

pub fn has_stub(&self, def_id: DefId) -> Option<&'static Stub>

Trait Implementations§

Source§

impl<'tcx> Clone for MarkerCtx<'tcx>

Source§

fn clone(&self) -> MarkerCtx<'tcx>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tcx> From<MarkerDatabase<'tcx>> for MarkerCtx<'tcx>

Source§

fn from(value: MarkerDatabase<'tcx>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'tcx> Freeze for MarkerCtx<'tcx>

§

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

§

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

§

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

§

impl<'tcx> Unpin for MarkerCtx<'tcx>

§

impl<'tcx> !UnwindSafe for MarkerCtx<'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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> Captures<'_> for T
where T: ?Sized,