Repository navigation
Conversation
|
Thanks for the pull request, @smngvlkz. 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 3 changed function(s) (3 not verified).
Formal verification. PR-changed functions: 0/3 verified (0 proven, 0 may-equivalent, 0 distinguished) · 3 not verified (2 vacuous, 1 unsupported).
Not verified on this run: \_extract\_generic (unsupported), \_js\_extra\_walk (vacuous: never exercised), \_scan\_js\_nested\_function\_declarations (vacuous: never exercised).
Graphify review — findings
Fixes JS/TS call resolution so a nested function binds only inside its own lexical scope. Nested declarations are now recorded in scope_parents and lexical_nids_by_scope, so both direct calls and indirect references (e.g. register(run)) resolve to the nearest in-scope function before the file-wide name map is consulted, the same scheme Python already uses. Nested JS/TS functions are also kept out of the file-wide label_to_nid map, so a same-named top-level, imported, or sibling-inner function no longer has its callers stolen, but any call that falls outside the recorded scope chain can no longer reach the nested function.
Worth a look
- Nested JS function becomes unreachable from callers outside the recorded scope chain —
graphify/extractors/engine.py:8725· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3253 functions depend on the 376 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1016 callers, 62 callees
Verification — 3253 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: 1678 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
40 of 454 test file(s) selected (9%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_partial_classes.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_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_js_nested_function_scope.py— impact, changed-testtests/test_languages.py— impacttests/test_multilang.py— impacttests/test_php_unparsed_casts.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.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_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— impacttests/test_typescript_module_extensions.py— impacttests/test_vue_extraction.py— impact
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 \_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 \_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)
Could not verify: Could not verify \_scan\_js\_nested\_function\_declarations.
The verifier did not have enough to check \_scan\_js\_nested\_function\_declarations, 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 244 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)
· 1 more finding(s) on lines outside this diff (see the check run).
bercedev
left a comment
There was a problem hiding this comment.
Ran the new tests (4 fail on v8, all 5 pass here) and threw a few extra shapes at it:
- sibling inner functions (
a()callingb()inside the same outer) still link - a call from an arrow callback inside the outer still resolves to the outer's inner
a - a nested function inside a class method still links from that method
caller() { return top(); }with a top-leveltopand another function's innertop: v8 bound it toother_top, this PR binds it to the top-level one
All as expected. LGTM.
|
Landed in v0.9.97, now on PyPI (pip install graphifyy==0.9.97). Nested functions stay scoped so a same-named call elsewhere binds to the top-level function. Thanks for the fix, @smngvlkz. |
What this fixes
Since #2653, a JS/TS function declared inside another function gets its own node, which is great. But it also went into the file-wide name lookup, so a call to that name from anywhere in the file could get linked to it, even from outside the function it lives in. Two ways this goes wrong:
run: both get linked to the last onehelpersteals the callers of a top-level or importedhelperSo the graph says things call functions they can't even see.
How to recreate
Before:
b()is linked to thehelperhidden insidea(). After:Same thing with two inner functions of the same name:
Before,
first()callsx_second_run. After, each calls its own.What changed
Python already handles this the right way (#3405), so I reused the same approach for JS/TS:
register(run)) looks in its own scope first, then the outer onesTop-level functions, imports and methods are looked up the same as before.
How I tested it
tests/test_js_nested_function_scope.pywith the cases above, an inner function named like an import, siblings and deeper nesting, and inner functions inside arrow components. The four that check the wrong links fail on currentv8and pass with this change, the siblings one checks those still resolvetest_ext_tagged_id_clash.py, 1 intest_skill_no_backtick_substitution.py) fail the same way onv8without this change, they need the SQL parser which my local setup doesn't haveNot in this one
a()also gets acalls lib_helperlink from the separate import pass, which doesn't know about inner functions. That's onv8too, so I left it for nowconst helper = () => {}still don't get nodes at all (TypeScript extraction emits internal edges whose endpoint nodes are absent #2143). I have that fix ready and will open it after this one, since it builds on this