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: boolThe 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>
impl<'tcx> Analyzer<'tcx>
pub fn new(tcx: TyCtxt<'tcx>) -> Self
fn has_body(&self, def_id: DefId) -> bool
Sourcepub fn summarize(&mut self, def_id: DefId) -> Rc<Summary>
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.
Sourcefn component(&mut self, v: DefId, t: &mut Tarjan)
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.
Sourcefn local(&mut self, def_id: DefId) -> Rc<Local>
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.
Sourcefn 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,
)
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).
Sourcefn by_name(
&self,
summary: &mut Summary,
path: &str,
name: &str,
target: Option<String>,
span: Span,
)
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.
fn external(&mut self) -> &HashMap<String, FnSummary>
Sourcefn string_constant(&self, op: &Operand<'tcx>) -> Option<String>
fn string_constant(&self, op: &Operand<'tcx>) -> Option<String>
The value of a &str constant operand.
Sourcefn annotated(&self) -> Vec<DefId>
fn annotated(&self) -> Vec<DefId>
The functions #[psync::graph] annotated: each contains the item __PSYNC_GRAPH.
Sourcefn call_facts(&mut self) -> BTreeMap<String, CallFact>
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.
Sourcefn pdg(&mut self) -> CratePdg
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.
Sourcefn entries(&self) -> Vec<PdgEntry>
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.
fn body_pdg(&mut self, def_id: DefId, body: &'tcx Body<'tcx>) -> FnPdg
Sourcepub fn write_summaries(&mut self)
pub fn write_summaries(&mut self)
Write the summaries of every local function for crates that depend on this one.