Skip to content

fix(rust): resolve use paths by the module tree and Cargo manifests (#4544) - #4558

Merged
squid-protocol merged 6 commits into
mainfrom
fix/4544-rust-imports
Oct 6, 2026
Merged

squid-protocol merged 6 commits into
mainfrom
fix/4544-rust-imports

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #4544

Problem

Rust use tokens (crate::render::bsp::Node, super::x, wad::WadData) went through the generic name search, which read them as files called Node / 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.rs or a/b/mod.rs. A path resolves to the deepest module that exists as a file, so crate::a::b::Item goes to a/b.rs.
    • Workspace crates: [dependencies] path entries and workspace = 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.
    • Rust 2015 packages (manifest without edition) also try crate-relative paths.
    • Globs, grouped and nested use a::{b, c::{self, d}}. pub use re-exports are followed up to 2 hops, named first, then the one glob that can supply the item (narrowed by declared names).
    • Manifests are read with a small line reader, not 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.
  • Extraction (rust.py _dependency_capture + galaxyscope.extract_raw_imports):
    • #[path = "x.rs"] mod m; is recorded as ./x.rs.
    • extern crate x; is recorded.
    • A self:: or super:: path inside an inline mod tests { … } is rescoped to the file, so use super::* in a test module does not draw a false edge to the parent module.
  • No other language's resolution changes.

Evidence

room4doom (real rescan, --db-only):

main (before) this branch, same 378 files this branch + #4550 merged (395 files)
import edges 293 1,890 2,111
.rs files with internal_dependency_links=0 267 / 353 48 / 353 48 / 370
avg path length / cyclic density 1.31 / 0.0 — 3.25 / 0.47
  • Expected ratio: the 2,603 use lines expand to 5,004 path tokens. 3,920 of them resolve; these are all the crate/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 35 crate::/super:: paths in docs/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).
  • Spot checks: I read the files without links and they import only std or external crates. Re-exports land on the defining file, for example use vr::ControllerState resolves to render/vr/src/actions.rs.
  • Independent oracle: tests/tools/import_graph_accuracy.py now also scores Rust use paths, #[path] and extern 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 the rust entry of tests/import_graph_accuracy_baseline.json.
  • Fixture: tests/core_engine/test_rust_module_resolution_4544.py is a 4-crate workspace written to disk, run through the real extractor and sensor. It pins the exact 20 edges. A real galaxyscope scan of the same fixture gives the identical 20.

Golden masters

  • Blessed both legs only via golden-lock.sh python tests/tools/crucible_check.py --update --yes, after the real-scan proof.
  • I discarded the first bless: under load, a CSS ReDoS timeout in one leg caused a fake defensive_programming_constructs diff. 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 26 Composition Fit (Z-Score) values. That score reads the file's graph role (PageRank / blast radius), which is normalized over the whole crucible graph.
  • The remaining diffs are repo-wide rollups that move with the new Rust edges: network macro, PageRank-ranked bottlenecks, column digests, LLM brief, and firewall.imports_unknown +3 from extern crate tokens.

Gates

  • pr_gates (full) passes. Ratchets: 6/6 pass.
    • ports needs JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 on this box, because Maven otherwise picks Java 21 and cannot build release 17.
  • dead_key_audit: allowlisted the Cargo.toml keys build and workspace, which come from a manifest on disk.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR

squid-protocol and others added 6 commits October 6, 2026 03:54
…#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
@squid-protocol squid-protocol added bug Unintended behavior or logic failure in the engine data-integrity Issues relating to RAM state or SQLite database fidelity core-engine Modifications to the central physics and parsing engine priority: high Core feature broken, but workarounds exist labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol marked this pull request as ready for review October 6, 2026 09:30
@squid-protocol
squid-protocol merged commit 1e76198 into main Oct 6, 2026
31 of 32 checks passed
@squid-protocol
squid-protocol deleted the fix/4544-rust-imports branch October 6, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unintended behavior or logic failure in the engine core-engine Modifications to the central physics and parsing engine data-integrity Issues relating to RAM state or SQLite database fidelity priority: high Core feature broken, but workarounds exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust import graph under-resolved: 2,603 use lines -> 336 edges in room4doom; 76% of .rs files show no internal links

1 participant