Skip to content

refactor(csharp): lift interface dispatch into a language-agnostic core - #4034

Closed
GAURAV-1313 wants to merge 1 commit into
Graphify-Labs:v8from
GAURAV-1313:refactor/interface-dispatch-core
Closed

GAURAV-1313 wants to merge 1 commit into
Graphify-Labs:v8from
GAURAV-1313:refactor/interface-dispatch-core

Conversation

@GAURAV-1313

Copy link
Copy Markdown
Contributor

What does this PR do?

Moves the single-implementer dispatch mechanism out of graphify/csharp_dispatch.py into a new graphify/interface_dispatch.py, with the file-suffix gate as a keyword parameter (resolve_interface_dispatch(..., suffixes=)). csharp_dispatch.py keeps its public names (resolve_csharp_interface_dispatch, _method_label, DISPATCH_RELATION) and becomes the .cs gate over the core. The registration in extract.py is untouched.

Why: Swift protocols have exactly the shape #3003 fixed for C# interfaces. Since #3673 a call through an injected protocol lands on the requirement node, and the conformer's method is unreachable from it. The follow-up PR adds a 46-line .swift gate over this core instead of a second copy of the algorithm, following the rule from the #3729 review: reuse the existing resolver rather than re-implement a subset of it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: for every corpus, the edges this pass emits are identical before and after. The body of resolve_interface_dispatch is the old function verbatim; the only edit is the module constant _CSHARP_SUFFIXES becoming the suffixes parameter, which the C# gate passes as (".cs",). Which pairs qualify, the edge's fields, and the dedup are unchanged. No persisted or generated state is involved: the pass runs in memory after extraction.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test. Not a bug fix: the 15 tests in tests/test_csharp_interface_dispatch.py pass unmodified and are the boundary test (two implementers produce nothing, a Java corpus gains no edge, the dedup is scoped to dispatches_to).
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly. Nothing new; the docstring keeps the out-of-scope list from feat(csharp): link interface methods to their single implementation #3005 (abstract base classes, interface hierarchies).

How was this tested?

uv run pytest tests/test_csharp_interface_dispatch.py -q
  15 passed, file unmodified
uv run pytest tests/test_csharp*.py tests/test_language_resolvers.py tests/test_architecture_doc.py -q
  207 passed
uv run pytest tests/ -q
  6135 passed, 102 skipped, 24 failed: the 24 are tests/test_{erlang,r,solidity,vbnet}_extractor.py,
  whose grammars are optional extras not installed here; a clean v8 checkout fails the identical 24
uv run ruff check graphify/interface_dispatch.py graphify/csharp_dispatch.py
  All checks passed
uv run pyright graphify/interface_dispatch.py graphify/csharp_dispatch.py
  4 errors: the same 4 v8 reports on csharp_dispatch.py (`e.get("target")` typed as possibly None,
  lines 92/102 there, 96/106 here), moved with the code and not touched

Diff: 2 files, +176 / −133. One commit, rebased on v8 at 0b60d47.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. No fragment changed.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables). The pass reads the edge list in order and dedups on node ids; no filesystem, environment or network input.
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python). No shell, subprocess or interpolation.
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. Claude Code assisted with this change; the commit message says so.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

Thanks for the pull request, @GAURAV-1313. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

Move the single-implementer dispatch mechanism from csharp_dispatch.py
into interface_dispatch.py with the file-suffix gate as a keyword
parameter. csharp_dispatch.py keeps its public names
(resolve_csharp_interface_dispatch, _method_label, DISPATCH_RELATION)
and becomes the `.cs` gate over the core. No behaviour change: the 15
C# dispatch tests pass untouched, and the extractor registration is
not modified.

Swift protocols have the same shape (Graphify-Labs#3673 resolves a call through an
injected protocol to the requirement, and the conformer's method sits
unreachable from it). With the core shared, that language can add a
gate instead of a second copy of the algorithm.

AI disclosure: Claude Code assisted with this change.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.


Graphify review — findings

Refactors the single-implementer interface-dispatch resolver into a language-agnostic resolve_interface_dispatch, which takes a suffixes gate that both the interface and its implementer must be declared in. Another language (Swift protocols, say) can now add a thin wrapper instead of copying the algorithm. resolve_csharp_interface_dispatch becomes that wrapper with .cs and still re-exports DISPATCH_RELATION and _method_label for existing callers.

Worth a look

  • Cross-language implementers suppress valid dispatch — graphify/interface_dispatch.py:92 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 14 functions depend on the 12 functions this change touches.

Health — grade A; no new coupling hotspots.

Verification — 14 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 14 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

1 of 318 test file(s) selected (0%) via static blast radius.

  • tests/test_csharp_interface_dispatch.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.75 (live on PyPI as graphifyy==0.9.75). Landed on v8 via an authorship-preserving cherry-pick, so your original commit authorship is kept. Thanks @GAURAV-1313 for the language-agnostic interface-dispatch core 🙏

Closing as shipped.

@safishamsi safishamsi closed this Oct 4, 2026
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.

3 participants