Repository navigation
calls_out: calls inside a nested named function belong to that function only (C8, #3642) - #3671
Merged
Merged
Conversation
…t's (C8, #3642) The detector scanned each unit's whole block for calls, so every call inside a nested named unit the slicer also emitted was listed on the enclosing unit too (#3360's C5 fix dropped only the nested header). Each C-style/ruby call site's offset is now kept per slice, and _drop_nested_unit_calls blanks every named unit nested inside a unit's span before keeping a callee; qualifiers are rebuilt from the surviving sites. Synthetic buckets are not named units, so anonymous bodies' calls stay with the enclosing unit (C8's second bullet). Golden masters not yet re-blessed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Contributor
…3642) _apply_literal_shield changes lengths (a comment becomes ''), so call offsets taken on the shielded block did not line up with the nested units' spans and the first cut dropped the wrong calls (python recall 99.2 -> 98.2 on the crucible). A unit with named units nested inside it is now rescanned with them blanked out of its original block, newlines kept, through the same shield and calls_out pattern. Regenerates the call_graph_accuracy baseline and merges the shapes into graph_comparison_ledger.json: python precision 96.3 -> 99.6, javascript 87.6 -> 97.3, typescript 94.0 -> 99.6, csharp 93.9 -> 99.2, java 99.1 -> 100, rust 87.4 -> 89.8. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Four values move, all idiom-wrapper call-site counts, which are summed over functions' calls_out_to: a call inside a unit the slicer nests in another was counted once per enclosing unit. cpython ceval.c debug_prints 52 -> 13 (the C slicer nests 29-34 units inside three over-long preprocessor-spanning units), gnucobol numeric.c memory_alloc 9 -> 7, redis printf.lua printf 192 -> 153. test_calls_out_keywords_3359's typescript case wrote go() inside a named arrow (const f = async () => ...), which C8 gives to f; the case now uses an anonymous callback so it still tests that async( is not a call. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
graph_comparison_ledger.json conflicted with main's auto-update (#3669): took main's side and re-merged this branch's shapes with call_graph_accuracy.py --regenerate --ledger (baseline unchanged). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Fixes the ruff ARG001 and mypy union-attr findings the rescan rewrite added. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
The same four idiom-wrapper call-site counts the zero-dependency fixture moved (cpython ceval.c debug_prints 52 -> 13, gnucobol numeric.c memory_alloc 9 -> 7, redis printf.lua printf 192 -> 153); nothing else. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3642 (part of #3641). Contract C8 (
docs/calls_out_rule_contract.md) says a call inside a nested named function belongs to that inner function only. A call inside an anonymous one (lambda, arrow callback, closure) stays with the enclosing named function.The bug: the engine scanned each unit's whole text block for calls. So every call inside a nested unit the slicer also emits was listed on the enclosing unit too. #3360's C5 fix removed only the nested unit's header (
def inner(), not its body.The fix (
gitgalaxy/core/detector.py):_calculate_block_metricsqueues each unit it scanned with the C-style/rubycalls_outfamily (the qualified patterns)._function_slicecalls_drop_nested_unit_callsfor every queued unit that has named units strictly inside its[start_idx, end_idx)span. It rescans the unit's original block with those spans blanked out (newlines kept), using the same literal shield andcalls_outpattern.calls_out_qualifiersis rebuilt from the rescan._apply_literal_shieldchanges lengths (a comment becomes''). Offsets taken on the shielded text don't line up with source spans, and the first cut of this PR dropped the wrong calls because of that.Anonymous_Block,__global_context__, …) are not named units, so their bodies are never blanked out of the unit around them.Type of change
gitgalaxy/core/detector.py)Measured:
call_graph_accuracy.pyon language-crucible v1.5.0The
fp:inner-named-*shapes from the issue fall like this:function_definitionfunction_itemlocal_function_statementmethod_declarationmethod_definitionarrow_functionfunction_declarationfunction_expressionThe remainder are cases where the engine and tree-sitter nest units differently.
Recall cost: 7 true positives (JS 3, TS 3, Rust 1). All are
fn:engine-attributes-to-another-function: the engine emits a nested unit that tree-sitter treats as anonymous, so the call now sits on the engine's inner unit, not the function tree-sitter expects. These are leads for the ledger, not verified verdicts.tests/call_graph_accuracy_baseline.jsonis regenerated.docs/self_scan/graph_comparison_ledger.jsonhas the new shapes merged in with--ledger. Some shapes now readstill_reproduces: false, including validated ones. No verdict was hand-edited.Golden masters
Both fixtures were re-blessed with
crucible_check.py --update --yes(--mode zero, then--mode full). Each moves the same 4 values, all idiom-wrapper call-site counts. Those counts sum over each function'scalls_out_to, so a call inside nested units was counted once per enclosing unit:ceval.cdebug_printswrapped sites 52 → 13. The C slicer nests 29–34 units inside three over-long units that span preprocessor blocks; before this PR each of those also carried the inner units' calls.numeric.cmemory_alloc(cob_gmp_free) 9 → 7.printf.luadebug_prints(printf) 192 → 153.The session's network policy blocks
openaipublic.blob.core.windows.net, so the full-precision run loaded tiktoken'scl100k_basefrom a local cache. That file was rebuilt from thejs-tiktokennpm package; its SHA-256 matches tiktoken's expected hash, which tiktoken re-checks on load.Test changes
tests/extraction/languages/test_calls_out_nested_body_3642.py:test_calls_out_nested_decl_3360.py::test_default_argument_call_on_a_nested_header_is_still_a_call:def inner(x=make())now putsmakeoninner, which matches the tree-sitter side ofcall_graph_accuracy.py. Needs a decision: Python evaluates that default when the outer function runs, so if C8 should carve out parameter lists, that's a small follow-up.test_calls_out_keywords_3359.pytypescript case:go()sat insideconst f = async () => …, a named arrow that C8 gives tof. It's now an anonymousp.then(async () => …)callback, so the case still checks thatasync (is not a call.Verification
main is merged in (#3669's ledger auto-update conflicted: took main's side and re-merged this branch's shapes).
🤖 Generated with Claude Code
https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr