Skip to content

feat(csharp): link interface methods to their single implementation - #3005

Closed
durmazoguzhan wants to merge 4 commits into
Graphify-Labs:v8from
durmazoguzhan:feat-csharp-interface-dispatch
Closed

durmazoguzhan wants to merge 4 commits into
Graphify-Labs:v8from
durmazoguzhan:feat-csharp-interface-dispatch

Conversation

@durmazoguzhan

@durmazoguzhan durmazoguzhan commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3003.

A C# call through an injected dependency lands on the interface's method node, because that is what the call site names. The implementation is a separate node with nothing joining the two, so a directed walk stops there:

.Go()     -> .Build()   [calls]      target: ireport_ireport_build
.Build()  -> .Format()  [calls]      source: report_report_build

Two .Build() nodes, no edge between them, so .Go() never reaches .Format(). On a service that injects every dependency as an interface, that is most chains, and affected reports a blast radius smaller than the real one.

resolve_csharp_interface_dispatch adds a member-level edge:

ireport_ireport_build  --dispatches_to-->  report_report_build

Guards

  • the interface has exactly one implementer
  • that implementer owns exactly one method of the same name
  • zero or several candidates at either step leaves the pair alone

Walking implements to the only type that can serve the call is the same bet resolve_pascal_inherited_calls describes for walking inherits: structurally justified rather than a name guess. Ambiguity produces nothing, which is also what #437 asks for.

Confidence is INFERRED. The target is forced once there is a single implementer, but the source text never names it.

The pass is additive. The call edge to the interface method stays, since the call site really does name the interface, and the join is per method rather than per call site.

Measured

A .NET 8 service, 1457 C# files, Scrutor assembly scanning. Same checkout, resolver registration on and off:

without:  9925 nodes, 29547 edges
with:     9925 nodes, 30409 edges     (+862, +2.9%)

862 edges give 1511 interface-method call edges a route to an implementation. 115 interface types have implementers there and 107 have exactly one, so the guard drops 8.

Review fixes

Two passes of findings, all four real:

  • The member match folded case, copied from the Pascal resolver where it belongs because Pascal is case insensitive. C# is not, so it is case sensitive now.

  • The already-emitted check scanned every edge, so another relation between the two members suppressed the link. Scoped to dispatches_to.

  • implements resolves by name, so a Java class declaring implements IReport binds to a C# IReport and the resolver linked the C# member to the Java method. Every end of a pair now has to be a .cs declaration.

  • A non-C# implementation of a C# interface, from VB or a Razor @implements, is real but stays out: claiming one should rest on that extractor's evidence rather than a cross-language name match.

  • The member name was taken by stripping a trailing (). That holds for every label the extractor emits today (3674 method nodes on that service, none outside the .Name() shape, explicit interface implementations and generic methods included), but the match is keyed on that string, so it now reads up to the first parenthesis and a signature-carrying label would keep matching instead of silently missing.

The corpus count is 862 edges before and after all five, which is what I would expect if nothing real was riding on the loose ends.

Three of the five landed on one theme: the resolver's shape is lifted from resolve_pascal_inherited_calls, and assumptions that hold for Pascal (case insensitive names, a calls-only edge space) do not hold for C#.

Out of scope, both pinned by tests

  • class Impl : Base on an abstract class is an inherits edge, and a base method may well be the real target, so walking inheritance is a different bet.
  • An interface hierarchy (IBase <- IChild <- Impl) is not walked transitively. IBase's only implementer is IChild, which declares nothing, so nothing links. I found no case of it in the corpus above, so I left the chain walk out rather than write code with no evidence behind it.

Tests

tests/test_csharp_interface_dispatch.py, 15 tests: the link itself, the chain becoming reachable, the interface call being kept, two implementers producing nothing, a missing member producing nothing, collapsed overloads still linking (the guard counts distinct nodes, not method edge multiplicity, same as the Pascal dedup comment), abstract base classes staying out, interface hierarchies staying out, and a Java corpus gaining no edge.

Three fail on v8 without the registration.

$ uv run pytest tests/test_csharp_interface_dispatch.py -q
15 passed

$ uv run pytest tests/ -q --ignore=tests/test_skillgen.py
4826 passed, 11 skipped

tests/test_skillgen.py fails here on a clean v8 checkout as well, before any of my changes, so I left it out of that run rather than report failures that are not mine. ruff check is clean on the three files.

Open question

dispatches_to is my guess at a name that fits the existing vocabulary. I did not reuse implements at member level because its type-level direction is implementation to interface, and a directed walk needs the opposite to be useful. Happy to rename.

…raphify-Labs#3003)

`_report.Build()` on an injected `IReport` resolves to `IReport.Build()`, which
is what the call site names, and the implementing `Report.Build()` is a separate
node with nothing joining the two. A directed walk stops at the interface, so on
a codebase where every dependency is injected as an interface, most chains are
cut mid-way and `affected` understates the blast radius.

