Skip to content

fix(cpp): an overload chosen by arguments that call it again no longer overflows the stack - #2999

Closed
JosefAschauer wants to merge 1 commit into
colbymchenry:mainfrom
JosefAschauer:fix/cpp-overload-argument-reentry
Closed

JosefAschauer wants to merge 1 commit into
colbymchenry:mainfrom
JosefAschauer:fix/cpp-overload-argument-reentry

Conversation

@JosefAschauer

Copy link
Copy Markdown
Contributor

Problem

On current main, codegraph index of a 5.5k-file repository fails in "Resolving refs" with RangeError: Maximum call stack size exceeded, and the whole index run is lost (the index is left truncated). v1.6.2 indexes the same repository fine.

The stack cycles through the C++ overload choice added with argument-type fitting (a6ceb04 / 4a591ae):

cppExpressionType → cppMemberObject → cppExpressionType → cppArgumentType
  → cppArgumentTypeChoice → cppOverloadFor → cppScopeMethod
  → cppImplicitThisMethod → cppExpressionType → …

The trigger is darts-clone's darts.h:

extras(extras(id).prev()).set_next(extras(id).next());

on a class with const extra_type &extras(id_type) const and extra_type &extras(id_type). Typing the argument extras(id).prev() types extras(id). Its overload is chosen by the arguments of the call the reference is at, which is the outer call (cppCallArguments(ref, …)), so the same arguments are typed again. cppArgumentType restarts cppExpressionType's depth at 0 on each lap, so the existing depth bound never trips.

Fix

cppArgumentTypeChoice keeps the calls whose arguments it is typing (file:line:column:name). A choice that comes back to the same call takes the first tied overload. That is the answer it already gives when no argument's type is known. try/finally clears the entry.

Validation

  • New __tests__/cpp-overload-argument-reentry.test.ts: a 20-line class with the same shape. On main it fails with the RangeError; with the fix it indexes, and unlink links extras, set_next and set_prev.
  • npx tsc --noEmit: clean.
  • Full suite on Linux: 8761 passed, 4 failed. The failures are environmental and also fail on main:
    • bundle-launcher ×2: no zip binary.
    • cli-sync ×2: the host runs Node 26, which prints the unsupported-Node banner.
  • The 5.5k-file repository that failed now indexes to completion.
  • Independent review (Grok): SHIP. Its notes: the guard is at the right layer, and no non-recursive path changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_018hJjBUPFiLSFBssshFwHzq

…r overflows the stack

cppArgumentTypeChoice types a call's arguments to pick among tied
overloads. In `extras(extras(id).prev())` on a class with a const and a
non-const `extras(id)`, typing the argument types `extras(id)`, whose
overload is chosen by the arguments of the call the reference is at - the
outer one - and cppArgumentType restarts cppExpressionType's depth at 0 on
each lap. The recursion never ended and the whole index run failed with
"Maximum call stack size exceeded" (darts-clone's darts.h reproduces it).
A choice that comes back to the same call now takes the first overload,
as one whose argument types are unknown does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJjBUPFiLSFBssshFwHzq
colbymchenry pushed a commit that referenced this pull request Oct 30, 2026
…r overflows the stack

On main, indexing darts-clone failed in "Resolving refs" with "Maximum call
stack size exceeded", and the whole run was lost. darts.h writes
`extras(extras(id).prev()).set_next(extras(id).next())` on a class with a
const and a non-const `extras(id)`. Choosing between them types the
arguments; typing `extras(id).prev()` types `extras(id)`, whose overload is
chosen by the arguments of the call the reference is at, the outer one, so
the same arguments are typed again. cppArgumentType restarts
cppExpressionType's depth at 0 on each lap, so the depth bound never trips.

cppArgumentTypeChoice now keeps the calls whose arguments it is typing
(`file:line:column:name`), and a choice that comes back to the same call
takes the first tied overload, the answer it already gives when no
argument's type is known. A try/finally clears the entry.

Validation on main 5526e33 (Windows 11):
- Red/green: the new test fails with main's name-matcher.ts (RangeError:
  Maximum call stack size exceeded) and passes with the fix.
- A/B against main: darts-clone fails on main and indexes with the fix,
  503 more linked sites (897 edges against the 394 the failed run left),
  with `reserve_id` and `expand_units` reaching `extras`, `prev`, `next`,
  `set_prev` and `set_next`. leveldb, fmt, googletest and nlohmann/json are
  byte-identical, as are the express and flask controls.
- Index time unchanged: median of 3 interleaved runs on nlohmann/json,
  15.9 s on main and 16.0 s with the fix.

Original PR #2999 by @JosefAschauer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@colbymchenry

Copy link
Copy Markdown
Owner

Thanks for tracking down this crash and for the minimal reproduction, @JosefAschauer! It landed in #3078 with you as the author, and your guard and test are unchanged. On our A/B, darts-clone now indexes fully instead of failing, with 503 more linked call sites, while leveldb, fmt, googletest and nlohmann/json come out identical. We only moved the changelog entry next to the other C++ entries and named darts-clone in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants