accuracy(Rust): measure import graph accuracy and close gaps below 90%
Part of #237.
Starting estimate: 80-90% recall. This is an unmeasured guess.
Measure
Run codemap on real Rust repositories at pinned commits and compare it to ground truth.
- Suggested ground truth: rustc dep-info or cargo-modules.
- Report: recall, precision, and whether the coverage status was honest for each file.
Likely gaps to check
macro-generated modules, cfg-gated paths, workspace crate edges.
Done when
- Repositories, commits, method and numbers are recorded here.
- Each miss has a root cause.
- Recall is at or above 90%, or the remaining gap is one codemap cannot close and its coverage status says so.
Rust import-graph accuracy (#241)
codemap 4.6.3. Samples, not full-repo numbers. Seeded sample (python random.seed(42)), 40 files per repo, drawn from files reachable in the crate module tree (mod x; from lib.rs/main.rs/bin/tests/examples/benches roots).
| Repo | SHA | Shape | .rs files |
|---|---|---|---|
| tokio-rs/tokio | b499257ef62bd631b83a988d371f4330f545670c | Cargo workspace, 14 crates | 814 |
| BurntSushi/ripgrep | 91f5d22ef48bde459d90a8c7dbeab416e97d0f2b | Cargo workspace, ~10 crates | 102 |
Method: ground truth is a script (not rustc, nothing built) that follows mod x; / #[path] to build each crate's module tree, then resolves use crate::/super::/self:: paths, inline crate:: paths and workspace-crate paths (use tokio::io::X) to the longest module prefix that is a file. Codemap side: codemap --json --importers <file> imports. Ground truth is naive about re-exports and root items (an item defined in lib.rs maps to lib.rs). Extras (codemap edges my script lacked) were checked by hand for ripgrep; for tokio they were not individually verified.
| Repo | sample | truth edges | codemap edges | matched | recall | precision | coverage_status on sample |
|---|---|---|---|---|---|---|---|
| ripgrep | 40 files | 119 (108 scripted + 11 added after hand check) | 109 | 109 | 109/119 = 91.6% | 109/109 = 100% (all 11 script-missing extras verified real) | partial 40/40 |
| tokio | 40 files | 121 | 60 | 29 | 29/121 = 24.0% | 29/60 = 48% strict; 31 extras unverified (all tests/examples/benches edges to tokio/src/lib.rs and mod.rs files, plausible) | partial 40/40 |
Honesty: every sampled Rust file reported partial with the macro/#[path] caveat note, never complete. So no miss under complete. For tokio the caveat is accurate but understates the loss: 15 of 40 sampled files had zero resolved imports while having real crate:: imports.
Root causes, ranked by edges lost
- tokio, 74 of 92 lost edges:
mod x;declared inside a macro invocation is invisible. Example:tokio/src/lib.rs:567-568cfg_fs! { pub mod fs; }socrate::fs::asyncifyintokio/src/fs/copy.rs:1has no edge (importers null, imports empty). Same pattern in io/mod.rs, time, task, etc.; descendants of any macro-wrapped module lose allcrate::edges. Code:scanner/sg-rules/rust.yml:32-33(patternsmod $PATH;only matchmod_itemnodes, not token trees), consumed inscanner/rustgraph.goaddRustModuleDeclarations (line ~167). Inferred, not tested: the rule never fires insidemacro_invocationtoken trees. Fix: medium (scan token_tree formod IDENT ;/pub mod). - tokio tests/examples/benches, 18 lost edges: dev-dependency workspace crate
tokio_testnever resolved (e.g.tokio/tests/sync_notify_owned.rs-> tokio-test/src/lib.rs, task.rs); cross-crate paths resolve only to crate root ormod.rs, not the deeper file (tokio::signal::unix-> tokio/src/signal/unix.rs). Code:scanner/rustgraph.goresolveRustPath / externalPackagesForPath (~764, ~903). Fix: medium. - ripgrep, 7 of 10 lost edges:
use grep_matcher::LineTerminator;(item defined at the root of a workspace crate) produces no edge to that crate's lib.rs. Examplecrates/searcher/src/lines.rs:7. Others in this class: sink.rs:3, regex/matcher.rs, searcher/testutil.rs, core/haystack.rs. Method caveat: my truth maps root items to lib.rs, codemap may be deliberately skipping it. Fix: small if wanted. - ripgrep, 2 lost edges: expression-position
super::render_custom_markup(...)(crates/core/flags/doc/man.rs:66,complete/zsh.rs:30) is not treated as an import of the parent module. Fix: small. - ripgrep, 1 unexplained miss (
crates/printer/src/summary.rs->crates/printer/src/lib.rs), not diagnosed.
Not a miss, worth noting: codemap correctly resolved things my script lacked: tests/*.rs -> tests/hay.rs, tests/util.rs (children of tests/tests.rs), and include_str!("encodings.sh") edges.
Searches/fetches: 0 web. Scripts: local scratch dir/lang/scripts/rust.py. Raw per-file data: local scratch dir/lang/out/{tokio,ripgrep}.json.
Measured with codemap 4.6.3. Sampled numbers are samples, not a census.