Repository navigation
csharp: a relative qualified name is read from the site's namespace, not the file's (#1906) - #1910
Open
swapnilpaliwal-sd wants to merge 1 commit into
Open
swapnilpaliwal-sd wants to merge 1 commit into
swapnilpaliwal-sd wants to merge 1 commit into
Conversation
…not the file's `Models.Report` written inside namespace P, in a file that also declares P.Other.Models and Z.Models, bound to all three Report types: the relative candidate (type_qn_tail + module_ns_chain) is keyed per FILE, so every namespace the file declares a type in qualified every name in it. C# reads the first segment from the namespaces enclosing the site, innermost outward, and the innermost level with a match wins. - type_name_out_of_scope(ns, name, arity, group): per site namespace and dotted written name, candidates are ranked by the prefix they were found under; only the longest survives, and a full match survives only when no enclosing namespace matched. Demand-driven from names a file writes. - type_ref_resolves, ref_names_type, expr_new_type and heritage_resolves drop what the site's enclosing type's namespace rules out. Prune-only: the file-level answer is unchanged and a site with no known enclosing type drops nothing. Case a-relative-name-is-read-from-the-sites-namespace fails 5/6 on the base (the single-namespace control passes on both) and passes 6/6. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
swapnilpaliwal-sd
requested review from
JaredHLZhang,
Whua689 and
suyashpaliwal26
as code owners
October 10, 2026 21:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
The relative qualified-name candidate (
type_qn_tail+module_ns_chain, rank 1 intype_name_cand) is keyed per file:module_ns_chainholds every namespace the file declares a type in, plus their prefixes. In a file declaringP.Models,P.Other.Models,Z.Modelsand a class inP,Models.Reportwritten inPbound to all threeReporttypes. C# reads the first segment from the namespaces enclosing the site, innermost outward, and the innermost level that has a match wins.What changed
type_name_out_of_scope(prov, ns, name, arity, group): for each site namespace and dotted written name, the candidates are ranked by the length of the prefix they were found under. Only the longest survives. A full match (the global level) survives only when no enclosing namespace matched. It is demand-driven from the dotted names each file writes (type_name_written_dotted, keyed by module so the probe reusestype_name_resolves' existing index).type_ref_resolves,ref_names_type,expr_new_typeandheritage_resolves(the written-name clause).type_name_resolvesstays per file and unchanged. A site only removes answers from it. A site whose enclosing type is not known removes nothing.SCHEMA.mdis unchanged (checked with--print-schema).Case and controls
tests/cases/csharp/a-relative-name-is-read-from-the-sites-namespace: one file declaresP.Models,P.Other.ModelsandZ.Models, with sites inP, inP.Otherand in a type nested inP.Other. A second file declares onlynamespace P.P→P.Models.Reportonly. TheP.Otherchild is not in scope.P.Otherand in the nested type →P.Other.Models.Reportonly. The outerP.Models.Reportis not merged in.Z.Models.Reportis never named.[resolved]target. It passes on both base and fix.Base: 1/6 checks (only the single-namespace control). Fix: 6/6.
Suites
tests/run.py --lang csharp --jobs 3: 325/325 checks in 61 cases, includinga-namespace-name-is-read-from-its-namespace(6/6).graph/test/csharp/run-tests.sh(Roslyn oracle): 22/22 cases, plus the self-tests, entry-points, library-resolution, mediator, mock-constructor, overload, pipelines and remote-edge tests. All ok.Cost (compiled engine,
devrun.shfacts, solve wall time, base vs fix interleaved ×3)The difference is within noise (the machine was loaded). New relation sizes on A / B:
type_name_written_dotted1081 / 818 (per module on B),type_name_scope_demand32 on B,type_name_scope_level74 / 87,ns_read_level103 / 107,type_ref_scope_type12.6k / 9.8k,type_name_out_of_scope0 / 16, and every*_droppedrelation 0 / 0.type_name_resolves(1.20M / 887k),type_ref_resolves,ref_names_type,expr_new_typeandheritage_resolvesare identical to base. Neither subject has a multi-namespace file with a clashing relative name, so their edges are unchanged.A first version keyed the demand on the name alone, which needs a new index on
type_name_resolves. In one run it measured about 1.7x the base solve time; that run was not isolated from other load. Keying the demand on (module, name) brought it back within noise.Not changed
The relative
usingrule (module_in_scopeviamodule_ns_chain) is also per file, but so is everyusinghere. The IR does not record which namespace block a using sits in, so it cannot be scoped per site without parser support.Fixes #1906 (close by hand on merge: integration branch)