Skip to content

Support enum values in substitution XML - #131663

Open
sbomer wants to merge 4 commits into
dotnet:mainfrom
sbomer:enum-substitution
Open

Support enum values in substitution XML#131663
sbomer wants to merge 4 commits into
dotnet:mainfrom
sbomer:enum-substitution

Conversation

@sbomer

@sbomer sbomer commented Jul 31, 2026

Copy link
Copy Markdown
Member

Fixes #131601

  • Allow ILLink enum substitutions to use numeric values parsed as the enum underlying type.
  • Allow NativeAOT substitutions for int-backed enums to use member names.
  • Add shared field and stubbed-method coverage for named and numeric values, including exact linked IL validation.

Tests:

  • Mono.Linker.Tests.TestCases.All.SubstitutionsTests
  • Mono.Linker.Tests.TestCases.All.Substitutions (NativeAOT)

Note

This pull request was created with assistance from GitHub Copilot.

sbomer and others added 3 commits July 30, 2026 15:44
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
Copilot AI review requested due to automatic review settings July 31, 2026 18:28
@sbomer
sbomer requested a review from MichalStrehovsky as a code owner July 31, 2026 18:28
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jul 31, 2026
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jul 31, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs Outdated
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
Copilot AI review requested due to automatic review settings July 31, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 agocke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, I think there are some ILTrim failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

ILLink and ILC disagree about how to specify enum values in ILLink.Substitutions.xml

3 participants