Repository navigation
fix(js): resolve ns.fn() calls through namespace imports (#4619) - #4636
Deepjyoti-Sarmah wants to merge 2 commits into
Conversation
|
Thanks for the pull request, @Deepjyoti-Sarmah. 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.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 5 changed function(s) (2 sampled, not proven, 3 not verified).
Formal verification. PR-changed functions: 2/5 verified (0 proven, 2 may-equivalent, 0 distinguished) · 3 not verified (3 unsupported).
Not verified on this run: \_extract\_generic (unsupported), \_apply\_symbol\_resolution\_facts (unsupported), \_collect\_js\_symbol\_resolution\_facts (unsupported).
Graphify review — findings
Fixes ns.fn() on TS/JS namespace imports so the call resolves to the imported module's export instead of a same-named function in the calling file. The extractor records each relative import's binding, defers the call when the receiver is an import * as ns binding rather than a local, and stamps the raw call with its module. A new cross-file pass then turns those calls into ns.fn use facts that link only when exactly one export matches, including through export * as ns barrels. The local-call deferral keys on * bindings alone, so barrel-reexported namespaces aren't protected from same-file shadowing, and an import specifier with a non-identifier name maps the alias to itself.
Worth a look
- Local-call defer only covers
*bindings, not named re-exported namespaces —graphify/extractors/engine.py:9464· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3868 functions depend on the 897 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 988 callers, 59 callees - worse:
_extract_generic()— 20 callers, 47 callees - worse:
_collect_js_symbol_resolution_facts()— 3 callers, 28 callees - worse:
_resolve_js_import_target()— 12 callers, 3 callees
Verification — 3868 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: 3623 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
207 of 436 test file(s) selected (47%) via static blast radius.
tests/test_affected_overrides.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.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_template_type_params.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_delegate_declarations.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_foreach_loop_variable.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_underscore_collisions.py— impacttests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impact- … and 157 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.
Docs that may be stale (advisory)
graphify/extractors/MIGRATION.md§ Helper classification (lines 53-66): references changed symbols_name
Formal verification
No difference found (not proven): No behavior difference found in extract (not a proof).
The verifier ran both versions of extract 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\_generic.
The verifier did not have enough to check \_extract\_generic, 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: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set
Could not verify: Could not verify \_apply\_symbol\_resolution\_facts.
The verifier did not have enough to check \_apply\_symbol\_resolution\_facts, 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: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set
No difference found (not proven): No behavior difference found in \_augment\_symbol\_resolution\_edges (not a proof).
The verifier ran both versions of \_augment\_symbol\_resolution\_edges 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 \_collect\_js\_symbol\_resolution\_facts.
The verifier did not have enough to check \_collect\_js\_symbol\_resolution\_facts, 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: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set
· 4 more finding(s) on lines outside this diff (see the check run).
`import * as ns from './m'; ns.fn()` gives no calls edge, and when the caller's file has its own `fn`, the call binds to that one instead. Covers caller shapes, barrels, renamed re-exports, shadowing, external packages and unexported names. Undecided shapes are xfail(strict=False).
The extractor records which import binds each receiver. For
`import * as ns`, it skips the same-file name lookup and stamps the call
with the module. The symbol-resolution pass turns that into a use fact and
resolves `fn` against the module's exports only, through re-export chains,
`export { a as b }` and `export * as ns`. Shadowed receivers, type-only
imports and external packages make no edge.
JS/TS skip the AST cache, so no schema bump.
b75d70b to
c7be31c
Compare
What does this PR do?
Fixes #4619. A call through a namespace import made no
callsedge:It failed in both call paths:
resolution.py) never recordedimport * as ops, and kept only bare-identifier callees, soops.submitwas dropped. fix(js): resolve calls inside exported functions, incl. aliased imports (#3346) #3517 fixed aliased named imports here and left namespace imports for later.submitup by bare name in the caller's own file. When that file has its ownsubmit, the call bound to it, so the edge pointed at the wrong function. Otherwise the call was parked, and the cross-file loop skips every member call.The engine now knows which import binds each receiver. The resolution pass resolves
fnagainst the module's real exports:The lookup uses the export table that named imports already use (
exported_candidates), so it handles renames the same way. Unlikeresolve_exported_origin, it doesn't fall back to "a symbol with that name exists in the file", sons.privateFn()makes no edge.Before (the issue's repro, v8):
After:
I chose this after writing the tests first and running four candidates against them:
.tsx,.mjs(T2)export { a as b }:x.b()edge,x.a()noneimport type(T4)B rebuilt the export table from graph labels. That lost the renamed name and treated every
containschild as an export.Type of change
Verification & Invariants
A call
ns.fn()throughimport * as ns from './m'has acallsedge to the functionmexports asfn, and to nothing else.Merge Danger
Door: two-way. No id changes and no schema bump: JS/TS files skip the per-file AST cache (
_JS_CACHE_BYPASS_SUFFIXES), so the next extract gives the new edges, and a revert gives v8 output again.Blast Radius: small. Only JS/TS graphs change, and only around namespace imports. On a 2876-file TypeScript project, 12 edges were added and 7 removed out of 15567, and I checked each against the source:
ops.add()inside a class methodadd(), which v8 bound to the class's own.add().ops.list()andops.wakeNow(), now point atservice/ops.ts. 3 more are calls insideit(...)callbacks, through anexport *barrel.Extraction took 37.7 s, against 38.6 s on v8 (median of 3).
Limitations
ns.fn()statement, outside any function, still makes no edge, the same as a bare call.test_ts_import_require.pypins the edges of that case.ops.a.b()andconst f = ops.submit; f()still make no edge.new ops.K()andconst { submit } = ops; submit()now do. All four arexfail(strict=False), because their wanted behaviour isn't decided._resolve_js_module_path).tsconfigpath aliases and Vue/Svelte callers are untested."*"import fact goes into the shared alias table."*"is never an export name, so a bareops()resolves to nothing.How was this tested?
New tests in
tests/test_js_exported_fn_call_resolution.py, next to the #3346 tests. Each one runsextract()on a small project and asserts(caller, callee, callee file)edges. None of them calls a private helper.dispatch -> helper.js), class method, nested function,.tsx,.mjsexport *,export { x } from,export * as nsbarrelsreact,import typenew, destructureimports_fromedgesOn v8 the tests that pass do so because v8 makes no namespace edges at all. They guard against binding by name.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)