Skip to content

Propose change for metadata names of grouping types#9682

Merged
jcouv merged 11 commits intomainfrom
jcouv-patch-5
Sep 17, 2025
Merged

Propose change for metadata names of grouping types#9682
jcouv merged 11 commits intomainfrom
jcouv-patch-5

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Sep 12, 2025

No description provided.

@jcouv jcouv marked this pull request as ready for review September 12, 2025 22:04
@jcouv jcouv requested a review from a team as a code owner September 12, 2025 22:04
- if someone makes metadata for an extension type using some other tool, and they do include the arity suffix in the metadata names of grouping and marker types, then docIDs won't match metadata names again.

The docIDs from C# source or metadata for the example would be:
- extension block: "E.<G>$8048A6C8BE30A622530249B904B537EB.<M>$65CB762EDFDF72BBC048551FDEA778ED"
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 12, 2025

Choose a reason for hiding this comment

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

This doesn't look accurate. In this case, "they do include the arity suffix in the metadata names", the suffixes will be preserved by C# because they are in metadata names and C# doesn't remove them from metadata names. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

This paragraph is about docIDs from C# source or metadata. It relates to the first bullet. I'll make that more explicit.
The illustration for metadata from some other tool (ie. second bullet) is below.


The docIDs from C# source or metadata for the example would be:
- extension block: "E.<G>$8048A6C8BE30A622530249B904B537EB.<M>$65CB762EDFDF72BBC048551FDEA778ED"
- extension member: "E.<G>$8048A6C8BE30A622530249B904B537EB.M"
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 12, 2025

Choose a reason for hiding this comment

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

Here as well. #Closed


**If we do include an arity suffix** when producing docIDs for extensions, then the docIDs don't match the metadata names.

The docIDs for the example would differ from the names in metadata:
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 12, 2025

Choose a reason for hiding this comment

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

I think there is another doc id that includes type parameters, which drops the arity suffix, and that also causes slightly different issues. Consider including examples of those too. #Pending

# Proposal

We're proposing to update the metadata design to include arity suffix in the metadata names for grouping and marker types.
The metadata names for grouping and marker types would be mangled from the `ExtensionGroupingName` and `ExtensionMarkerName`.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

I think there is no issue with ExtensionMarkerName. A conventional name for it wouldn't include any arity suffix, because from language perspective marker type inherits all type parameters from the enclosing grouping type, therefore itself not generic from C# or VB point of view.

class C1<T, U>
{
    class C2
    {}
    class C3<S>
    {}
}

Checkout metadata name for C2:

.class private auto ansi beforefieldinit C1`2<T, U>
    extends [mscorlib]System.Object
{
    // Nested Types
    .class nested private auto ansi beforefieldinit C2<T, U>
        extends [mscorlib]System.Object
    {
    } // end of class C2

    .class nested private auto ansi beforefieldinit C3`1<T, U, S>
        extends [mscorlib]System.Object
    {
    } // end of class C3`1
} // end of class C1`2

#Closed

```
.class E
{
.class '<G>$8048A6C8BE30A622530249B904B537EB`1' // grouping type with arity suffix
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Is there a type parameter? #Closed

{
.class '<G>$8048A6C8BE30A622530249B904B537EB`1' // grouping type with arity suffix
{
.class '<M>$65CB762EDFDF72BBC048551FDEA778ED`1' // marker type with arity suffix
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Is there a type parameter? And, as I mentioned above, there should be no arity suffix here #Closed

```
.class E
{
.class '<G>$8048A6C8BE30A622530249B904B537EB' // grouping type
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Is there a type parameter? #Closed

{
.class '<G>$8048A6C8BE30A622530249B904B537EB' // grouping type
{
.class '<M>$65CB762EDFDF72BBC048551FDEA778ED' // marker type
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Is there a type parameter? #Closed

}
```

Then the docIDs would not match the metadata names:
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Why wouldn't they match? The types aren't generic, therefore suffixes wouldn't be added or removed by compilers. Perhaps there is a mistake in the IL and types should be generic? Suffix doesn't make types generic. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

IL got adjusted and the thread was resolved, but I am still confused by the names below. What tool/component would produce the names below? Why the arity suffix wouldn't be there? It will be part of ExtensionGroupingName for C# and VB would include the suffix as well. Probably in this scenario there could be a problem with a doc id that includes type parameters instead?

public static void M(this int i) { } // implementation method
}
```
The `ExtensionGroupingName` would remain "<G>$8048A6C8BE30A622530249B904B537EB" (both for source and metadata symbols).
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Effectively we are proposing that ExtensionGroupingName should reflect name of the emitted grouping type from language perspective, not its emitted name. Emitted name should follow naming convention used by C# for types declared in source. I think this should be clearly stated. #Closed

}
```
The `ExtensionGroupingName` would remain "<G>$8048A6C8BE30A622530249B904B537EB" (both for source and metadata symbols).
The `ExtensionMarkerName` would remain "<M>$65CB762EDFDF72BBC048551FDEA778ED" (both for source and metadata symbols).
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Taking my previous comments into account. ExtensionMarkerName reflects name of the emitted marker type from language perspective and its emitted name at the same time. Both names are equivalent. No need to change here. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Sep 13, 2025

Done with review pass (commit 3) #Closed

@jcouv jcouv self-assigned this Sep 13, 2025

# Proposal

We're proposing to update the metadata design to include arity suffix in the metadata names for grouping and marker types.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

and marker types

Consider dropping marker types from this sentence since no change is proposed for them. #Closed

`ExtensionGroupingName` should reflect names of the emitted grouping typs from language perspective, not its emitted names.
That would be more conventional.
No change to `ExtensionMarkerName` (name and metadata names match).
Then we'd produce the docIDs as described above, by appending an arity suffix to `ExtensionGroupingName` as needed.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

as needed

The "as needed" part is confusing because, in my opinion, in some scenarios compiler adds suffix when it is not needed. However, I think we are not proposing changing that part. Perhaps "in a way consistent to the current handling of regular generic types" would reflect what is proposed more accurately. #Closed

If we're going to make this change, we have about 1 week to get this into the RC2 compiler.
But the RC2 SDK/BCL will be compiled using the RC1 compiler, so the change would only be visible in the GA SDK/BCL assemblies.
The new compiler will still be able to consume extensions produced by the RC1 compiler: when loading metadata symbols, the unmangling is optional (if there is no arity suffix in the metadata name, we just use the whole metadata name as the name).
Given that only the compiler and docIDs make use of grouping and marker types, there would be no binary breaking change. Only implementation methods are referenced in IL, and those are unaffected by the change.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

and marker

Consider dropping marker types, they are not affected #Closed


# Alternative proposals

We also brainstormed a design where docIDs for extensions would be produced by taking `ExtensionGroupingName` and `ExtensionMarkerName`, would strip any arity suffix (to deal with metadata from another tool), then would proceed as usual (add an arity suffix.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

and ExtensionMarkerName

Consider dropping marker types, they are not affected #Closed


## Metadata names and metadata loading
The C# and VB compilers generally appends the arity suffix for generic types, to make the metadata name for a named type. There's some exceptions (notably EE named type symbols).
For extension grouping and marker types, we use the grouping and marker names as-is, without appending a suffix. The grouping and marker names are the metadata names.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

and marker types

Consider dropping marker types, they are not affected #Closed


## Metadata names and metadata loading
The C# and VB compilers generally appends the arity suffix for generic types, to make the metadata name for a named type. There's some exceptions (notably EE named type symbols).
For extension grouping and marker types, we use the grouping and marker names as-is, without appending a suffix. The grouping and marker names are the metadata names.
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

The grouping and marker names are the metadata names.

Consider dropping this sentence entirely. #Closed

When loading types from metadata, the C# and VB compilers remove the arity suffix when it matches the arity found in metadata (see `MetadataHelpers.UnmangleMetadataNameForArity`).

This means that we can load a type whose name doesn't include a suffix.

Copy link
Contributor

@AlekseyTs AlekseyTs Sep 13, 2025

Choose a reason for hiding this comment

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

Current compiler's behavior is a proof of that because right now it has to load grouping types without suffix. #ByDesign

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Sep 13, 2025

Done with review pass (commit 6) #Closed

@jcouv jcouv changed the title Propose change for metadata names of grouping and marker types Propose change for metadata names of grouping types Sep 15, 2025

We're proposing to update the metadata design to include arity suffix in the metadata names for grouping types.
The metadata name for grouping type would be mangled from the `ExtensionGroupingName`.
`ExtensionGroupingName` should reflect names of the emitted grouping typs from language perspective, not its emitted names.
Copy link
Member

@jjonescz jjonescz Sep 15, 2025

Choose a reason for hiding this comment

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

Suggested change
`ExtensionGroupingName` should reflect names of the emitted grouping typs from language perspective, not its emitted names.
`ExtensionGroupingName` should reflect names of the emitted grouping types from language perspective, not its emitted names.
``` #Pending


# Alternative proposals

We also brainstormed a design where docIDs for extensions would be produced by taking `ExtensionGroupingName`, would strip any arity suffix (to deal with metadata from another tool), then would proceed as usual (add an arity suffix.
Copy link
Member

@jjonescz jjonescz Sep 15, 2025

Choose a reason for hiding this comment

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

Suggested change
We also brainstormed a design where docIDs for extensions would be produced by taking `ExtensionGroupingName`, would strip any arity suffix (to deal with metadata from another tool), then would proceed as usual (add an arity suffix.
We also brainstormed a design where docIDs for extensions would be produced by taking `ExtensionGroupingName`, would strip any arity suffix (to deal with metadata from another tool), then would proceed as usual (add an arity suffix).
``` #Pending

# Proposal

We're proposing to update the metadata design to include arity suffix in the metadata names for grouping types.
The metadata name for grouping type would be mangled from the `ExtensionGroupingName`.
Copy link
Member

@jjonescz jjonescz Sep 15, 2025

Choose a reason for hiding this comment

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

What does it mean that metadata name would be mangled from ExtensionGroupingName? As I understand from the examples, the metadata name would be just ExtensionGroupingName plus the arity suffix appended. #Pending

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, mangling means adding an arity suffix



**If we don't include an arity suffix**, then:
- docIDs produced from VB symbols on extension metadata will diverge from those produce from C# symbols. VB doesn't have the concept of extension, so will have regular handling for types (which include an arity suffix)
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 15, 2025

Choose a reason for hiding this comment

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

produce

Typo? "produced" #Closed

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- docIDs produced from VB symbols on extension metadata will diverge from those produce from C# symbols. VB doesn't have the concept of extension, so will have regular handling for types (which include an arity suffix)
- docIDs produced from VB symbols on extension metadata will diverge from those produced from C# symbols. VB doesn't have the concept of extension, so will have regular handling for types (which include an arity suffix)


# Proposal

We're proposing to update the metadata design to include arity suffix to the `ExtensionGroupingName`
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 15, 2025

Choose a reason for hiding this comment

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

to include arity suffix to the ExtensionGroupingName

It feels like this contradicts the next sentence. This now reads as ExtensionGroupingName going to match metadata name. Then there is this sentence below: "Then we'd produce the docIDs as described above, by appending an arity suffix to ExtensionGroupingName ..."
Why would we need to add suffix if we already added it?

I think the previous wording of this sentence was fine, we just needed to not mention marker type. For example: "We're proposing to update the metadata design to include arity suffix in the metadata names for grouping types." #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Sep 15, 2025

Done with review pass (commit 9) #Closed

public void M() => throw; // extension member without implementation
}

public static void M(this int i) { } // implementation method
Copy link
Member

@333fred 333fred Sep 15, 2025

Choose a reason for hiding this comment

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

Type parameter? #Pending

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 10)

public void M() => throw; // extension member without implementation
}

public static void M(this int i) { } // implementation method
Copy link
Member

Choose a reason for hiding this comment

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

Consider doing a find/replace for this int and in this doc and fixing up all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks

@jcouv jcouv merged commit be0eec4 into main Sep 17, 2025
1 check passed
@jcouv jcouv deleted the jcouv-patch-5 branch September 17, 2025 03:45
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.

4 participants