Repository navigation
fix(ts): never guess a same-named function for a locally bound callee (#1355) - #3012
Open
DryadeCore wants to merge 1 commit into
Open
DryadeCore wants to merge 1 commit into
DryadeCore wants to merge 1 commit into
Conversation
…DeusData#1355) `const submitForm = useCallback(...)` inside a component is no graph node, so the TS LSP declines a later `submitForm()`. The registry then fell back to a project-wide short-name match and bound the call to any function that shares the name, in a file the caller never imports: a fabricated CALLS edge at unique_name / suffix_match confidence. The same happened for a useState setter and for a callback parameter. Python already drops such a guess for a callee that an enclosing scope binds as a parameter (callee_is_locally_bound, DeusData#1912). This extends the same flag to JS/TS/TSX/ArkTS: - The walk's lexical binding table records, per binding, whether it names no definition: a parameter, a declarator whose initializer is not a function or class, or an array-pattern element. Function-valued declarators and nested function declarations are real definitions and stay unflagged, as do imports and module-scope bindings. - cbm_finalize_lexical_usages flags every bare call whose nearest binding is such a local. It runs after the walk because let/const/var bind their whole scope (a handler may call a local declared further down). - The weak-local-binding guard's language set moves into cbm_weak_local_binding_guard_lang, so pass_calls.c and pass_parallel.c share one list. Only the plain-CALLS fall-through of a weak strategy is dropped; LSP, import and same-module matches are untouched. Tests: extraction flags for each binding shape, both directions; a pipeline test on the sequential and the parallel resolver (homonyms in a never-imported file, with an arrow-valued local, an unbound name and a destructured hook member as controls); registry rows for the shared gate. Co-Authored-By: Dammerzone <dammerzone@users.noreply.github.com> Signed-off-by: Dryade <contact@dryade.ai>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
This branch has not been deployed
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.
What does this PR do?
A bare call whose callee the calling function binds locally to a value that is not a
definition (
const submitForm = useCallback(...), auseStatesetter, a callbackparameter) was bound by short name to an unrelated function of the same name, in a
file the caller never imports. Found while indexing a large React codebase, where
handlers declared this way are the norm. This is one more shape of #1355: the caller's
own source already says the callee is not that project symbol.
Minimal repro
On main (cdfdf26):
go fixture.src.Elsewhere.submitForm unique_name. Identical withCBM_INDEX_SINGLE_THREAD=1.Root cause
const submitForm = useCallback(...)is no graph node (the open question of Arrow functions assigned to consts emitted as label:Variable with no function signal #1220 /Enhancement: index inner declarations of factory/setup callbacks — Vue Pinia setup stores, composables & React hooks (the Vue/React twin of the tracked Zustand gap) #415), so the TS LSP has nothing to resolve
submitForm()to and declines.unique_name/suffix_match, which bind the callto any project function with that spelling. Nothing on that path looks at the caller's
own scope.
CBMCall.callee_is_locally_bound(fix(python): suppress bare calls shadowed by an enclosing parameter #1912) marks abare call whose callee is a parameter of an enclosing scope, and
cbm_suppress_weak_local_binding_calldrops a weak short-name match for it. The flag wasnever set for JS/TS, and both resolvers gated the guard on Python.
What changed
internal/cbm/extract_usages.c: the lexical binding table the unified walk alreadykeeps for JS/TS (parameters,
let/const/var, with their scope and active range)records one more fact per binding,
names_no_definition: a parameter, a declaratorwhose initializer is not a function or class, or an array-pattern element. After the
walk,
cbm_finalize_lexical_usagesflags every bare call whose nearest binding is sucha local. It runs after the walk because
let/const/varbind their whole scope, so ahandler may call a local that is declared further down.
const save = () => {}, alsobehind parentheses,
as,satisfies,!) and a nested function declaration, which arereal definitions; an import; a module-scope binding; a declarator without initializer.
A scope that binds the name twice is flagged only when every active binding agrees.
src/pipeline/registry.c:cbm_weak_local_binding_guard_lang()holds the language set(Python, JS, TS, TSX, ArkTS).
pass_calls.candpass_parallel.cboth take the guard'senabledfrom it, so the two lists cannot drift.suffix_match/unique_name/field_type_hint/fuzzy. LSP, import-map andsame_modulematches are kept, and route / HTTP classification still runs.No new node kinds, no change to what is extracted as a definition: #1220 and #415 stay
with the maintainer.
Tests
tests/test_extraction.cextract_tsx_bare_call_flags_locally_bound_callee: flagged:useCallbackconst, the same declared after its caller, array-pattern element,parameter, call result behind
as. Not flagged: shorthand object-pattern name,arrow-valued const, arrow behind parentheses and
as, nested function declaration,unbound name, module-scope const, import, unbound name in a sibling function. Each
callee must be extracted exactly once.
tests/test_pipeline.cpipeline_tsx_local_binding_not_bound_to_homonym_issue1355: onetree, indexed with
CBM_INDEX_SINGLE_THREAD=1and withCBM_WORKERS=4(64 paddingfiles):
go -> Elsewhere.submitForm= 0 (useCallbackconst)go -> Elsewhere.setOpen= 0 (useStatesetter)finish -> Elsewhere.onDone= 0 (callback parameter of the enclosing hook)go -> localStep= 1callsUnbound -> submitForm= 1ListPage -> removeItem= 1tests/test_registry.c: rows forcbm_weak_local_binding_guard_lang.Results (linux arm64, gcc 13.3, base cdfdf26)
Fixture above, release build (
scripts/build.sh), 64 padding files added so that bothresolvers can be forced:
A public tree to check it against: this repository's own
graph-ui/at cdfdf26 (React +TypeScript, plus
.mjstools), indexed by main and by this branch into separate cache dirs,then every edge compared:
For none of the 159 removed edges is the target in the caller's file, and for none does the
caller's file have an IMPORTS edge to the target's file. I read 9 of them in the source;
all 9 are local bindings, for example:
ProjectsPanel -> AddProjectIndexDialog.loadProjects:ProjectsPaneldeclaresconst loadProjects = useCallback(...); the dialog has its own local arrow of that name.useSystemPoll.poll -> IndexesPanel.read:readis a parameter of the hook.NodeLabels -> GalaxyPanel.measure:const measure = useCallback(...)inNodeLabels.SpatialArchitecture -> SystemArchitecture.setEntryChoice: auseStatesetter.tools/*.mjsfunctions toadr-strings.done:doneis the parameter of anew Promise((done) => ...)executor (read in one of the scripts).Tests (ASan + UBSan,
scripts/test.sh --suites <every suite of --list-suites>):10501 passed, 25 failed, 11 skipped. All 25 failures are in theclisuite and come fromthis host: the installer refuses a group-writable build directory
(
install_dir_group_or_world_writable (mode 0775), umask 0002 here). No file of that suiteor of
src/cliis touched; I did not build main's test runner to confirm they fail theretoo. The three suites this PR touches (
extraction,registry,pipeline) are green.Reproduce-first: with only the call to
flag_js_locally_bound_calleesdisabled and thetests kept:
Not run: the default
scripts/test.shleg (its clean step and contract checks), the TSanleg, cppcheck, clang-tidy.
Limits
function Row({ onClose }),const { removeItem } = useStore()) is not a binding occurrence of the walk today, sosuch a callee is never flagged and keeps its name guess. For a hook member that guess is
often right; for a prop it is the same wrong edge as above. Not in this PR: recording
those bindings also changes which USAGE edges are blocked.
const restore = await setup(); await restore()no longer binds a project functionrestore, even whensetuphappens to return that function. The name is the onlyevidence there, and the edge was a guess.
for (const fn of fns) fn()) and renamed object-pattern values arebound but not flagged.
const x = useCallback(...)still have no node, so their owncallers and callees stay invisible (Arrow functions assigned to consts emitted as label:Variable with no function signal #1220, Enhancement: index inner declarations of factory/setup callbacks — Vue Pinia setup stores, composables & React hooks (the Vue/React twin of the tracked Zustand gap) #415). This PR removes the wrong edge; it does
not add the right one.
Checklist
git commit -s)make -f Makefile.cbm test) -- see results above for what was runmake -f Makefile.cbm lint-ci) -- clang-format 20.1.8: no drift on thechanged hunks; cppcheck and clang-tidy not run
Refs #1355
Written by an AI coding agent (Claude Code) operating this account on behalf of its owner, who authorised this submission and is accountable for it.
🤖 Generated with Claude Code