Skip to content

Call resolver: link a constructor call to the class's constructor method - #3690

Merged
squid-protocol merged 2 commits into
mainfrom
claude/resolver-constructors
Sep 25, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
claude/resolver-constructors

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

A Level 2 (call-graph resolution, epic #3265) improvement found by breaking down where the resolver loses pyan3's edges.

Problem.

  • A constructor call Foo(...) names the class (contract C3), and the resolver linked it to the class definition.
  • The function graph only follows function→function edges (dst_kind == "function"), so no function ever reached Foo.__init__.
  • pyan draws that edge; it was 341 of pyan's edges on language-crucible's Python repos.

Fix (gitgalaxy/core/call_resolver.py, _constructor_of): when a call resolves to a class that defines its own constructor, the row points at that constructor method:

language(s) constructor
python __init__ / __new__
js, ts, kotlin constructor
php __construct
ruby initialize
swift init
java, c#, c++, dart, apex, objective-c the method named after the class
  • The constructor must be in the class's own file, or beside it with the same stem (C++ foo.h class, Foo::Foo in foo.cpp).
  • Owner keys are bare class names, so a constructor anywhere else could belong to a different class of the same name, and is never taken.
    • This was caught during the golden-master review. An earlier cut linked fastapi's tests/test_read_with_orm_mode.py Person (no __init__) to the unrelated Person.__init__ in tests/test_jsonable_encoder.py. There's a regression test for it.
  • A class without its own constructor (dataclass, pydantic model, inherited __init__) keeps the class as its target, as before.
  • The fcall_data row still names the class: record_keeper.py fills dst_class_id from the new dst_class_path/dst_class_name site keys, alongside dst_func_id for the constructor.

Type of change

  • Bug fix
  • Parsing or engine logic (call_resolver.py, record_keeper.py)

Measured: call_graph_resolution.py python (pyan3 reference, language-crucible)

metric before both #3689 alone (merged) this PR on top of #3689
confident precision 98.7% (1,277 judged) 99.4% (1,567) 99.3% (1,687)
edge recall 36.1% 44.6% 48.0%
resolution recall 71.8% 90.2% 90.2%

Measured on its own against the pre-#3689 main, this PR took edge recall from 36.1% to 39.3% at 98.8% precision.

  • The gain is smaller than the 341 edges suggested, because many Python classes don't define an __init__ of their own.
  • Resolution recall doesn't move by construction: it counts only pyan edges whose callee name the engine extracted. pyan names these edges __init__ while the engine names the class, so the metric can't see them. Making the metric credit a class name for an __init__ edge would be a separate truth-side change.

tests/call_graph_resolution_baseline.json is regenerated on the merged head.

Golden masters

Re-blessed with crucible_check.py --mode both --update --yes on the merged head: 4 differences per fixture on top of main (network_macro avg path length / modularity / assortativity at the 4th decimal, and the undocumented_critical_path forensic top list).

The branch's own change, before the merge, was 7 differences:

  • cpp/godot/rendering_server_default.cpp direct downstream and Popularity Rank 1 → 2, plus its Composition Fit z-score: a constructor defined beside its header now draws the file edge to the .cpp. That part merged cleanly into main's fixture.
  • The same network macros and forensic top list.

Tests

  • tests/core_engine/test_call_resolver.py: Python __init__; a class with no constructor stays a class; TypeScript constructor; Java class-named constructor; C++ out-of-class constructor beside its header; a constructor calling its own class is not an edge; a same-named class elsewhere doesn't lend its constructor.
  • tests/tools_recorders/test_fcall_data.py: the recorded row has both dst_func_id (the constructor) and dst_class_id (the class).

Verification (merged head f58bc0fa)

$ pytest tests/                                               -- 11412 passed, 337 skipped, 0 failed
$ PATH=.venv/bin:$PATH python tests/tools/audit_check.py      -- all clear (ruff, mypy, dead-key, ast-accuracy)
$ python tests/tools/call_graph_resolution.py python --regenerate
$ python tests/tools/crucible_check.py --mode both --update --yes   -- 4 differences each, reviewed above

Main was merged in (#3689 conflicted on the shared test file, the resolution baseline and the golden masters). Both test sections were kept, and the generated files were regenerated rather than hand-merged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr

A call that resolved to a class (`Foo(...)`, contract C3) stayed a class
target, which the function graph never sees, so no function reached
`Foo.__init__`. It now links the class's own constructor -- __init__ /
__new__ (python), constructor (js/ts/kotlin), __construct (php), initialize
(ruby), init (swift), or the class-named method (java, c#, c++, dart, apex,
objective-c) -- found in the class's own file or beside it with the same
stem (a C++ foo.h class, Foo::Foo in foo.cpp). Owner keys are bare class
names, so a constructor anywhere else is never taken. The fcall_data row
keeps the class too (dst_class_id). A class without its own constructor
keeps the class as the target.

call_graph_resolution.py python (pyan3): confident precision 98.7 -> 98.8
(1277 -> 1391 judged), recall 36.1 -> 39.3. Resolution recall only counts
pyan edges whose callee name the engine extracted, and pyan names these
`__init__` where the engine names the class, so it does not see them.

Golden masters (both): godot rendering_server_default.cpp gains a
downstream file (a constructor defined beside its header), plus the
network macros and one forensic top list it moves.

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

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…tructors

Kept both test sections in test_call_resolver.py; took main's side for the
resolution baseline and golden masters, then regenerated them with both
changes: call_graph_resolution.py python -> confident precision 99.3%
(1687 judged), recall 48.0%, resolution recall 90.2%. Golden masters move
4 values each (network_macro, one forensic top list).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
@squid-protocol
squid-protocol merged commit 7477080 into main Sep 25, 2026
31 checks passed
@squid-protocol
squid-protocol deleted the claude/resolver-constructors branch September 25, 2026 23:46
@squid-protocol squid-protocol added this to the Compiler call-graph comparison milestone Sep 26, 2026 — with Claude
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