Repository navigation
fix(csharp): keep names that differ only by _ or case apart, in ids and in member-call keys (#4415) - #4416
fix(csharp): keep names that differ only by _ or case apart, in ids and in member-call keys (#4415)#4416JensD-git wants to merge 1 commit into
Conversation
… and in member-call keys (Graphify-Labs#4415) make_id strips leading/trailing underscores and casefolds, while C# is case-sensitive and spells private members `_Name`. In one file, `Action()` / `_Action()`, `Size` / `_Size`, `Load()` / `load()` and the types `Pair` / `_Pair` minted one id; add_node kept the first declaration and dropped the second, and the dropped method's calls were credited to the survivor. Apply the rule of Graphify-Labs#3302 to C#: a pre-scan groups the declared names of a file (types; per type its methods, properties and enum members) that would share an id, and _underscore_salted_nid (renamed from the Python helper, unchanged) keeps the plain id on the one name without a leading underscore and salts the rest. In-file type references and base lists go through the same rule. A name without a colliding sibling keeps its id. The C# member-call resolver keyed names by lowercased alphanumerics, so `this.Put()` bound to `_Put()` on a nearer base, and `Token` / `TOKEN` were one type key. The key now keeps `_` and case. Fixes Graphify-Labs#4415. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the pull request, @JensD-git. 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 3 changed function(s) (3 not verified).
Formal verification. PR-changed functions: 0/3 verified (0 proven, 0 may-equivalent, 0 distinguished) · 3 not verified (2 vacuous, 1 unsupported).
Not verified on this run: \_resolve\_csharp\_member\_calls (vacuous: never exercised), \_csharp\_extra\_walk (vacuous: never exercised), \_extract\_generic (unsupported).
Graphify review — findings
Fixes C# declarations whose names collapse to one node id (Put/_Put, Load/load, Pair/_Pair). A new _csharp_pre_scan_name_collisions pass finds these groups per file, and the shared _underscore_salted_nid (renamed from the Python-only helper) now salts types, methods, properties, enum members and generic base references apart instead of dropping the second declaration. Member-call resolution in _resolve_csharp_member_calls now keys on case and _, so this.Put() no longer binds to _Put.
No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3370 functions depend on the 701 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 947 callers, 57 callees - worse:
_extract_generic()— 20 callers, 41 callees - worse:
walk()— 1 callers, 73 callees - worse:
_csharp_extra_walk()— 2 callers, 6 callees
Verification — 3370 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: 3133 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
190 of 413 test file(s) selected (46%) via static blast radius.
tests/test_affected_overrides.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_template_type_params.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impact, changed-testtests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impact, changed-testtests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_underscore_collisions.py— impact, changed-testtests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_path_memo.py— impacttests/test_extract_php_closures.py— impacttests/test_file_label_disambiguation.py— impact- … and 140 more
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 \_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 \_csharp\_extra\_walk.
The verifier did not have enough to check \_csharp\_extra\_walk, 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 264 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
· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).
| @@ -3999,7 +4101,8 @@ def _csharp_namespace_name(node, source: bytes) -> str: | |||
| def _csharp_extra_walk(node, source: bytes, file_nid: str, stem: str, str_path: str, | |||
There was a problem hiding this comment.
_csharp_extra_walk()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
C# nameless / `new X()` / `foreach` receiver resolution (#4422, #4428, #4423) and `_`/case-distinct node ids (#4416) change AST extraction output, so warm caches must re-extract. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.90, just released to PyPI as |
What does this PR do?
Fixes #4415.
Two C# defects with one root:
ids.py:make_idstrips leading/trailing underscores and casefolds, while C# iscase-sensitive and spells private members
_Name.1. Declarations in one file collapsed (
graphify/extractors/engine.py).Action()/_Action(),Size/_Size,Load()/load()in one type, andPair/_Pairin one namespace, minted one id;add_nodekept thefirst declaration and dropped the second, and the dropped method's calls were credited to the survivor. This PR
applies the rule of #3302 (Python, v0.9.55) to C#:
_csharp_pre_scan_name_collisions, groups the declared names of a file that would share an id:types (class, struct, interface, record, enum), and per type its methods, properties and enum members. Types are
keyed exactly as the walk mints them (namespace, arity, [Bug]: C#: a generic and a non-generic type of the same name share one node #4249); members under the type's final id, so the members
of a salted type are grouped under the salted id. It enters only namespace and type bodies and
#ifwrappers,so its recursion depth is the nesting depth of declarations.
_python_underscore_salted_nidis renamed to_underscore_salted_nidand used for both languages,unchanged: when exactly one name of a group has no leading underscore, it keeps the plain id; every other name
gets
sha1(name)[:6]appended. A type, method, property or enum member without a colliding sibling keeps itsid exactly, and the result does not depend on declaration order.
ensure_named_nodeand thebase_listlookup), soclass Z : _Pairin the same file reaches_Pair, notPair._csharp_type_name_for_id, shared by the walk and the pre-scan.2. The member-call resolver ignored
_and case (graphify/extract.py)._resolve_csharp_member_callskeyed names with
[^a-zA-Z0-9]removed and lowercased, sothis.Put()bound to_Put()on a nearer base class,and type names such as
Token/TOKENorSpec/_Specwere one key. The key now removes onlynon-word characters (the label decoration of
.Put()), keeping_and case.Two existing tests asserted the old first-wins result for a case-only pair (
enum Odd { Value, value }, propertiesCount/count); they now assert one node and one edge per member.Type of change
Verification & Invariants
Invariant: in a C# file, two declarations with different names never share a node id because of
_or case;a declaration with no such sibling keeps the id it had before. A C# member call binds only to a method whose name
equals the called name.
Persisted state: node ids change only for C# declarations that have a colliding sibling in the same file
(salted, as for Python since #3302). No node metadata or cache format change. I did not bump
_AST_CACHE_SCHEMA:the AST cache is namespaced by package version, so a release re-extracts anyway; say if you want the bump in this PR.
Determinism: the salt is a function of the declared name; the group a name falls in does not depend on the
order of declarations.
Effect on a real corpus. A proprietary C# corpus of eight graphs, each built twice from the same source tree:
graphifyy 0.9.89 from PyPI, and the same files with this change. Compared is graphify's own output (
graphify extract), no post-processing. Unit, unless stated otherwise: a pair of (source file, label) of both ends of an edge,deduplicated, per relation.
from their former survivor by an underscore, 27 only by case.
callsedges whose target name is not called on the edge's source line, while a name that differs only by aleading or trailing underscore is (source line read for every edge): 319 -> 0, in four of the eight graphs.
calls1029,references115,method2,contains1.calls, 115references): the same edge, now starting at the restored sibling, i.e. the edge comesfrom the body of
_X(), which 0.9.89 had merged intoX(). 5 sampled by hand: in each, the call line isbelow the declaration of
_X().calls, 2method, 1contains): the same edge, now ending at the sibling with the same name up to_/ case (the method actually called, or the restored declaration).calls, each checked against its source line. 22 were wrong in 0.9.89 and are gone: the target's namediffers from the called name only by underscores (e.g.
x.Run()bound to_Run(),this.Re_Do()bound to__ReDo()), or a bare call such as_Hide()bound to another class's method of that name because thecaller's own
_Hide()had been dropped, or the receiver was typed through a collapsed type key (a parameterof type
TOKENtyped as the classToken; a field of typeSpecleft untyped becauseSpecand_Specwereone key, after which the field's own name matched an unrelated type). 1 is a call between two methods that
call each other: with
_X()restored they are one node pair, andgraph.jsonkeeps one edge per pair.calls+1344,references+282,method+189,defines+35,dispatches_to+2,contains+1..sqlfile nodes appear only in the branch build (my branch environment has the optionalSQL grammar from
uv sync --all-extras, the PyPI install does not), and one HTML file whose output also variesbetween two builds of the same version.
Limitations
_key(). I changed onlythe C# one.
_csharp_receiver_type_nameaccepts only type names that start with an upper-case letter, so a receiver of type_Pairis never typed. Not changed here.Host.Itemand_Itemnestedin another type of the same file form one group and are salted apart. Two nested types with the SAME name under
different outers still share an id, as before. PR fix(extract): qualify nested class node IDs with parent class scope #4287 (open, in no release) prefixes nested type ids with the
enclosing type; if it lands, the pre-scan's key for nested types has to follow (
_visitpasses the namespaceonly). If the two keys ever diverge, a nested type's collision is only missed (no salt), never salted wrongly.
the C# pre-scan here overlaps with it for methods and types; it does not cover C# properties, enum members or the
resolver key.
How was this tested?
The repro from #4415, run with this branch:
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill fragments changed.)Generated with Claude Code