Skip to main content

infigraph_core/resolve/
mod.rs

1mod calls;
2pub(crate) mod inherits;
3
4pub use calls::*;
5
6/// Statistics from call/inheritance resolution.
7#[derive(Debug)]
8pub struct ResolveStats {
9    pub total_calls: usize,
10    pub resolved: usize,
11    pub unresolved: usize,
12    pub learned_resolved: usize,
13    pub inherits_resolved: usize,
14}
15
16impl std::fmt::Display for ResolveStats {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        if self.learned_resolved > 0 {
19            write!(
20                f,
21                "Call resolution: {} cross-file calls, {} resolved ({} from learned patterns), {} unresolved (builtins/externals)",
22                self.total_calls, self.resolved, self.learned_resolved, self.unresolved
23            )?;
24        } else {
25            write!(
26                f,
27                "Call resolution: {} cross-file calls, {} resolved, {} unresolved (builtins/externals)",
28                self.total_calls, self.resolved, self.unresolved
29            )?;
30        }
31        if self.inherits_resolved > 0 {
32            write!(f, ", {} inheritance edges resolved", self.inherits_resolved)?;
33        }
34        Ok(())
35    }
36}
37
38// Shared helpers used by both calls and inherits submodules.
39
40fn shortest_id<'a, I, F>(iter: I, pred: F) -> Option<String>
41where
42    I: Iterator<Item = &'a (String, String, String)>,
43    F: Fn(&(String, String, String)) -> bool,
44{
45    iter.filter(|t| pred(t))
46        .min_by(|(a, _, _), (b, _, _)| a.len().cmp(&b.len()).then_with(|| a.cmp(b)))
47        .map(|(id, _, _)| id.clone())
48}
49
50fn escape(s: &str) -> String {
51    s.replace('\'', "\\'")
52}