Repository navigation
Conversation
…-Labs#5240) In a Cargo workspace, every crate's `use crate::…::X` targets the same bare stub id. The rewire scopes each stub to its own file's crate (Graphify-Labs#4699), but it kept one answer per id and applied it to every edge. One file's stub decided where every crate's import landed. On ripgrep, the `Error` in globset's `use crate::{Candidate, Error, ErrorKind, new_regex}` reached the regex crate's `Error`. Resolve per file instead. Each importing file gets its own `use` stub, and each Rust edge uses its own file's answer. A file whose crate has no unique match leaves its import unbound rather than borrowing another crate's answer. Fixes Graphify-Labs#5240 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the pull request, @Max17190. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (1 sampled, not proven, 1 not verified).
Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: extract (vacuous: never exercised).
Graphify review — findings
Fixes Rust use crate::…::X imports landing in the wrong crate when two crates each import their own X. Previously every such import shared one bare stub id, so one crate's resolution could decide where another crate's edge pointed. _rewire_unique_stub_nodes now records each stub's answer per importing file and has Rust edges take their own file's result. If two stubs in one file disagree, or the file's crate has no match, that file's edges stay unbound instead of borrowing another crate's target. extract also lends one use stub per importing file rather than one per name, and skips files that already have a stub. New tests cover two crates with the same name, use-only crates, a nested mod tests import, and a crate with no local match.
No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 4791 functions depend on the 433 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
extract()— 1257 callers, 78 callees (high)_rebuild_code()— 281 callers, 76 callees (high)build_from_json()— 319 callers, 25 callees (high)build_merge()— 123 callers, 18 callees (high)dispatch_command()— 8 callers, 154 callees (high)extract_js()— 101 callers, 8 callees (high)build()— 92 callers, 6 callees (high)main()— 126 callers, 3 callees (high)- …and 2 more
Verification — 4791 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 4077 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
334 of 581 test file(s) selected (57%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_4978_reconcile_cost.py— impacttests/test_4992_ts_import_types.py— impacttests/test_affected_overrides.py— impacttests/test_alias_folding.py— impacttests/test_analyze.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/test_build_merge_ghost_fold_4955.py— impacttests/test_build_merge_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_case_only_decl_ids_4904.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_chunking.py— impacttests/test_cjs_module_extension.py— impacttests/test_cli_export.py— impacttests/test_cluster.py— impacttests/test_cobol_extractor.py— impacttests/test_confidence.py— impacttests/test_confidence_score_output.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_alias_member_resolution.py— impacttests/test_cpp_anonymous_namespace_receivers.py— impacttests/test_cpp_conditional_initializers.py— impacttests/test_cpp_forward_declarations.py— impacttests/test_cpp_forward_receiver_completion.py— impacttests/test_cpp_inherited_member_resolution.py— impacttests/test_cpp_local_callable_shadowing.py— impacttests/test_cpp_member_call_by_receiver_type.py— impacttests/test_cpp_member_declaration_identity.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_receiver_chains.py— impacttests/test_cpp_receiver_parameters.py— impacttests/test_cpp_split_header_owner.py— impacttests/test_cpp_template_members.py— impacttests/test_cpp_template_type_params.py— impacttests/test_cpp_type_alias.py— impacttests/test_cpp_underscore_ids.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impact- … and 284 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in \_rewire\_unique\_stub\_nodes (not a proof).
The verifier ran both versions of \_rewire\_unique\_stub\_nodes on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify extract.
The verifier did not have enough to check extract, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
Fixes #5240
Why
In a Cargo workspace,
use crate::api::ApiErrorin one crate can land on another crate'sApiErroras an EXTRACTED edge. The graph then states a dependency that cannot exist. On ripgrep, 20use crate::imports point at the wrong crate. For example, theErrorin globset'suse crate::{Candidate, Error, ErrorKind, new_regex}reaches the regex crate'sError.Summary
Every crate's
use crate::…::Xtargets the same bare stub id._rewire_unique_stub_nodesscopes each stub to its own file's crate (#4699), but it keeps one answer per id and applies it to every edge. Whichever file left the stub decides for all crates. The issue points at the nestedmod tests, but a top-levelusetriggers it too._use_stubsgives each importing file its own stub instead of one per name, unless the file already left a stub for that name.This keeps one invariant. A Rust
use crate::import resolves to a definition in the importing file's own crate, or stays unbound.The change runs after per-file extraction, so cached AST results stay valid and the cache schema doesn't change.
Limitations:
usethat names another crate, likeuse grep_regex::RegexMatcher, is out of scope. The extractor records the imported name only forcrate::paths, so these edges get no stub of their own and keep the per-id answer, unchanged from v8. Some still land in the wrong crate. In ripgrep, grep-printer'suse grep_regex::RegexMatcherreaches grep-searcher's testRegexMatcher. Fixing that means recording the name in the extractor, which changes cached extraction output, so I left it for a follow-up.Test plan
End to end with
graphify update .:On the issue's fixture,
crates_core_src_client_callsnow importscrates_core_src_api_mod_apierror. On v8 it importscrates_server_src_error_apierror.The import stays correct on a warm-cache rebuild, in a checkout copied to a new folder, and through a symlinked path.
After touching each of the fixture's four files, an incremental update matches a fresh full build. On v8 all four differ.
ripgrep @ 178cc02: 20 wrong-crate imports now land in their own crate and 13 unresolved imports now resolve.
axum @ 2449f16: 10 wrong-crate imports and 7 unresolved imports are fixed. axum-extra's
Multipartimport is now unbound because that crate defines twoMultiparttypes. On v8 it pointed at axum's.One other change shows up in both repos. Where a test module imports its own file's item, like
use super::file_name, that file'scontainsedge to the item becomesimports_from. v8 already does this in a single-crate project, and now it also happens when the import resolves in a workspace.I checked a sample of the changed edges against the source of both repos.
Regression tests fail on v8 and pass with the fix
No generated skill files changed
Extraction stays deterministic, and incremental updates match a full build
No shell or Python interpolation, secrets, or local graph data
AI help disclosed in the commit trailer