Repository navigation
fix(rust): resolve use paths by the module tree and Cargo manifests (#4544) - #4558
Merged
Merged
Conversation
…#4544) Rust import tokens (`crate::a::B`, `super::x`, `other_crate::y`) went through the generic name search, which read them as files called `B`/`y`, so a Rust workspace's import graph was nearly empty. New core/rust_modules.py resolves crate::/self::/super::, 2018 child modules, workspace and path dependencies (Cargo.toml [dependencies], workspace = true, renames, lib names with hyphens as underscores), Rust 2015 crate-relative paths, globs and grouped uses, and follows `pub use` re-exports up to two hops. The extractor now also records `#[path = "..."] mod m;` and `extern crate x;`, and rescopes self::/super:: paths written inside inline `mod tests { ... }` blocks. room4doom: 293 -> 1,890 import edges; .rs files with no internal links 267 -> 48. The import-graph accuracy oracle now scores Rust `use` paths too (serde-rs/json: 37 -> 211 resolvable imports, 100% / 100%). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR
Both legs, blessed via crucible_check.py --update --yes with no timeouts (an earlier run under load hit a CSS ReDoS timeout and was discarded). scope_check.py --expect rust: every per-file diff is a rust/ file except Composition Fit (Z-Score), which reads the graph role (PageRank / blast radius) normalized over the whole crucible graph. The repo-wide rollups (network macro, PageRank-ranked bottlenecks, column digests, LLM brief, firewall imports_unknown +3 from `extern crate`) move with the new Rust edges. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4544
Problem
Rust
usetokens (crate::render::bsp::Node,super::x,wad::WadData) went through the generic name search, which read them as files calledNode/WadData. A Rust workspace's import graph came out nearly empty.Fix (Rust-only)
gitgalaxy/core/rust_modules.py(new) resolves Rust paths by the module tree and the Cargo manifests:crate::,self::,super::(repeatable), and Rust 2018 child-module paths. A module is<crate dir>/a/b.rsora/b/mod.rs. A path resolves to the deepest module that exists as a file, socrate::a::b::Itemgoes toa/b.rs.[dependencies]path entries andworkspace = true(looked up in[workspace.dependencies]), renamed dependencies, the package's own lib (for bins, tests and examples), and any scanned package's[lib]/[package]name, with hyphens read as underscores. std and crates.io crates get no edge.edition) also try crate-relative paths.use a::{b, c::{self, d}}.pub usere-exports are followed up to 2 hops, named first, then the one glob that can supply the item (narrowed by declared names).tomllib, so the graph does not change between Python 3.10 and 3.11+. Lookups are memoized.network_risk_sensor._resolve_target: a Rust token never falls back to the name search.#[path]tokens resolve exactly against the declaring file's directory.rust.py_dependency_capture+galaxyscope.extract_raw_imports):#[path = "x.rs"] mod m;is recorded as./x.rs.extern crate x;is recorded.self::orsuper::path inside an inlinemod tests { … }is rescoped to the file, souse super::*in a test module does not draw a false edge to the parent module.Evidence
room4doom (real rescan,
--db-only):.rsfiles withinternal_dependency_links=0uselines expand to 5,004 path tokens. 3,920 of them resolve; these are all thecrate/super/self/workspace-crate forms. The 1,084 that do not resolve are about 1,040 std/third-party paths (std 557, glam 100, log 83, …) plus about 35crate::/super::paths indocs/cool_things_tried/sketches, which belong to no crate. Distinct file pairs then collapse those 3,920 to about 1,900 edges, about 5 per file (chocolate-doom has 6.3).use vr::ControllerStateresolves torender/vr/src/actions.rs.tests/tools/import_graph_accuracy.pynow also scores Rustusepaths,#[path]andextern crate, using tree-sitter use-trees plus Cargo. On room4doom it finds 3,666 resolvable imports with recall 1.000, 1 FP (a template file tree-sitter cannot parse) and 1 FN (an oracle superset). On serde-rs/json, resolvable imports go from 37 to 211 at 100% precision and 100% recall; I updated therustentry oftests/import_graph_accuracy_baseline.json.tests/core_engine/test_rust_module_resolution_4544.pyis a 4-crate workspace written to disk, run through the real extractor and sensor. It pins the exact 20 edges. A realgalaxyscopescan of the same fixture gives the identical 20.Golden masters
golden-lock.sh python tests/tools/crucible_check.py --update --yes, after the real-scan proof.defensive_programming_constructsdiff. I re-ran it on a quiet box with 0 timeouts; both legs are symmetric (14 files each).scope_check.py --mode both --expect rust: 282 diffs are in rust/ files. The only per-file diffs outside Rust are 26Composition Fit (Z-Score)values. That score reads the file's graph role (PageRank / blast radius), which is normalized over the whole crucible graph.firewall.imports_unknown+3 fromextern cratetokens.Gates
pr_gates(full) passes. Ratchets: 6/6 pass.portsneedsJAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64on this box, because Maven otherwise picks Java 21 and cannot build release 17.dead_key_audit: allowlisted the Cargo.toml keysbuildandworkspace, which come from a manifest on disk.🤖 Generated with Claude Code
https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR