Repository navigation
Fix ReadyToRun generic parameter symbol collisions #136191
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
Open
jtschuster
wants to merge
7
commits into
dotnet:main
Choose a base branch
from
jtschuster:fix/runtime-determined-generic-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−51
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
080c9af
Use generic parameter identity in runtime-determined type names
jtschuster 8bab801
Simplify generic parameter collision R2R test
jtschuster 0dc8d21
Move runtime-determined identity into name mangling
jtschuster 9d06697
Use Log10 instead of CountDigits
jtschuster 19f88e2
Share Log10-based digit counting helper
jtschuster fa4768e
Use UTF-8 TryFormat for runtime-determined prefixes
jtschuster 02aad97
Merge branch 'main' into fix/runtime-determined-generic-names
jtschuster 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
35 changes: 35 additions & 0 deletions
35
.../aot/ILCompiler.ReadyToRun.Tests/TestCases/VirtualMethodGenerics/GenericParameterNames.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,35 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| public static class GenericParameterNames | ||
| { | ||
| public static bool CompareUnicodeProperties() | ||
| { | ||
| var value = new { \u3042 = "", \u3044 = "" }; | ||
| return value.Equals(new { \u3042 = "a", \u3044 = "b" }); | ||
| } | ||
|
|
||
| public static bool CompareUnderscoreProperties() | ||
| { | ||
| var value = new { a_b = "", a\uFF3Fb = "" }; | ||
| return value.Equals(new { a_b = "a", a\uFF3Fb = "b" }); | ||
| } | ||
|
|
||
| public static object[] GetComparers() => | ||
| GenericParameters<string, object>.GetComparers<string, object>(); | ||
| } | ||
|
|
||
| public static class GenericParameters<\u3042, \u3044> | ||
| { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static object[] GetComparers<\u3046, \u3048>() => | ||
| [ | ||
| EqualityComparer<\u3042>.Default, | ||
| EqualityComparer<\u3044>.Default, | ||
| EqualityComparer<\u3046>.Default, | ||
| EqualityComparer<\u3048>.Default, | ||
| ]; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will come up with the same prefix for e.g.
List<__Canon>andDictionary<__Canon, __Canon>. The RuntimeDeterminedType for the first argument is rawCanonType == __Canon for both, but detailsType is T (ofList<>) in one case and TKey (ofDictionary<,>in the other).This would need the extension I mentioned to do properly.
Based on what Copilot says, this is not a problem for ReadyToRun because it has a custom comparer for RuntimeDeterminedTypes that ignores where the generic parameter comes from and ends up comparing these two equal even though they're not equal in type system sense.
It is also not a problem for native AOT because it doesn't use mangled names for these.
However, the implementation is still wrong.
We should either make it correct, or continue doing weird things on the ReadyToRun side and e.g. also do custom mangling for these that takes into consideration the equivalency rules.