MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / analyze

Method analyze

src/analysis/callgraph/mod.rs:96–132  ·  view source on GitHub ↗

Perform callgraph analysis on the given instances. The instances should be **all** the instances with MIR available in the current crate.

(
        &mut self,
        instances: Vec<Instance<'tcx>>,
        tcx: TyCtxt<'tcx>,
        typing_env: TypingEnv<'tcx>,
    )

Source from the content-addressed store, hash-verified

94 }
95
96 /// Perform callgraph analysis on the given instances.
97 /// The instances should be **all** the instances with MIR available in the current crate.
98 pub fn analyze(
99 &mut self,
100 instances: Vec<Instance<'tcx>>,
101 tcx: TyCtxt<'tcx>,
102 typing_env: TypingEnv<'tcx>,
103 ) {
104 let idx_insts = instances
105 .into_iter()
106 .map(|inst| {
107 let idx = self.graph.add_node(CallGraphNode::WithBody(inst));
108 (idx, inst)
109 })
110 .collect::<Vec<_>>();
111 for (caller_idx, caller) in idx_insts {
112 let body = tcx.instance_mir(caller.def);
113 // Skip promoted src
114 if body.source.promoted.is_some() {
115 continue;
116 }
117 let mut collector = CallSiteCollector::new(caller, body, tcx, typing_env);
118 collector.visit_body(body);
119 for (callee, location) in collector.finish() {
120 let callee_idx = if let Some(callee_idx) = self.instance_to_index(&callee) {
121 callee_idx
122 } else {
123 self.graph.add_node(CallGraphNode::WithoutBody(callee))
124 };
125 if let Some(edge_idx) = self.graph.find_edge(caller_idx, callee_idx) {
126 // Update edge weight.
127 self.graph.edge_weight_mut(edge_idx).unwrap().push(location);
128 } else {
129 // Add edge if not exists.
130 self.graph.add_edge(caller_idx, callee_idx, vec![location]);
131 }
132 }
133 }
134 }
135

Callers

nothing calls this directly

Calls 4

add_nodeMethod · 0.80
instance_to_indexMethod · 0.80
add_edgeMethod · 0.80
finishMethod · 0.45

Tested by

no test coverage detected