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>
impl<'tcx> MarkerCtx<'tcx>
fn tcx(&self) -> TyCtxt<'tcx>
fn db(&self) -> &MarkerDatabase<'tcx>
Sourcepub fn source_annotations(&self, def_id: DefId) -> &[Annotation]
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.
Sourcepub fn external_markers<D: IntoDefId>(&self, did: D) -> &[MarkerAnnotation]
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.
Sourcepub fn combined_markers(
&self,
def_id: DefId,
) -> impl Iterator<Item = &MarkerAnnotation>
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.
Sourcefn defid_rewrite(&self, def_id: DefId) -> DefId
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.
Sourcepub fn is_externally_marked<D: IntoDefId>(&self, did: D) -> bool
pub fn is_externally_marked<D: IntoDefId>(&self, did: D) -> bool
Are there any external markers on this item?
Sourcepub fn is_locally_marked(&self, def_id: DefId) -> bool
pub fn is_locally_marked(&self, def_id: DefId) -> bool
Are there any local markers on this item?
Sourcepub fn is_marked<D: IntoDefId + Copy>(&self, did: D) -> bool
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).
Sourcepub fn source_annotations_found(&self) -> Vec<(DefId, &[Annotation])>
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.
Sourcepub fn external_annotations(&self) -> &HashMap<DefId, Vec<MarkerAnnotation>>
pub fn external_annotations(&self) -> &HashMap<DefId, Vec<MarkerAnnotation>>
Direct access to the loaded database of external markers.
Sourcepub fn marker_is_reachable(&self, res: Instance<'tcx>) -> bool
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
Sourcepub fn has_transitive_reachable_markers(
&self,
res: impl Into<MaybeMonomorphized<'tcx>>,
) -> bool
pub fn has_transitive_reachable_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> bool
Queries the transitive marker cache.
pub fn get_reachable_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> &[Identifier]
fn get_reachable_and_self_markers( &self, res: impl Into<MaybeMonomorphized<'tcx>>, ) -> impl Iterator<Item = Identifier> + '_
Sourcefn compute_reachable_markers(
&self,
res: MaybeMonomorphized<'tcx>,
) -> Box<[Identifier]>
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.
fn span_err(&self, span: Span, msg: impl Into<DiagMessage>)
Sourcefn terminator_reachable_markers(
&self,
local_decls: &LocalDecls<'_>,
terminator: &Terminator<'tcx>,
expect_resolve: bool,
) -> impl Iterator<Item = Identifier> + '_
fn terminator_reachable_markers( &self, local_decls: &LocalDecls<'_>, terminator: &Terminator<'tcx>, expect_resolve: bool, ) -> impl Iterator<Item = Identifier> + '_
Does this terminator carry a marker?
Sourcepub fn all_type_markers<'a>(
&'a self,
ty: Ty<'tcx>,
) -> impl Iterator<Item = (&'a MarkerAnnotation, (Ty<'tcx>, DefId))>
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.
pub fn shallow_type_markers<'a>( &'a self, key: Ty<'tcx>, ) -> impl Iterator<Item = TypeMarkerElem> + 'a
pub fn deep_type_markers<'a>(&'a self, key: Ty<'tcx>) -> &'a TypeMarkers
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>
pub fn type_has_surface_markers(&self, ty: Ty<'_>) -> Option<DefId>
Sourcepub fn all_function_markers<'a>(
&'a self,
function: MaybeMonomorphized<'tcx>,
) -> impl Iterator<Item = (&'a MarkerAnnotation, Option<(Ty<'tcx>, DefId)>)>
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).
Sourcepub fn all_annotations(
&self,
) -> impl Iterator<Item = (DefId, Either<&Annotation, &MarkerAnnotation>)>
pub fn all_annotations( &self, ) -> impl Iterator<Item = (DefId, Either<&Annotation, &MarkerAnnotation>)>
Iterate over all discovered annotations, whether local or external
pub fn functions_seen(&self) -> Vec<MaybeMonomorphized<'tcx>>
pub fn has_stub(&self, def_id: DefId) -> Option<&'static Stub>
Trait Implementations§
Source§impl<'tcx> From<MarkerDatabase<'tcx>> for MarkerCtx<'tcx>
impl<'tcx> From<MarkerDatabase<'tcx>> for MarkerCtx<'tcx>
Source§fn from(value: MarkerDatabase<'tcx>) -> Self
fn from(value: MarkerDatabase<'tcx>) -> Self
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> 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,
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