Skip to content

Call graph: typing and overloads — receiver typing (C++/Go/Rust/TS), Java overloads by argument type, C++ arity ranges and ctor edges, Python property reads, renamed imports (Part of #8161) - #8190

Merged
squid-protocol merged 21 commits into
mainfrom
callgraph/typing-overloads
Nov 10, 2026

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #8161. PR 4 of 4: typing and overloads. The engine now works out which object a method is called on and which overload is meant, for C++, Go, Rust, TS/JS, Java and Python.

What changes

commit change
X3 (receiver typing) In C++, Go, Rust and TS/JS, x.m() links to the method of x's class. The class comes from parameters, locals, constructions (new T, T{}, T::new(), make_unique<T>) and fields. New resolver step typed (core/receiver_types.py). The declaration and field scans stay linear, so the C++ linear-time test is unchanged.
J1 Java same-arity overloads are chosen by argument type (core/java_arg_types.py; columns calls_out_arg_types and param_types, recorded, healed and rehydrated). Also fixed: Java method names with combining marks.
P5 C++ overloads are chosen by the range of argument counts they take, counting defaults and variadics (function_data.arity_range, class_data.method_arities). An exact count wins, then a default, then a variadic.
P3 C++ constructions not written as calls (T x;, T x{..}, T x = lit;, make_unique/make_shared<T>) become a new ctor edge kind, reported separately (owner decision: kinds are labelled, never folded into call). T x(a) now counts its arguments.
Y2 A Python @property / @cached_property read anywhere is a call to its getter.
X5 A bare call through a renamed import reaches its definition, in TS/JS, Python and Rust (core/import_renames.py).
baselines, goldens Regenerated after each gain; golden masters re-blessed in both modes (new columns, rows, fan-in, PageRank).

Gates (confident precision / strict / recall; before = PR 3, #8186)

lane before after
C++ (fmt) 89.1 / 79.1 / 35.9 90.2 / 80.3 / 39.6
Go (cobra+gin) 99.5 / 96.4 / 74.8 99.6 / 96.7 / 77.8
Rust 98.3 / 91.6 / 78.0 98.3 / 92.0 / 81.5
Java (gson) 99.8 / 98.0 / 72.9 99.8 / 98.0 / 82.5
TypeScript 100 / 100 / 82.3 100 / 100 / 82.3
JavaScript 99.4 / 97.5 / 87.9 unchanged
Python 99.9 / 99.9 / 52.8 99.9 / 99.9 / 54.8
flask 99.4 / 99.4 / 41.2 99.4 / 99.4 / 43.5
C 100 / 100 / 50.6 unchanged
  • typed links are 98.7–100% precise.
  • C++ ctor edges are 95.2% precise (21 judged).
  • Java wrong links went 12 → 15. All 3 new ones are a gson test helper whose protobuf-generated argument type scip-java does not attribute; reading the source, the engine's link is correct.

Also run locally:

  • mypy, dead_key_audit --ci, ruff;
  • pr_gates --fast;
  • import_graph_accuracy --ci (27 languages);
  • DOOM-rosetta, Unicode gauntlet 950/950.

The full unit run's only failures are environmental: no pandas or tree_sitter_language_pack in the local venv, and a stale local keyword-rosetta clone. CI has all three.

Follow-ups (not in this PR)

  • C++:
    • argument types (s04 p.emit(1) still picks the wrong overload);
    • defaults on free-function prototypes in headers;
    • header-declared fields typing out-of-line .cpp methods;
    • operator and macro edge kinds.
  • Renamed re-exports (zod export { _gte as gte }) need a per-file export map.
  • J1: type-variable bounds, and arguments that are themselves calls.
  • Rehydrator: restore def_shape and owners.
  • Go: package name ≠ directory.
  • Next: PR 5 (C#, Kotlin, PHP: the LAWS Amendment 2 admission survey) builds on this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF

squid-protocol and others added 17 commits November 9, 2026 16:33
…tion or field reaches its class's method (X3, Part of #8161)

core/receiver_types.py reads, from the calling unit and its file: parameters and
locals with a written type, locals bound to a construction (T::new(), T { }, &T{},
new(T), new T(), T x;, auto x = T(), make_unique<T>()), and struct/class fields
for self.x / this.x (C++: a bare name no local declares). The resolver's typed
step then links x.m() to that class's method. Go keeps a package qualifier
(x *pkg.T resolves in that package only); Rust's Self is the caller's own type;
C++/TS/JS take a typed class only when it is in a file the caller sees.

Gate (confident precision / recall): cpp 89.1/35.9 -> 89.9/39.4; go 99.5/74.8 ->
99.6/77.8; rust 98.3/78.0 -> 98.3/81.5; ts 100/82.3 -> 100/82.3; js unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…k runs and unclosed openers (X3, Part of #8161)

0925b711c's scans were quadratic on adversarial text, which #3772's linear-time test
caught (an unterminated namespace opener shields to one word and a long blank run):
- C++: adjacent backtracking blank runs in the declaration pattern (`[ \t]*(?:<..>)?`
  then `[ \t\r\n]*`) split a long run every way; blank runs are now possessive, the
  optional template arguments own the blanks before them, and a match starts only at
  a word or `::`.
- Rust: the blanks after a `:` and around an optional `&` were the same shape.
- TypeScript: the parameter pattern's leading `^[ \t\r\n]*` (re.M) rescanned a blank
  run from every line start; the match now starts at the name and `_ts_params` checks
  the lead (`(`, `,` or a line start) by walking back once.
- Go / TS / Rust fields: each unclosed struct/class opener scanned to the end of the
  file; brace matches now come from one stack pass (`_brace_closes`).

Test: test_declaration_scans_are_linear (5 adversarial shapes x 4 languages).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…t of #8161)

Regenerated with `tests/tools/call_graph_resolution.py <lang> --regenerate`
(confident precision / recall): cpp 89.1/35.9 -> 89.9/39.4; go 99.5/74.8 ->
99.6/77.8; rust 98.3/78.0 -> 98.3/81.5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…8161)

core/java_arg_types.py: the detector records each call site's argument types
(literals, typed locals / parameters / fields with primitives and arrays, `new T(..)`,
`new T[..]`, casts of a plain operand, `xs.length`, `null`) as calls_out_arg_types and
each method's declared param_types, both read from the unit's source with literals
blanked to the same length (the engine's shield shortens 'c' and "c" alike to ""). The
resolver's _choose_overloads picks, per call site, the overload Java picks (JLS
15.12.2: strict, then loose invocation, then the most specific method), and only when
certain: every argument typed, every candidate's parameters read, no candidate only
maybe applicable. Repo classes decide subtyping by their lineage; a final JDK class
(String, the boxes) has known supertypes; a type variable's bound is unread, so it
decides nothing. A site it cannot decide keeps the `overload` row.

New function_data columns calls_out_arg_types and param_types (JSON; recorded, healed
and rehydrated). Stricter than the gaps/java-tools prototype (which cost 0.4 pp):
unknown arguments never pass.

Gate (java, gson vs scip-java): recall 72.9 -> 82.5; confident precision 99.8 -> 99.8
(6480 agree / 15 wrong, was 5729 / 12): the 3 new wrong-overload links are one test
helper, roundTrip(Gson, Gson, ProtoWithAnnotationsAndJsonNames), whose argument is a
protobuf-generated type scip-java did not attribute; by the source they are right.
Extraction cost on gson's 40 largest files: about +7%.

Tests: test_java_overload_types_8161.py; test_fcall_data round trip; the J2 guess test
now uses an argument with no readable type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
… Part of #8161)

Regenerated with `call_graph_resolution.py java --regenerate`: recall 72.9 -> 82.5,
confident precision 99.8 (wrong-overload 0 -> 3, see the J1 commit). Also a mypy
fix: the unit's own-name list no longer reuses a frozenset-typed name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…and variadics (P5, Part of #8161)

A default argument lowers the fewest arguments an overload takes and a variadic (`...`,
a top-level pack `Ts&&... xs`; `format_string<T...>` is none) has no most. The
detector records a definition's own range (function_data.arity_range) and, per class,
its member declarations' ranges (class_data.method_arities): an out-of-line
definition repeats no default, so `Printer::emit(int a, int b)` takes the range its
class declares (`void emit(int a, int b = 0);`). The resolver picks by tier: an
exact parameter count first (#3835, unchanged), else an overload that takes the count
through its defaults, else a variadic; several in the winning tier stay ambiguous.

Both columns are recorded, healed and rehydrated (test_fcall_data).

An exact count still beats a default (s04 `p.emit(1)` -> `emit(const char*)`):
ranking a default as ambiguous measured 92.6 / 35.7 on fmt (precision up, recall
down 3.7 pp, the gate fails), because fmt's defaulted overloads lose to the exact
one far more often than not; only C++ argument types can settle that case.

Gate (cpp, fmt vs libclang, confident precision / recall): 89.9 / 39.4 -> 90.0 / 39.8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
Regenerated with `call_graph_resolution.py cpp --regenerate`: confident precision /
recall 89.9 / 39.4 -> 90.0 / 39.8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…; `T x(a)` counts its arguments (P3, Part of #8161)

Owner decision: such an edge is its own kind, never folded into `call`.
core/cpp_ctor_forms.py reads, from a unit's body, `T x;`, `T x{a, b};`, `T x = lit;`
(a declaration opening a statement, no `*`/`&` declarator) and `make_unique<T>(..)` /
`make_shared<T>(..)`, with their argument counts (function_data.ctor_forms, recorded,
healed, rehydrated). The resolver links each to the class's own constructor, chosen by
count like a call, as an fcall row of kind `ctor`; a class with no constructor of its
own gets no row. Written constructions (`T x(a)`, `T(a)`, `new T(a)`) stay `call`
(contract C3); `T x(a)` now records its count at the declarator's `(` (it was read at
the type, so it was None).

arity_range now also carries the header's own parameter count when the `args` metric
misreads it (`const Allocator& alloc = Allocator()` counted 6), and the resolver uses
it: fmt's `basic_memory_buffer buf(alloc)` no longer links the move constructor.

The resolution gate reports the `ctor` kind (by_fcall_kind; labelled-kinds and
all-kinds recall count it); gated numbers stay confident `call` edges. Docs: the edge
kind table and the contract's open-question row.

Gate (cpp, fmt vs libclang): call 90.0 / 80.1 / 39.8 -> 90.2 / 80.3 / 39.6 (confident
precision / strict / recall; wrong 147 -> 142); ctor 21 judged, 95.2%; the
reference's ctor edges linked 16.5% -> 17.3%; labelled-kinds recall 10.9 -> 11.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
… of #8161)

A property read runs the getter, but only a value-position `self.p` was recorded (as a
`reference`): chains (`self.conn.batches`), conditions, subscripts and call receivers
gave no edge. The detector now records every attribute read off `self` / `cls` that is
neither called nor assigned (function_data.property_reads; recorded, healed,
rehydrated). The resolver keeps one only when it reaches, through the class or typed
step, a method decorated `@property`, `@cached_property` or `@x.getter` (a setter
sharing the name maps to its getter), as a `call` row; data attributes get no row. A
value-position read of a property is that call, no longer a `reference`; a plain
method read as a value stays a `reference`.

Gate (python, confident precision / recall): 99.9 / 52.8 -> 99.9 / 54.8; flask
import-graph lane 99.4 / 41.2 -> 99.4 / 43.5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
#8161)

Regenerated with `call_graph_resolution.py python --regenerate`: python recall 52.8 ->
54.8, flask import-graph lane 41.2 -> 43.5; confident precision unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
… imported definition (X5, Part of #8161)

core/import_renames.py reads a file's renamed imports (`import { add as plus2 }`,
`from m import f as g`, `use a::b as c` and brace groups); default and namespace
imports and module aliases are not renames of a definition. The detector records, per
unit, the bare callees that use one (function_data.calls_out_renames; recorded,
healed, rehydrated), and the resolver looks such a call up under the imported name, so
`plus2()` links to `add` through the import step instead of giving no row. A name bound
to two different imports is left alone.

Gates (all --ci pass, confident precision unchanged): typescript recall 82.3 (+1
agree), javascript 87.9, python 54.8, rust 81.5: the gate corpora rarely rename an
import. zod's 66 renamed-export misses come from re-exports (`export { _gte as gte }`
in a barrel), which need a per-file export map: a follow-up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…art of #8161)

Regenerated with `call_graph_resolution.py cpp --regenerate`: confident precision /
recall 90.0 / 39.8 -> 90.2 / 39.6 (wrong 147 -> 142).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
…ust rename pattern passes xray (Part of #8161)

- J1: the one-pass call-name index reads ASCII-led identifiers, so a method named with
  combining marks or a ZWJ (`probeनाम`, `probeक्‍ष`) lost its header and its
  param_types; the unicode gauntlet's 8 Java cells failed against their ASCII twins.
  A non-ASCII name is now searched literally (gauntlet 950/950).
- X5: the binary anomaly detector (xray) read the one-literal Rust `a as b` pattern as a
  dense string (Shannon entropy 4.9); it is built from a named identifier piece now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
`tests/tools/crucible_check.py --update --yes` (both modes). The scan output moves
because the call graph gained edges: receiver-typed links (X3), Java overloads chosen
by argument type (J1), C++ arity ranges and `ctor` edges (P5, P3), Python property
getters (Y2) and renamed imports (X5). Function fan-in / fan-out / PageRank, the
confident call pairs that join the file graph (import_edges, blast radius, network
macro, bottlenecks) and the SQLite snapshot (new function_data columns
calls_out_arg_types, param_types, arity_range, ctor_forms, property_reads,
calls_out_renames; class_data.method_arities) change accordingly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRvhoWCV984xPpQKJHfF
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit a94f75e into main Nov 10, 2026
69 checks passed
@squid-protocol
squid-protocol deleted the callgraph/typing-overloads branch November 10, 2026 00:21
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.

1 participant