-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Support enum values in substitution XML #131663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
229e802
Support enum values in substitutions
sbomer 3f671cf
Validate enum field substitutions after trimming
sbomer d3cb501
Verify linked enum field substitutions exactly
sbomer 633ebdc
Limit enum numeric substitutions to Int32
sbomer 13e1e14
Skip enum substitutions in ILTrim tests
sbomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
116 changes: 116 additions & 0 deletions
116
src/tools/illink/test/Mono.Linker.Tests.Cases/Substitutions/EnumSubstitutions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
| using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
|
||
| namespace Mono.Linker.Tests.Cases.Substitutions | ||
| { | ||
| [ExpectedNoWarnings] | ||
| [SetupLinkerSubstitutionFile("EnumSubstitutions.xml")] | ||
| [IgnoreSubstitutions(false)] | ||
| [SkipKeptItemsValidation(By = Tool.NativeAot)] | ||
| public class EnumSubstitutions | ||
| { | ||
| [Kept] | ||
| [KeptMember("value__")] | ||
| [KeptBaseType(typeof(Enum))] | ||
| private enum SubstitutionValue | ||
| { | ||
| [Kept] | ||
| Initial, | ||
|
|
||
| [Kept] | ||
| ByName, | ||
|
|
||
| [Kept] | ||
| ByNumber, | ||
| } | ||
|
|
||
| [Kept] | ||
| private static readonly SubstitutionValue FieldByName = SubstitutionValue.Initial; | ||
|
|
||
| [Kept] | ||
| private static readonly SubstitutionValue FieldByNumber = SubstitutionValue.Initial; | ||
|
|
||
| public static void Main() | ||
| { | ||
| VerifyFieldByNameSubstitution(); | ||
| VerifyFieldByNumberSubstitution(); | ||
| MethodByName(); | ||
| MethodByNumber(); | ||
| } | ||
|
|
||
| [Kept] | ||
| [ExpectedInstructionSequence(new[] { | ||
| "nop", | ||
| "ldsfld Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions/SubstitutionValue Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions::FieldByName", | ||
| "ldc.i4.1", | ||
| "ceq", | ||
| "ldc.i4.0", | ||
| "ceq", | ||
| "stloc.0", | ||
| "ldloc.0", | ||
| "brfalse.s il_10", | ||
| "ret", | ||
| })] | ||
| private static void VerifyFieldByNameSubstitution() | ||
| { | ||
| if (FieldByName != SubstitutionValue.ByName) | ||
| ReachableOnUnexpectedFieldByNameValue(); | ||
| } | ||
|
|
||
| private static void ReachableOnUnexpectedFieldByNameValue() | ||
| { | ||
| } | ||
|
|
||
| [Kept] | ||
| [ExpectedInstructionSequence(new[] { | ||
| "nop", | ||
| "ldsfld Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions/SubstitutionValue Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions::FieldByNumber", | ||
| "ldc.i4.2", | ||
| "ceq", | ||
| "ldc.i4.0", | ||
| "ceq", | ||
| "stloc.0", | ||
| "ldloc.0", | ||
| "brfalse.s il_10", | ||
| "ret", | ||
| })] | ||
| private static void VerifyFieldByNumberSubstitution() | ||
| { | ||
| if (FieldByNumber != SubstitutionValue.ByNumber) | ||
| ReachableOnUnexpectedFieldByNumberValue(); | ||
| } | ||
|
|
||
| private static void ReachableOnUnexpectedFieldByNumberValue() | ||
| { | ||
| } | ||
|
|
||
| [Kept] | ||
| [ExpectedInstructionSequence(new[] { | ||
| "ldc.i4 0x1", | ||
| "ret", | ||
| })] | ||
| [ExpectedLocalsSequence(new string[0])] | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static SubstitutionValue MethodByName() | ||
| { | ||
| return SubstitutionValue.Initial; | ||
| } | ||
|
|
||
| [Kept] | ||
| [ExpectedInstructionSequence(new[] { | ||
| "ldc.i4 0x2", | ||
| "ret", | ||
| })] | ||
| [ExpectedLocalsSequence(new string[0])] | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static SubstitutionValue MethodByNumber() | ||
| { | ||
| return SubstitutionValue.Initial; | ||
| } | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/tools/illink/test/Mono.Linker.Tests.Cases/Substitutions/EnumSubstitutions.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <linker> | ||
| <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
| <type fullname="Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions"> | ||
| <field name="FieldByName" value="ByName" /> | ||
| <field name="FieldByNumber" value="2" /> | ||
| <method signature="Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions/SubstitutionValue MethodByName()" body="stub" value="ByName" /> | ||
| <method signature="Mono.Linker.Tests.Cases.Substitutions.EnumSubstitutions/SubstitutionValue MethodByNumber()" body="stub" value="2" /> | ||
| </type> | ||
| </assembly> | ||
| </linker> |
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.
Uh oh!
There was an error while loading. Please reload this page.