Repository navigation
fix(csharp): make constructors nodes and link new/base/this to the overload by arity - #5054
rohit-jsfreaky wants to merge 1 commit into
Conversation
…erload by arity A C# constructor had no node. Calls in its body were credited to the type (Graphify-Labs#4246), calls in `: base(...)`/`: this(...)` arguments were never walked, and `new X(a, b)` could only point at the type, never at the overload it runs. On Dapper, AutoMapper and Newtonsoft.Json (Roslyn answer key) 151 call links made from constructors were all lost and none of the 130 constructor initializers was linked. - Each constructor (instance, static, and a type's primary constructor) is a node owned by its type through a `method` edge, labeled `.TypeName()` with metadata kind "constructor" plus arity/signature. The id is `_make_id(type_id, TypeName)`, the one a method named after the type would get; other signatures are salted like method overloads (Graphify-Labs#4584), a static constructor is its own "static" signature, and if a member spelled like the type in another case (`foo()` in `Foo`) already owns that id the constructor takes a salted one. No existing node id changes (checked on all three projects). - Body and initializer calls belong to the constructor. - `new X(...)` sites and initializers are recorded in raw_calls with no callee (so every name-keyed consumer skips them and the id passes remap their caller). A tail C# pass links the constructor whose parameter count fits, next to the existing edge to the type. `: this(...)` uses the own type, `: base(...)` the single resolvable base. Two fitting overloads, an unresolved base, or a type the caller did not bind give no edge. - Constructors are left out of every name-keyed call index (in-file label map, global label index, member-call index, overload index, interface dispatch), so a constructor can never be picked for an ordinary call or shadow its type. - AST cache schema 40. Co-Authored-By: Claude <[email protected]>
|
Thanks for the pull request, @rohit-jsfreaky. 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. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 7 changed function(s) (7 not verified).
Formal verification. PR-changed functions: 0/7 verified (0 proven, 0 may-equivalent, 0 distinguished) · 7 not verified (5 vacuous, 2 unsupported).
Not verified on this run: \_csharp\_overload\_index (unsupported), \_resolve\_csharp\_member\_calls (vacuous: never exercised), extract (vacuous: never exercised), \_csharp\_method\_signature (vacuous: never exercised), \_csharp\_pre\_scan\_name\_collisions (vacuous: never exercised), \_extract\_generic (unsupported), resolve\_interface\_dispatch (vacuous: never exercised).
Graphify review — findings
Adds C# constructors (instance, static and primary) as nodes owned by their type through a method edge, labeled .TypeName() with kind: "constructor". Each constructor reuses the id a method named after the type would get, with overloads, static constructors and case-only collisions (foo() in Foo) salted, so no existing id moves. new X(...) keeps its edge to the type and also links the constructor whose parameter count fits, as does : base(...)/: this(...), with _resolve_csharp_constructor_calls assigning each edge's confidence and score; two fitting overloads, an unresolved base or an unbound type fall back to the type edge alone. Bumps the AST cache schema to 40 so cached C# extractions without constructors re-run.
Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 5427 functions depend on the 1036 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1153 callers, 69 callees - worse:
_rebuild_code()— 261 callers, 73 callees - worse:
walk()— 1 callers, 83 callees - worse:
walk_calls()— 1 callers, 39 callees - new:
_resolve_csharp_constructor_calls()— 0 callers, 6 callees
Verification — 5427 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: 4781 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
526 of 526 test file(s) selected (100%) via static blast radius.
Escalated to a full run for safety (
noncode-change,uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.
tests/pi.test.ts— full-run-safetytests/test_4874_jvm_resolution.py— impact, full-run-safetytests/test_4909_reference_binding_scale.py— full-run-safetytests/test_4978_reconcile_cost.py— impact, full-run-safetytests/test_4992_ts_import_types.py— impact, full-run-safetytests/test_affected_cli.py— full-run-safetytests/test_affected_defines.py— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_affected_overrides.py— impact, full-run-safetytests/test_affected_path_file_node.py— full-run-safetytests/test_affected_seed_reference_forms.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_alias_folding.py— impact, full-run-safetytests/test_analyze.py— impact, full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— impact, full-run-safetytests/test_astro_import_ids.py— impact, full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_backend_opt_in.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_benchmark_real_query.py— full-run-safetytests/test_binary_media_words.py— impact, full-run-safetytests/test_blade_extractor.py— impact, full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_located_semantic_identity.py— impact, full-run-safetytests/test_build_merge_dedup_scope.py— impact, full-run-safetytests/test_build_merge_ghost_fold_4955.py— impact, full-run-safetytests/test_build_merge_hyperedges_and_prune.py— impact, full-run-safetytests/test_build_merge_shrink_guard.py— impact, full-run-safetytests/test_builtin_global_type_refs.py— impact, full-run-safetytests/test_c_include_resolution.py— impact, full-run-safetytests/test_cache.py— impact, full-run-safetytests/test_cache_long_paths.py— impact, full-run-safetytests/test_cache_stale_import_target.py— impact, full-run-safetytests/test_cache_windows_case_4925.py— impact, full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— impact, full-run-safetytests/test_case_only_decl_ids_4904.py— impact, full-run-safetytests/test_case_sensitive_resolution.py— impact, full-run-safetytests/test_charmap_encoding.py— impact, full-run-safety- … and 476 more
non-code file(s) changed (
ARCHITECTURE.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
ARCHITECTURE.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests
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.
Formal verification
Could not verify: Could not verify \_csharp\_overload\_index.
The verifier did not have enough to check \_csharp\_overload\_index, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 81 values but only 11 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)
Could not verify: Could not verify \_resolve\_csharp\_member\_calls.
The verifier did not have enough to check \_resolve\_csharp\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
Could not verify: Could not verify extract.
The verifier did not have enough to check extract, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_csharp\_method\_signature.
The verifier did not have enough to check \_csharp\_method\_signature, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 121 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_csharp\_pre\_scan\_name\_collisions.
The verifier did not have enough to check \_csharp\_pre\_scan\_name\_collisions, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 253 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_extract\_generic.
The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set
Could not verify: Could not verify resolve\_interface\_dispatch.
The verifier did not have enough to check resolve\_interface\_dispatch, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 12 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
· 2 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).
| e.pop("target_file", None) | ||
|
|
||
|
|
||
| def _resolve_csharp_constructor_calls( |
There was a problem hiding this comment.
_resolve_csharp_constructor_calls()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| add_edge(type_nid, ctor_nid, "method", line) | ||
| return ctor_nid | ||
|
|
||
| def walk(node, parent_class_nid: str | None = None) -> None: |
There was a problem hiding this comment.
walk()
fans out to 83 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
#5058, #5060, #5062, #5054 and #5056 each change per-file Solidity or C# extraction output and each bumped _AST_CACHE_SCHEMA to 40 on their own. Landed together in one release window they share a single bump; this folds their descriptions into one chained schema-40 comment over the prior 39 so a warm cache re-runs the affected Solidity and C# extractions exactly once. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed on |
Closes #5053
What does this PR do?
C# constructors become nodes, and the calls that reach them are linked to the right overload:
new X(a, b)links to theXconstructor with that arity. The existing edge to the type stays; this adds one.: this(...)links to the own overload, and: base(...)to the base class constructor, also across files.newnever picks it. Primary constructors are nodes too, so they compete with explicit ones.It fails closed: no constructor edge when two overloads take the same number of arguments, or when the base class is outside the corpus.
Node ids. A constructor gets
_make_id(type_id, TypeName), the id a method named after the type would get. Other overloads are salted like method overloads. If a member likefoo()inclass Fooalready owns that id, the constructor gets a salted id instead. On the three projects below, no existing node id changed or disappeared. All 1,423 new nodes are constructors.AST cache schema 39 -> 40. #5052 and the accessor/operator PR also bump it to 40, so whichever lands second takes the next number.
Diff:
extractors/engine.py+126 / -15,extract.py+136,extractors/csharp.py+15,interface_dispatch.py+3, an ARCHITECTURE.md note, 13 tests across 4 test files.Behaviour change to flag
#4246 credited constructor-body calls to the class, because constructors had no node. Now they come from the constructor, so "what does class X call directly" shows fewer edges, and the constructor node shows them instead. I updated the two #4246 tests and one label list to match.
Earlier attempts
#3016 and #3247 (both open since August) add
constructor_declarationto the method types, a 2-line change. On v8 that:new X(a, b)can't pick one;foo()inclass Foodisappears);This PR handles each of those, and it adds the
new/this(...)/base(...)links.Numbers
Newtonsoft.Json, Dapper and AutoMapper, compared with Roslyn (same harness as #5003):
base(...)/this(...)initializers (separate Roslyn key)callsedgesNo kind drops. Wrong edges change in four ways:
Add(content)picked by arity only.46 of the 50 missed initializers are same-arity overloads, which fail closed by design.
Limitations
new()(88 Roslyn links) is not handled.Type of change
Verification & Invariants
Invariants:
Existing node ids never change; new constructor ids are salted when taken.
A constructor edge is added only when exactly one overload fits the argument count.
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.
Kept the PR description synchronized with the final implementation.
Documented any limitations / unsupported cases explicitly.
How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (Not needed: no skill fragments changed.)🤖 Generated with Claude Code