resolve_csharp_interface_dispatch adds a `dispatches_to` edge from the interface
method to the implementing method when the interface has exactly one implementer
and that implementer owns exactly one method of the same name. Walking
`implements` to the only type that can serve the call mirrors what the runtime
does, the same reasoning resolve_pascal_inherited_calls gives for walking
`inherits`; ambiguity at either step leaves the pair alone.

Confidence is INFERRED, since the target is forced but never written in source.
The join is per method rather than per call site, and the existing call edge to
the interface method is kept, so the pass is additive.

On a 1457-file .NET service this emits 862 edges, +2.9% on 29547, and gives 1511
interface-method calls a route to an implementation.

Abstract base classes (an `inherits` edge, where the base method may itself be
the target) and interface hierarchies are out of scope, both pinned by tests.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE

@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 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Adds member-level C# interface dispatch resolver in the new graphify/csharp_dispatch.py (resolve_csharp_interface_dispatch), which links an interface method to its implementation when the interface has exactly one implementer owning exactly one same-named method, emitting additive dispatches_to edges at INFERRED confidence. Registers it as a language resolver in extract.py alongside the Pascal resolver. Covers behavior with tests/test_csharp_interface_dispatch.py, including single-implementer linking, chain reachability through injected dependencies, and the guards for ambiguous/abstract/transitive cases.

Worth a look

  • C# method matching incorrectly ignores case — graphify/csharp_dispatch.py:36 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Existing non-dispatch edge suppresses dispatch edge — graphify/csharp_dispatch.py:108 · 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 — 1559 functions depend on the 228 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 23 more — each is listed as a finding

Verification — 1559 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: 1411 function(s) in the blast radius were not formally verified this run

· 31 more finding(s) on lines outside this diff (see the check run).

Two review findings on the resolver.

The member match folded case, copied from resolve_pascal_inherited_calls where
it is right because Pascal is case insensitive. C# is not: an implementing member
must spell the interface member exactly, so folding case could only pair a
declaration with a member that does not implement it. Corpus count is unchanged
at 862 edges, since a real implementation already matches exactly.

The already-emitted check scanned every edge, so any other relation between the
two members suppressed the dispatch link. It now looks only for dispatches_to.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE
@durmazoguzhan

Copy link
Copy Markdown
Contributor Author

Both findings were right. Fixed in the commit above.

The case fold came from resolve_pascal_inherited_calls, which I used as the model for this resolver. It belongs there, since Pascal is case insensitive, and it does not belong here: a C# member that implements an interface member spells it exactly, so folding case could only pair a declaration with something that does not implement it. The corpus count is unchanged at 862 edges, which is the expected result if no real implementation was ever relying on the fold.

The already-emitted check scanned every edge rather than dispatches_to edges, so any other relation between the two member nodes would have suppressed the link. It is scoped to the relation now.

Three tests added: a case-only difference producing nothing, an unrelated edge between the two members not suppressing the link, and an existing dispatch edge not being duplicated. tests/test_csharp_interface_dispatch.py is 12 tests, and the extraction suites are 679 passed.

@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 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Adds graphify/csharp_dispatch.py with resolve_csharp_interface_dispatch, which links a C# interface method to its implementation (dispatches_to edge, INFERRED) when the interface has exactly one implementer owning exactly one same-named method, so directed walks no longer stop at interface methods on injected dependencies. Registers it as a .cs language resolver in extract.py, keeping the existing calls edge to the interface intact. Covers the single-implementer, ambiguity, overload-collapse, and abstract-base cases in tests/test_csharp_interface_dispatch.py.

Worth a look

  • C# dispatcher mutates non-C# interface edges in mixed-language corpora — graphify/csharp_dispatch.py:64 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • C# dispatch can target a non-C# implementer — graphify/csharp_dispatch.py:98 · 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 — 1562 functions depend on the 231 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 23 more — each is listed as a finding

Verification — 1562 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: 1414 function(s) in the blast radius were not formally verified this run

· 31 more finding(s) on lines outside this diff (see the check run).

Second review pass, and the mixed-corpus finding reproduces. `implements` is
resolved by name, so a Java class declaring `implements IReport` binds to a C#
`IReport` when that is the only node carrying the name, and the resolver then
linked the C# interface member to the Java method:

    .Build() (IReport.cs) -dispatches_to-> .Build() (Report.java)

A wrong edge across languages, not a missing one. Every end of a pair now has to
be a declaration in a .cs file: the interface, the implementer and both member
nodes. The interface side was already checked; the implementer and the members
were not.

A non-C# implementation of a C# interface is a real thing in .NET, from VB or a
Razor component, but claiming it needs that extractor's own evidence rather than
a name match. Corpus count is unchanged at 862 edges.

Tests: a C# interface with a Java implementer producing nothing, and a mixed
corpus linking only the C# pair.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE
@durmazoguzhan

Copy link
Copy Markdown
Contributor Author

The mixed-corpus finding reproduces, and it produces a wrong edge rather than a missing one, so thanks for pushing on it. Fixed in the commit above.

implements is resolved by name, so with one IReport in the corpus and it being C#, a Java class binds to it:

Report (Report.java)   -implements->     IReport (IReport.cs)
.Build() (IReport.cs)  -dispatches_to->  .Build() (Report.java)

Every end of a pair now has to be a declaration in a .cs file: the interface, the implementer, and both member nodes. I had checked the interface side only, which is why a Java-only corpus was already clean and this case was not.

On the other half of the finding, a non-C# implementation of a C# interface is a real thing in .NET, from VB or a Razor component with @implements. I left those out rather than in: claiming one should rest on that extractor's own evidence, not on a name match that happens to cross languages.

Corpus count is unchanged at 862 edges, which is what I would expect if nothing real was riding on the loose ends.

Two tests added: a C# interface with a Java implementer producing nothing, and a mixed corpus linking only the C# pair. tests/test_csharp_interface_dispatch.py is 14 tests, extraction suites 681 passed.

@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

Adds resolve_csharp_interface_dispatch in a new graphify/csharp_dispatch.py and registers it as a post-extraction language resolver, emitting dispatches_to edges from a single-implementer interface method to its implementing method so call chains through injected dependencies stay walkable. Edges are additive (the interface call is kept), C#-only on both ends, INFERRED confidence, and skipped on any ambiguity. Ships tests/test_csharp_interface_dispatch.py covering the link, chain reachability, and the two-implementer/no-match/overload guards.

Worth a look

  • Parameterized C# method labels are not reduced to bare names — graphify/csharp_dispatch.py:56 · 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 — 1566 functions depend on the 235 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 23 more — each is listed as a finding

Verification — 1566 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: 1418 function(s) in the blast radius were not formally verified this run

· 31 more finding(s) on lines outside this diff (see the check run).

…esis

The pair match is keyed on the member name, which was taken by stripping a
trailing `()`. That holds for every label the C# extractor emits today, so this
changes no edge: 3674 method nodes in a 1457-file service, none outside the
`.Name()` shape, and the corpus count stays at 862. Explicit interface
implementations (`void IReport.Build()`) and generic methods already label as
`.Build()` and already linked.

Cutting at the first parenthesis instead means a label that ever carried a
signature keeps matching rather than silently missing, which matters because the
guard reads this string on both ends. Pinned by a unit test on the helper.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE
@durmazoguzhan

Copy link
Copy Markdown
Contributor Author

This one does not reproduce on C# today, but it is a fair thing to point at, so I hardened it anyway and checked rather than assumed.

What the extractor actually labels, on a 1457-file service: 3674 method nodes, none of them outside the .Name() shape. The two cases where I expected a signature to leak in both come out as plain names and already linked:

void IReport.Build() { }     ->  .Build()   (explicit interface implementation)
public void Build<T>() { }   ->  .Build()   (generic method)

An indexer produces no method node at all, so there is nothing to match there either.

Still, the pair match is keyed on that string on both ends, so a label that ever carried a signature would silently stop matching instead of failing visibly. The name is now read up to the first parenthesis rather than by stripping a trailing (), with a unit test on the helper. No edge changes: the corpus count is 862, the same as through the previous three rounds of fixes.

That is the fourth round on this PR and the fifth finding overall. For what it is worth, the three that were real (case folding, the dedup scope, and the cross-language pair) all landed on the same theme: I lifted the shape from resolve_pascal_inherited_calls and inherited assumptions that hold for Pascal and not for C#. Worth keeping in mind if another language resolver gets written from that template.

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Adds a C# member-level interface dispatch resolver (graphify/csharp_dispatch.py) that links an interface's method node to its implementation via a new dispatches_to edge, reconnecting call chains that route through injected dependencies. Fires only when an interface has exactly one implementer owning exactly one same-named method, both ends are C# declarations, and the edge doesn't already exist; existing calls edges to the interface are left untouched. Registers it in graphify/extract.py as a post-extraction language resolver and covers the behavior in tests/test_csharp_interface_dispatch.py.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1567 functions depend on the 236 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 476 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_js() — 80 callers, 3 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: collect_files() — 17 callers, 6 callees
  • …and 23 more — each is listed as a finding

Verification — 1567 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: 1419 function(s) in the blast radius were not formally verified this run

· 31 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.49 via authorship-preserving cherry-pick so you keep contributor-graph credit. Thanks @durmazoguzhan! Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.49

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.

C#: a call through an interface dead-ends at the interface method, so injected dependencies cut every chain

2 participants