Repository navigation
Conversation
…d closures (Graphify-Labs#5217) The Graphify-Labs#3124 branch tracks the body of a closure passed in a call statement under the file node, and it fires for call statements nested inside other functions too. walk_calls then starts at that body, so the Graphify-Labs#2241/Graphify-Labs#2822 folds that carry enclosing params and block bindings down never reach it. Graphify-Labs#4448 registered only the closure's own params/vars, so a name captured from an enclosing function (`function (item) { confirm({ action: function () { del(item) } }) }`) read as free and became an indirect_call to any same-named function in the corpus. Add _js_enclosing_bound_names, which collects enclosing function params and vars, block let/const, for-in/of and catch bindings up to the program, and union it into closure_locals_by_body for that branch. Attribution is unchanged; module-level call statements have no enclosing scopes, so their behaviour is unchanged too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @Sidreyas. 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.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: \_js\_extra\_walk (vacuous: never exercised).
Graphify review — findings
Fixes JS indirect-call resolution for closures passed in call statements nested inside another function: the closure body is now tracked on its own with the bindings of every enclosing function and block (params, vars, let/const, loop and catch bindings). A captured name like value in function (item) { confirm({ action: function () { del(item) } }) } no longer reads as a free reference and resolves to a same-named callable elsewhere in the corpus (#5217). _js_enclosing_bound_names walks the ancestor chain to program level and mirrors what walk_calls folds into extra_locals on the way down, and the for_in_statement case treats the loop's left side as bound, including undeclared assignment targets.
Worth a look
- Undeclared for-in/of assignment targets are treated as enclosing locals —
graphify/extractors/engine.py:3297· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 4212 functions depend on the 469 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_js_extra_walk()— 2 callers, 16 callees
Verification — 4212 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: 2455 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
52 of 575 test file(s) selected (9%) via static blast radius.
tests/test_4992_ts_import_types.py— impacttests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_alias_member_resolution.py— impacttests/test_cpp_conditional_initializers.py— impacttests/test_cpp_inherited_member_resolution.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_extension_calls.py— impacttests/test_csharp_extension_metadata.py— impacttests/test_csharp_extension_resolution.py— impacttests/test_csharp_partial_classes.py— impacttests/test_dart.py— impacttests/test_dart_typedef.py— impacttests/test_dotnet.py— impacttests/test_ejs_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_call_file_scope_callback_shadow.py— impact, changed-testtests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_java_member_calls.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/test_languages.py— impacttests/test_multilang.py— impacttests/test_php_unparsed_casts.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_python_subscript_type_refs.py— impacttests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_context_bounds.py— impacttests/test_scala_extension_methods.py— impacttests/test_scala_given_instances.py— impacttests/test_scala_self_type.py— impacttests/test_scala_top_level_binding.py— impacttests/test_scala_type_definition.py— impacttests/test_svelte_extraction.py— impacttests/test_swift_computed_properties.py— impacttests/test_swift_protocol_requirements.py— impacttests/test_trailing_newline_not_a_syntax_error.py— impacttests/test_ts_new_expression_calls.py— impact- … and 2 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
Could not verify: Could not verify \_js\_extra\_walk.
The verifier did not have enough to check \_js\_extra\_walk, 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 264 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
· 1 more finding(s) on lines outside this diff (see the check run).
What does this PR do?
Fixes #5217. A name that a nested JS closure captures from an enclosing function (or enclosing block) was read as a free name and became an
indirect_callto any same-named function in the corpus.Cause. The #3124 branch in
_js_extra_walktracks the body of a closure passed in a call statement, under the file node. It fires for nested call statements as well as module-level ones ($ngConfirm({... action: function () {...}})andsetTimeout(function () {...})in the issue). Once a body is tracked,walk_callsstarts at that body instead of reaching it from the enclosing function. So the #2241 / #2822 folds that carry enclosing params and block bindings down never run for it. #4448 registered the closure's own params andvars for that walk (closure_locals_by_body). Bindings from the enclosing scopes were still missing. Case A in the issue works becausesave(value)has no closure argument, so its body is never tracked on its own.Fix. A new helper,
_js_enclosing_bound_names(closure, source), walks the ancestors from the closure up toprogramand collects whatwalk_callswould have folded on the way down:vars (_js_local_bound_names)statement_block/for_statement'slet/const(_js_direct_lexical_names)for…in/ofloop bindingscatch (e)bindingsThe #3124 branch unions this set into
closure_locals_by_bodywith the closure's own bindings. Nothing else changes. Edge attribution stays the same: calls are still credited to the file node, as before. For a module-level call statement the ancestor chain has no scopes, so the set is empty and behaviour is unchanged.Issue reproduction (
app/controller.js+web/helpers.tsfrom the issue), edges intohelpers.ts:contains(3)indirect_call controller.js → item()L9indirect_call controller.js → entry()L15Type of change
Verification & Invariants
Invariant: a name bound in any scope that lexically encloses a reference is never resolved as a corpus-wide by-name callback reference, whichever body the reference ends up walked from. Names that are not bound in an enclosing scope still resolve as before. Two guard tests check this: an unbound name in a nested callback, and a param of a sibling function that does not enclose the callback. Both resolve to
value()before and after this change.New tests in
tests/test_indirect_call_file_scope_callback_shadow.py(next to the #4448 ones):test_param_captured_from_an_enclosing_function_is_not_a_reference(issue case B)test_arrow_param_captured_two_levels_down_is_not_a_reference(issue case C)test_enclosing_const_is_not_a_referencetest_enclosing_loop_binding_is_not_a_referencetest_enclosing_catch_binding_is_not_a_referencetest_unbound_name_in_a_nested_callback_still_resolves(guard)test_a_binding_in_a_sibling_scope_does_not_shadow_a_nested_callback(guard)Limitations (unchanged, out of scope):
$scope.remove). This PR only removes the false references. It does not change attribution.function item() {}nested in an outer function) are not added to the shadow set. They are real nodes, and the lexical-scope lookup in_emit_indirect_by_namealready resolves them first.How was this tested?
Windows 11, CPython 3.11,
uv sync --all-extras.The 17 full-suite failures fail identically with the
engine.pychange stashed. They are environment-specific to this machine and unrelated to extraction:test_code_only_update_all_hosts[devin|aider],test_hooks::test_worktree_guard_survives_exported_cdpath)getcwd/ relative-root path tests (test_resolve_memoization,test_source_key_memoization,test_language_override_lifecycle)test_skillgenaudits, which compare againstv8history that is missing from my shallow cloneGraphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (n/a, no fragments touched)🤖 Generated with Claude Code