Skip to content

[3.0] Rework naming system#2565

Open
Exanite wants to merge 155 commits intodotnet:develop/3.0from
Exanite:feature/rework-naming-system
Open

[3.0] Rework naming system#2565
Exanite wants to merge 155 commits intodotnet:develop/3.0from
Exanite:feature/rework-naming-system

Conversation

@Exanite
Copy link
Copy Markdown
Member

@Exanite Exanite commented Apr 10, 2026

Summary of the PR

This PR combines my 3 previous naming-related PRs into a single PR.
This is because the 3 PRs contain interdependent changes and should be merged as a single unit.
That said, each of the 3 PRs focus on different aspects of the naming system and serve as supplementary documentation for the different changes.

Related issues, Discord discussions, or proposals

PRs contained by this PR:

Discord thread where I noted down my thoughts and decisions: https://discord.com/channels/521092042781229087/1485943448069738608

Further Comments

This PR does not introduce any new changes on top of the changes made in the 3 contained PRs.
However, prefer reviewing the diff through this PR since this is the PR that is intended to be merged.

Exanite added 30 commits March 24, 2026 05:59
…ld used by other bindings

The default acronym threshold was changed during #29, which was merged as part of dotnet#2503.
Considering we decided to follow Microsoft's Framework Design Guidelines (acronym threshold of 2) for the bindings and rest of the API, might as well be consistent here.
This lets us handle prefixing and prettification separately, which notably is important if we add prefixes after prettification.
We want to prefix the final name, not the intermediate name in this case.
This no longer makes sense to keep and enabling features by baseline version seems fiddly.
If we need to toggle features for newer versions, we can explicitly add a boolean config option.
Kinda a cop out decision, but it keeps thing simple (and thus maintainable) and implementing it fully seems overkill for what we need.
This is because we no longer output the separating underscore in ExtractNestedTyping
…nvention

Note that the goal is to eventually remove the name overrides for the `EFXEAXREVERBPROPERTIESflLateReverbPan` and `-Delegate` cases entirely.
This is because these are theoretically possible to handle automatically and the reason it doesn't work is due to an edge case interaction with the name override system.

See the "Tasks" section here for more info: dotnet#2555
Exanite added 21 commits April 8, 2026 12:59
… and update test cases to reflect expected behavior
I expected this to be an issue *eventually*, but apparently it also affects the SDL output already.
This is probably because SDL has multiple overloads of the SDL_main method, which my test case does not test for.
This new snapshot matches the expected output that I wrote in the comments earlier. I just forgot to update the snapshot.
… update test to indicate that one level of scoping is now supported
Copy link
Copy Markdown
Member Author

@Exanite Exanite left a comment

Choose a reason for hiding this comment

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

Self code review complete. The review comments I added provide additional context on the changes I made, but the code itself should make sense without them.


public BufferCallbackSOFT(delegate* unmanaged<void*, void*, int, int> ptr) => Pointer = ptr;

public BufferCallbackSOFT(BufferCallbackDelegateSOFT proc) =>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed to match my decision here: https://discord.com/channels/521092042781229087/1485943448069738608/1487577229121818766

In short, this reordering is because -Delegate is a variant or part of an existing type, similar to how inline array structs are part of their parent struct.

Notably, handle structs are named differently (BufferHandleEXT). This is because the -Handle suffix is a modification to an existing type.

This is a rule that we can consistently follow and also improves discoverability in IDEs since extensions to a type share a common prefix.

name switch
{
nameof(ChangeNamespace) => typeof(ChangeNamespace),
nameof(AddApiProfiles) => typeof(AddApiProfiles),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I alphabetically sorted the names here. This should be easier to read through and cause less diff noise in the future. Even if we forget to sort it when adding new names, sorting it again won't cause as much noise as the first sort.

/// <param name="type">The type syntax.</param>
/// <returns>The discriminator string.</returns>
public static string DiscrimStr(SyntaxTokenList? toks, TypeSyntax? type) =>
public static string GetMethodDiscriminator(SyntaxTokenList? toks, TypeSyntax? type) =>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed this because I always had to read the name twice to figure out what it meant. This should help with skimming the code.

/// <para/>
/// See <see cref="TransformHandles"/> for applying further transformations.
/// </summary>
public class ExtractHandles(ILogger<ExtractHandles> logger) : Mod
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This mod is effectively a cut and paste from TransformHandles.
This is part of my move to separate extraction/type creation from type transformation.

Originally, this was because I thought this was needed for better nested struct handling, but it turned out unnecessary. I kept it because it makes the codebase cleaner.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note I removed the AssumeMissingTypesOpaque config option when moving the code to this mod. This is because the false value for the config option is equivalent to disabling the entire mod.

}

var iden = $"{node.Identifier}_{match.Groups[1].Value}";
var iden = $"{node.Identifier}{match.Groups[1].Value}";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The underscore here is no longer necessary because the affix metadata lets us distinguish the two parts during prettification.


namespace Silk.NET.SilkTouch.UnitTests.Naming;

public class NameTrimmerTests : NameTrimmer
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test cases in this class were ported over to the new IdentifySharedPrefixTests class.

/// in favor of calling <see cref="NameUtils.PrefixIfStartsWithNumber"/> separately.
/// </summary>
[Theory]
// C# identifiers cannot start with numbers
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tests in this file were updated to match the change I made to Prettify (which now processes name fragments instead of full names).

"PrettifyNames": {
"Affixes": {
"SharedPrefix": {
"Remove": true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For SharedPrefix, we can either configure it as Remove or as a Discriminator. Both have the same effect until names conflict and no other discriminators are available. Fortunately, we no names conflict in this way right now and I assume this case will be very rare, so I'm defaulting to Remove.

"ContainerType": "GL"
},
"ContainerType": "GL",
"SeparableTargetEXT": "GL"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is new override is required since my new name underscorer/splitter handles 2D differently. It outputs 2_D instead of 2D since 2_D is arguably more consistent. I explain why here: https://discord.com/channels/521092042781229087/1485943448069738608/1489457083857506336

It's easier to handle the common case consistently while handling edge cases using overrides.

"ALDEBUGPROCEXT": "DebugProcEXT",
"ALDEBUGPROCEXTDelegate": "DebugProcDelegateEXT",
"LPALFOLDBACKCALLBACK": "FoldbackCallback",
"LPALFOLDBACKCALLBACKDelegate": "FoldbackCallbackDelegate"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Most of these overrides are no longer necessary because of referenced affixes. Overrides to the referenced name automatically propagate to names that reference them.

@Exanite Exanite marked this pull request as ready for review April 12, 2026 16:28
@Exanite Exanite requested a review from a team as a code owner April 12, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants