Skip to content

[3.0] Replace NameTrimmer with equivalent IdentifySharedPrefixes mod#2557

Draft
Exanite wants to merge 43 commits intodotnet:develop/3.0from
Exanite:feature/identify-shared-prefixes-mod
Draft

[3.0] Replace NameTrimmer with equivalent IdentifySharedPrefixes mod#2557
Exanite wants to merge 43 commits intodotnet:develop/3.0from
Exanite:feature/identify-shared-prefixes-mod

Conversation

@Exanite
Copy link
Copy Markdown
Member

@Exanite Exanite commented Mar 31, 2026

Summary of the PR

(WIP)

This PR chains off of #2555 and focuses on rewriting the NameTrimmer class as a new IdentifySharedPrefixes mod with equivalent functionality. The goal is to keep all outputs the same while removing edge cases and generally just making the code easier to understand.

Note: Part of the reason this PR chains off of #2555 is because #2555 actually needs some of the changes here to fully work correctly. #2555 can be merged as is, but one unit test has to be commented out and a non-critical feature will be missing.

Related issues, Discord discussions, or proposals

This is the conversation in January when this change was briefly discussed: https://discord.com/channels/521092042781229087/587346162802229298/1457864604951777441

Further Comments

Tasks

  • Add a IdentifySharedPrefixes mod that identifies shared prefixes and uses the name affix system to annotate those prefixes.
    • Ideally rewrite to avoid the "3 pass" logic. I have no idea how it works still.
    • Ideally avoid using Humanizer and use the new NameSplitter code for consistency (especially since we have thorough test coverage for this code)
  • Remove prefix trimming special casing from PrettifyNames
    • Visitor
    • Prettify-only pipeline
  • Rewrite rest of trimming+prettify pipeline as sequential INameProcessors
    • This should include the name conflict resolution code, since that's currently done as a step right after the name processors run.
    • This will act as the main and only code path. Currently we have two code paths (which technically was 3 before I removed another one during [3.0] Improve handling of nested struct names and affixes #2555).
    • Remove the name container isolation and just provide all names together. If name processors need the isolation, we still provide the container names and container members separately and can implement the old behavior as needed, but restricting access to all names is unnecessary and can actually lead to incorrect behavior.
  • Change INameProcessor to be an interface private to PrettifyNames
    • We can change this later if required, but I currently don't see a point to exposing it. There are plenty of ways to configure the name transformation process already through ways that are more declarative and configurable by the user.
  • Add unit tests documenting all common and known edge cases for IdentifySharedPrefixes
    • This is an initial list. I need to verify this behavior against the old behavior.
    • Simple shared prefix, no configured prefix hint
    • Simple shared prefix, with shorter prefix hint (the hint should be preferred)
    • Case where a bit more than half of the names share a prefix (or whatever the breakpoint is)
    • Multiple shared prefixes, with multiple configured hints
    • Case where a prefix is somewhat shared, but not quite due to capitalization/underscores/etc
      • Pretty sure we should normalize here, then identify accordingly
      • Also ensure that we don't naively use the "shared" prefix in the NameAffix attribute. We use the shared prefix to determine the actual prefix, which is going to be a variation of the shared prefix in this case.
    • Migrate the old test cases over from the NameTrimmer tests
      • This should cover some edge cases such as trimming names into nothing (due to a name being a prefix of another name)
  • Regenerate all bindings using Windows and ensure no changes to output

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 7 commits March 30, 2026 20:23
This covers cases where there are multiple levels of nested structs, such as in SDL:
GamepadBinding contains GamepadBindingInput which contains GamepadBindingInputAxis
This is just to hint that these structs come from SDL
MissingReferencedAffix_Throws currently fails, but seems to be an unrelated issue.
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.

1 participant