Support enum values in substitution XML - #131663
Open
sbomer wants to merge 4 commits into
Open
Conversation
Allow ILLink to parse numeric enum values and NativeAOT to resolve names for int-backed enums. Add shared coverage for fields and stubbed method returns. Assisted-by: GitHub Copilot:gpt-5.6-sol code-review Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 77531f73-7423-457e-891c-705990f7e7af
Assisted-by: GitHub Copilot:gpt-5.6-sol [code-review] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 77531f73-7423-457e-891c-705990f7e7af
Assisted-by: GitHub Copilot:gpt-5.6-sol [code-review] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 77531f73-7423-457e-891c-705990f7e7af
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes enum-valued substitutions in ILLink.Substitutions.xml more consistent between ILLink (trimmer) and NativeAOT (ILCompiler) by accepting additional enum value forms, and adds regression coverage in both test suites.
Changes:
- ILLink: when substituting an enum value, fall back to parsing numeric strings using the enum’s underlying type.
- NativeAOT: for
int-backed enums, allow substitution values to be specified by enum member name (resolved to the member’s constant). - Tests: add a new substitutions test case and enable it in the NativeAOT trimming substitutions suite.
Show a summary per file
| File | Description |
|---|---|
| src/tools/illink/test/Mono.Linker.Tests.Cases/Substitutions/EnumSubstitutions.xml | New substitution XML covering enum member names and numeric values for fields and stubbed methods. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/Substitutions/EnumSubstitutions.cs | New linker test case asserting stubbed method IL for enum substitutions by name and number. |
| src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs | Extends enum substitution parsing to accept numeric values via underlying-type parsing. |
| src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCases/TestSuites.cs | Enables the new test case in the NativeAOT trimming substitutions suite. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BodySubstitutionParser.cs | Adds enum-member-name resolution for int-backed enums when creating substitutions. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 1
Assisted-by: GitHub Copilot:gpt-5.6-sol [code-review] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 77531f73-7423-457e-891c-705990f7e7af
Contributor
There was a problem hiding this comment.
Copilot's findings
Suppressed comments (1)
src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs:656
- The enum fallback currently only attempts numeric parsing when the underlying type is Int32. That doesn't match the stated goal of parsing numeric values using the enum's underlying type, and it means numeric substitutions will still fail for enums backed by byte/short/long/uint/etc (even though TryConvertValue already supports those primitive metadata types).
var underlyingType = typeDefinition.GetEnumUnderlyingType();
if (underlyingType.MetadataType == MetadataType.Int32)
return TryConvertValue(value, underlyingType, out result);
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
agocke
approved these changes
Jul 31, 2026
agocke
left a comment
Member
There was a problem hiding this comment.
LGTM, I think there are some ILTrim failures
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.
Fixes #131601
int-backed enums to use member names.Tests:
Mono.Linker.Tests.TestCases.All.SubstitutionsTestsMono.Linker.Tests.TestCases.All.Substitutions(NativeAOT)Note
This pull request was created with assistance from GitHub Copilot.