Promote anonymous-name prefixes to consts with helper predicates#718
Merged
tannergooding merged 1 commit intoJul 13, 2026
Conversation
The generator checked scattered `__Anonymous*_` magic string prefixes inline across several files. Promote each distinct prefix to a `private const string` grouped near the top of `PInvokeGenerator.cs` and route the produce side (`GetAnonymousName`) through the shared `AnonymousNamePrefix` base so produce and consume share the same literals. Consts added: `AnonymousNamePrefix`, `AnonymousBasePrefix`, `AnonymousEnumPrefix`, `AnonymousFieldDeclPrefix`, `AnonymousRecordPrefix`. Helpers added: `IsAnonymousEnum` (4 call sites) and `IsAnonymousRecord` (2 call sites); single-use `FieldDecl`/`Base` checks use the const directly. Behavior-preserving: the literal string values are unchanged, so generated output is byte-identical. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
The generator checked scattered
__Anonymous*_magic string prefixes inline across several files. This promotes each distinct prefix to aprivate const stringand routes the produce side through a shared base const, so the produce and consume sides share the exact same literals.Consts added (grouped near the top of
PInvokeGenerator.cs):AnonymousNamePrefix = "__Anonymous"AnonymousBasePrefix = $"{AnonymousNamePrefix}Base_"AnonymousEnumPrefix = $"{AnonymousNamePrefix}Enum_"AnonymousFieldDeclPrefix = $"{AnonymousNamePrefix}FieldDecl_"AnonymousRecordPrefix = $"{AnonymousNamePrefix}Record_"The specific prefixes are built via compile-time const interpolation from the shared base, and
GetAnonymousNamenow emits$"{AnonymousNamePrefix}{kind}_..."so the produce side is tied to the same base literal.Helpers added (static, next to
GetAnonymousName):IsAnonymousEnum(string)-- 4 call sitesIsAnonymousRecord(string)-- 2 call sitesSingle-use
FieldDecl/Baseprefix checks reference the const directly rather than a one-off helper.Sites touched:
PInvokeGenerator.cs,PInvokeGenerator.Naming.cs,PInvokeGenerator.VisitDecl.cs,PInvokeGenerator.VisitStmt.cs.Behavior-preserving: the literal string values are unchanged, so generated output is byte-identical. Build is clean (0 warnings) and all 3708 golden-file tests pass with no expectation changes.