r/Compilers • u/blune-foo • 14d ago
PRISM v2: a syntax-only call-graph resolver that picks precision over soundness (97.7% edge precision on 24 projects, 8 languages, checked against compiler tooling)
Hey, I wanted to share an algorithm I built for cheap call-graph approximation. It's called PRISM (Polyglot Resolution via Inverted Symbol Map), and it's the call-graph resolver in libeulix, a Rust library that parses C, C++, Go, Java, JavaScript, PHP, Python, Rust and TypeScript with Tree-sitter. v2 trades soundness for precision, and I'd like this sub's take on that.
Why precision
- Most call graphs aim to be sound: include every edge that could happen, accept the false positives. That's right for compilers and verification.
- PRISM is used by people navigating multi-million-LOC codebases, and by LLMs. Eulix (the parent repo) uses the graph to pick which code goes into a coding agent's context. A false edge wastes context, and the model treats it as a real relationship. A missed edge is cheaper, since the agent usually finds that code another way (text search, symbol lookup, a follow-up query).
- So v2 only emits an edge it can justify. If it can't work out a receiver's type, it emits nothing. v1 guessed by unique method name.
How it resolves (no type checker, no build)
- Locals shadow imports, imports shadow globals. A call to the caller's own parameter never binds to a global of the same name.
- Method calls resolve from the receiver. In Go and Java the type comes from the declaration (field, parameter,
var x T,new T()). - Calls through an interface or base class link to the project's implementations (CHA-style).
- Unknown receiver, no edge.
Results
24 pinned open-source projects, three per language, compared against each language's own tooling: go/types (gin, chi, cobra), javac (gson, jsoup, commons-cli), jedi (flask, click, requests), rust-analyzer LSIF (ripgrep, serde_json, fd), the TypeScript checker (class-validator, class-transformer, immer, plus axios, markdown-it and mocha with allowJs), and libclang (cJSON, zlib, Lua, tinyxml2, pugixml, yaml-cpp). Numbers are pooled per language.
| Language | v2 precision | v2 recall | v1 precision |
|---|---|---|---|
| Go | 100.0% | 72.6% | 67.5% |
| TypeScript | 100.0% | 82.7% | 93.7% |
| C | 99.8% | 84.9% | 99.8% |
| Java | 99.7% | 94.2% | 62.3% |
| Python | 99.5% | 79.5% | 68.7% |
| Rust | 99.1% | 38.3% | 39.5% |
| JavaScript | 92.7% | 66.9% | 95.4% |
| C++ | 75.3% | 56.1% | 64.6% |
Overall: 17,784 of 18,199 v2 edges are correct (97.7%), vs 64.9% for v1. Pooled recall is 69.8%.
Weak spots
- C++: yaml-cpp alone gives 288 of the 415 wrong edges (66.1% precision) from overload confusion. The other 23 projects are at 90+%.
- Recall drops wherever a receiver's type must be inferred. Rust finds 38% of calls because
let x = foo();has no annotation. Go on chi is 57% (locals assigned from calls). class-transformer is 39%, where v1 got 87% by guessing. - JavaScript is the one language where v1 was more precise: some method calls on built-ins get linked to project methods with the same name.
Use of AI
I used AI, but only in the recent commits. I didn't know how to code with AI before, and as a fresher, not learning it felt like a mistake since it's here to stay whether we like it or not. It helped build the bench harness, fix Go and Java method calls, add a C/C++ ifdef branch checker to pick the right header files, and with smaller things like docs, comments and finding bugs.
Questions
- Cheapest way to recover Rust and Go method recall without becoming a type checker? I'm thinking of propagating return types one hop, for locals assigned from a call whose callee declares a return type.
- Any prior work treating call-graph construction as precision-first for retrieval/IR?
- Problems with the scoring? Methodology, TP/FP/FN definitions and per-call-kind tables: Call-Graph Accuracy
Repo: https://github.com/Nurysso/eulix (Apache-2.0). Harness is in bench/callgraph; make bench-callgraph reproduces the numbers.