Skip to main content

Analyzer

Struct Analyzer 

Source
pub struct Analyzer<'tcx> {
    tcx: TyCtxt<'tcx>,
    memo: HashMap<DefId, Rc<Summary>>,
    locals: HashMap<DefId, Rc<Local>>,
    external: Option<HashMap<String, FnSummary>>,
    summarized: HashSet<String>,
    summary_dir: Option<PathBuf>,
    library: bool,
    linked: BTreeMap<String, Resolved>,
}

Fields§

§tcx: TyCtxt<'tcx>§memo: HashMap<DefId, Rc<Summary>>§locals: HashMap<DefId, Rc<Local>>

Each body’s own effects and its calls of local bodies, read from MIR once.

§external: Option<HashMap<String, FnSummary>>§summarized: HashSet<String>

Stable ids of crates the driver summarized.

§summary_dir: Option<PathBuf>§library: bool

The crate being compiled comes from crates.io or git (not the user’s workspace): its summaries keep only real I/O, never verbs of the APIs it calls internally.

§linked: BTreeMap<String, Resolved>

Deferred trait methods resolved over the whole build by a previous run’s link step.

Implementations§

Source§

impl<'tcx> Analyzer<'tcx>

Source

pub fn new(tcx: TyCtxt<'tcx>) -> Self

Source

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

Source

pub fn summarize(&mut self, def_id: DefId) -> Rc<Summary>

The effects of a local function, closure or coroutine, including the closures and coroutines it creates (an async fn’s body is a coroutine it returns), through every local callee.

A summary is the least fixed point of S(f) = own(f) ∪ ⋃ S(g) over the local calls f → g. Recursive functions make the call graph cyclic, so the bodies are grouped into strongly connected components (Tarjan’s algorithm, callees before callers), and each component is iterated until its summaries stop growing. Every member of a cycle then gets the effects of the whole cycle, whichever member is asked for first.

Source

fn component(&mut self, v: DefId, t: &mut Tarjan)

Tarjan’s strongly connected components over local calls, from v. When v closes a component, its members’ summaries are computed together and memoized.

Source

fn local(&mut self, def_id: DefId) -> Rc<Local>

What one body does by itself, and which local bodies it calls, read from its MIR.

Source

fn call( &mut self, summary: &mut Summary, calls: Option<&mut Vec<Edge>>, typing_env: TypingEnv<'tcx>, callee: DefId, gargs: GenericArgs<'tcx>, args: &[&Operand<'tcx>], srcs: &[Src], origin: Option<DefId>, span: Span, )

Add the effects of calling callee to summary. With calls, a call of a local body is recorded there instead of followed (for Self::component).

Source

fn by_name( &self, summary: &mut Summary, path: &str, name: &str, target: Option<String>, span: Span, )

Classify a call into another crate’s API by the verb its name starts with.

Source

fn external(&mut self) -> &HashMap<String, FnSummary>

Source

fn string_constant(&self, op: &Operand<'tcx>) -> Option<String>

The value of a &str constant operand.

Source

fn annotated(&self) -> Vec<DefId>

The functions #[psync::graph] annotated: each contains the item __PSYNC_GRAPH.

Source

fn call_facts(&mut self) -> BTreeMap<String, CallFact>

Facts about every call in the annotated functions (and the closures and async blocks in them), keyed by the source location of the callee’s name, for the macro’s next expansion.

Source

fn pdg(&mut self) -> CratePdg

The dependence graph of every annotated function and local async fn, and of the closures and async blocks in them: their calls with effects (or into this crate) and their awaits, each with the branches that decide whether it runs.

Source

fn entries(&self) -> Vec<PdgEntry>

The crate’s entry points: main, and every local function or closure handed to a web framework’s registering call (axum’s get(h), MethodRouter::post(h), …; actix-web’s to(h), which its #[get("/x")] macros also expand to), with the route a string literal gives it. axum names the route downstream (.route("/x", get(h))), actix-web upstream (Resource::new("/x")...to(h)) or downstream (.route("/x", web::get().to(h))): both directions are followed through the framework’s own calls.

Source

fn body_pdg(&mut self, def_id: DefId, body: &'tcx Body<'tcx>) -> FnPdg

Source

pub fn write_summaries(&mut self)

Write the summaries of every local function for crates that depend on this one.

Auto Trait Implementations§

§

impl<'tcx> !DynSend for Analyzer<'tcx>

§

impl<'tcx> !DynSync for Analyzer<'tcx>

§

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

§

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

§

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

§

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

§

impl<'tcx> Forget for Analyzer<'tcx>

§

impl<'tcx> Freeze for Analyzer<'tcx>

§

impl<'tcx> Move for Analyzer<'tcx>

§

impl<'tcx> Unpin for Analyzer<'tcx>

§

impl<'tcx> UnsafeUnpin for Analyzer<'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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.