Repository navigation
Make the tree-sitter adapters' language overrides actually run - #4
Merged
Merged
Conversation
Two bugs in the shared tree-sitter walk meant per-language code never ran: - `_COMMON_META` bound the base-class builder functions, so `JavaAdapter._meta_call` and `CppAdapter._meta_member`/`_meta_index` were dead code. Every Java call had an empty callee and receiver, so the UI said "Calls `the function` on `the object`", known costs never applied, and naive Java `fib` was not flagged exponential the way the Python and C++ ones are. C++ member and index access read the wrong fields (index key was the container name). - `recurse_into` dropped the `name` child with `c is not name_field`, but py-tree-sitter returns a new wrapper on every access, so the check never matched. Each definition got a NAME child of its own name, which counted as a use: no JavaScript variable could ever be reported as unused. C++ functions had the same duplicate via their declarator. The builder table now holds method names resolved on `self`, node comparison uses `!=`, and C++ callables descend into their parameter list rather than the whole declarator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UigC7feaY8NkAy9oay3GDW
They sat at the same spot as the Python lowering tests in another open PR; at the end of the file the two merge cleanly in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UigC7feaY8NkAy9oay3GDW
ethanzhoucool
marked this pull request as ready for review
November 3, 2026 17:14
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
Two bugs in the shared tree-sitter walk (
adapters/treesitter.py) meant that per-language code in the Java, C++ and JavaScript adapters silently never ran.1. Language-specific meta builders were dead code.
_COMMON_METAstored the base-class functions (TreeSitterAdapter._meta_call), andmeta_forcalled them directly. So the overrides were never used:JavaAdapter._meta_call. Java puts the callee inname, notfunction, so every Java call hadcallee == ""andreceiver == "". Visible effects in the bundled Java sample:Calls `the function` on `the object` with 1 argument.forSystem.out.println(...).KNOWN_COSTS(e.g.Collections.sortin a loop) never applied.fibin the Java sample came out as O(n), "takes part in a recursive cycle through another function". The identical Python and C++ samples are O(2^n) with a high-severity finding.CppAdapter._meta_member/_meta_index. C++ calls the objectargument. Forp->xthe IR hadobject: ""and novia_pointer. Forv[i]it hadcontainer: ""andkey: "v"(the key was the container's name).2. Definitions repeated their own name as a child.
recurse_intois meant to drop thenamefield ("emitting it again as a NAME child buries every definition under a duplicate of itself"). It compared withc is not name_field, but py-tree-sitter returns a fresh wrapper object on every access, so identity never matches. (I checked:c is nfis False andc == nfis True for the same node.) The symbol table reads that NAME child as a use. As a result, no JavaScript variable could ever be reported as "assigned but never read":const unused = 2was always counted as used by its own declaration. The bundled JS sample'sslugifyis defined and never called, and is now correctly reported. C++ functions had the same duplicate through their declarator chain.Changes
_COMMON_METAnow mapsKindto the builder's method name, andmeta_forresolves it onself, so a subclass override replaces the shared builder. Existingmeta_<kind>hooks work as before.recurse_into(base and the JS parameter filter) compares with!=.CppAdapter.recurse_intodescends only into a function's parameter list instead of the whole declarator, so the name at the bottom of the chain isn't emitted again.Diff of the four bundled web samples (
web/static/samples.js) at all three levels:Calls `println` on `System.out`,`cache.clear()`), andfibis O(2^n) with the exponential finding.slugifyis reported as unused.Testing
pyteston Python 3.13, 3.12 and 3.11: 160 passed, 4 skipped.ruff check explain_my_code testsis clean.mypyreports the same 26 errors as before.main, except the cases for languages that were already correct:test_calls_name_their_callee, across all tree-sitter languages; failed for Java;test_definitions_do_not_repeat_their_own_name_as_a_child; failed for JS, Java and C++;test_java_calls_keep_their_receiver;test_cpp_member_and_index_read_cpp_field_names;test_unused_local_is_reported_in_javascript;test_naive_recursion_is_exponential_in_java_too.Notes
This is independent of the cost-model PR (#3), and the two touch different files. #3 deliberately left Java out of its tests because of the empty callee this PR fixes.
Generated by Claude Code