Skip to content

Call resolver: typed step — resolve x.method() when the function shows x's class (Python) - #3693

Merged
squid-protocol merged 1 commit into
mainfrom
claude/resolver-receiver-types
Sep 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
claude/resolver-receiver-types

Conversation

@squid-protocol

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

Copy link
Copy Markdown
Owner

Summary

A Level 2 (call-graph resolution, epic #3265) improvement.

Problem. After #3689/#3690, most of the remaining named-but-unlinked Python edges were receiver guesses: x.method() where several classes define method, and the resolver knows only the receiver's name. A breakdown of those misses against pyan3 on language-crucible:

evidence in the calling function edges example
x = SomeClass(...) in the same function 128 (84%) app = FastAPI() … @app.post("/") → FastAPI.post
a type annotation 2 twisted self.channel
none (loop over mixed types, module-level variable) 23 cython for attr in ...: attr.declare(), honestly ambiguous

Fix.

  • Detector (_python_receiver_types, Python and embedded_python via a top-level calls_out_receiver_types profile flag; not a rules pattern, per orphaned_logic reports 100% dead code for five languages whose invocation model never names the callee — the family #2727 closed without covering #2806): records, per function, receiver → class for the receivers the function calls methods on. Evidence:

    • an assignment from a call, including self.attr = mod.Parser(...);
    • a parameter or assignment annotation (ch: Channel, x: Store = make());
    • with Session() as s.

    A receiver is left out when its evidence conflicts, when it's also assigned from a non-call, or when it's bound by a for. It's never guessed.

  • Resolver: a new typed step, scoped (confident). It tries that class's method, then the nearest ancestor that has one, using the same lookup self.method() uses. It applies only when the name is a class the scan knows, so app = create_app() (a factory) changes nothing.

  • Persistence: new function_data.calls_out_receiver_types column (a JSON object, healed into older DBs). The state rehydrator restores it, so a delta scan resolves exactly like a fresh one.

  • tests/tools/call_graph_resolution.py now derives its confident steps from the resolver's RESOLUTION_OF_STEP instead of a hand-kept list.

  • docs/function_call_graph.md gains the typed row, and its example reachability query includes the step.

Type of change

  • Bug fix
  • Parsing or engine logic (detector.py, call_resolver.py, record_keeper.py, state_rehydrator.py, python profiles)

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

metric before after
confident precision 99.3% (1,687 judged) 99.4% (1,803 judged)
edge recall 48.0% 51.3%
resolution recall 90.2% 96.9%

No new "wrong target" examples appear in the 20-sample list. tests/call_graph_resolution_baseline.json is regenerated.

Cumulative since this Level 2 work started: precision 98.7% → 99.4%, edge recall 36.1% → 51.3%, resolution recall 71.8% → 96.9%.

Golden masters

crucible_check.py --mode both --update --yes: no drift in either fixture. The new links are function→function, between files that already import each other, so no file-level metric moves.

Tests

  • New tests/extraction/languages/test_calls_out_receiver_types.py covers:
    • assignment, self.attr, annotation and with evidence;
    • only receivers the function calls methods on are recorded;
    • conflicting, non-call and for-bound receivers are dropped;
    • an annotated assignment uses the annotation;
    • == and += aren't evidence;
    • languages without the flag record nothing.
  • tests/core_engine/test_call_resolver.py: the typed step, an inherited method, and a non-class type (factory) changing nothing.
  • tests/tools_recorders/test_fcall_data.py: the column persists and rehydrates.

Verification

$ pytest tests/                                               -- 11436 passed, 334 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   -- no drift

Not in this PR: the same idea for const x = new Foo() / Foo x = new Foo() in JS/TS/Java/C#. That's deferred until a Level 2 reference exists for one of those languages to measure it against.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr

…shows (python)

`app = FastAPI()` ... `app.post(...)` was a `receiver` guess: the resolver
knew only the receiver's name, and several classes define post. The
detector now records, per function, receiver -> class from local evidence
(a constructor assignment, incl. self.attr; a parameter or assignment
annotation; `with Cls() as x`), for the receivers the function calls
methods on. A receiver with conflicting evidence, a non-call assignment or
a `for` binding is left out. The resolver's new `typed` step (scoped)
takes that class's method, or its nearest ancestor's, when the class is one
the scan knows -- a factory function's name changes nothing.

Persisted as function_data.calls_out_receiver_types (JSON object, healed
into older DBs) and restored by the state rehydrator, so a delta scan
resolves the same way. call_graph_resolution.py now derives its confident
steps from the resolver.

call_graph_resolution.py python (pyan3): confident precision 99.3 -> 99.4
(1687 -> 1803 judged), recall 48.0 -> 51.3, resolution recall 90.2 -> 96.9.
Golden masters: no drift in either fixture.

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

@squid-protocol squid-protocol changed the title call resolver: a typed step for receivers whose class the function … Call resolver: typed step — resolve x.method() when the function shows x's class (Python) Sep 26, 2026
@squid-protocol
squid-protocol merged commit ad42d1b into main Sep 26, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the claude/resolver-receiver-types branch September 26, 2026 01:01
@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