-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Support devirtualization for virtual methods that require an instantiating stub #128702
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
hez2010
wants to merge
24
commits into
dotnet:main
Choose a base branch
from
hez2010:devirt-instantiating-stub-coreclr
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.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
61a278f
Devirtualize virtual methods that require an instantiating stub
hez2010 f01f4f4
R2R support
hez2010 b42c291
Bail shared MT for generic DIM as well
hez2010 b96fc2e
Stop returning an instantiating stub
hez2010 de840c2
Nit
hez2010 181e88e
Nit 2
hez2010 9331cc1
Remove redundant empty line
hez2010 f635686
Generic DIM devirt for NativeAOT
hez2010 5da42c5
Meh
hez2010 66c8d6a
More NativeAOT support
hez2010 152c44a
Address an assertion
hez2010 466ba2c
Use IsSharedByGenericMethodInstantiations
hez2010 dca1834
Add a couple of tests
hez2010 2582ba6
Address test name collisions
hez2010 800aa20
Fix crossgen2 not producing a const lookup
hez2010 a5c4574
Merge branch 'main' into devirt-instantiating-stub-coreclr
hez2010 31ff006
Fix NativeAOT build
hez2010 645e5dd
Pass a type dictionary fixup when the method doesn't have an instanti…
hez2010 1f2aacc
Nit
hez2010 cad1140
More fixes to AOT
hez2010 0c7102a
Use a better helper
hez2010 8f02750
Minor refactor
hez2010 e27aba9
Handle unboxing stub
hez2010 b77ad2d
Bail out unboxing stub in R2R for now
hez2010 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
Some comments aren't visible on the classic Files Changed page.
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
36 changes: 36 additions & 0 deletions
36
...sts/Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_github39419.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,36 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| interface IM<T> | ||
| { | ||
| bool UseDefaultM { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => true; } | ||
| ValueTask M(T instance) => throw new NotImplementedException("M must be implemented if UseDefaultM is false"); | ||
| static ValueTask DefaultM(T instance) | ||
| { | ||
| return default; | ||
| } | ||
| } | ||
|
|
||
| struct M : IM<int> { } | ||
|
|
||
| public static class Program | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var m = new M(); | ||
| if (((IM<int>)m).UseDefaultM) | ||
| { | ||
| IM<int>.DefaultM(42); | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| ((IM<int>)m).M(42); | ||
| } | ||
| throw new UnreachableException(); | ||
|
hez2010 marked this conversation as resolved.
hez2010 marked this conversation as resolved.
hez2010 marked this conversation as resolved.
hez2010 marked this conversation as resolved.
|
||
| } | ||
|
hez2010 marked this conversation as resolved.
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
...Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_github39419.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
26 changes: 26 additions & 0 deletions
26
src/tests/Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_inline.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,26 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| interface I<T> where T : IComparable<T> | ||
| { | ||
| T GetAt(int i, T[] tx) => tx[i]; | ||
| } | ||
|
|
||
| class C : I<string> | ||
| { | ||
| } | ||
|
|
||
| public static class Program | ||
| { | ||
| private static string[] tx = new string[] { "test" }; | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| I<string> c = new C(); | ||
| var dcs = c.GetAt(0, tx); | ||
| Assert.Equal("test", dcs); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...ests/Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_inline.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
31 changes: 31 additions & 0 deletions
31
src/tests/Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_simple.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,31 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
hez2010 marked this conversation as resolved.
hez2010 marked this conversation as resolved.
hez2010 marked this conversation as resolved.
|
||
|
|
||
| interface I<T> | ||
| { | ||
| string DefaultTypeOf() => typeof(T).Name; | ||
| } | ||
|
|
||
| class Dummy { } | ||
|
|
||
| class C : I<string>, I<object>, I<Dummy> | ||
| { | ||
| string I<Dummy>.DefaultTypeOf() => "C.Dummy"; | ||
| } | ||
|
|
||
| public static class Program | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var c = new C(); | ||
| var dcs = ((I<string>)c).DefaultTypeOf(); | ||
| Assert.Equal("String", dcs); | ||
| var dos = ((I<object>)c).DefaultTypeOf(); | ||
| Assert.Equal("Object", dos); | ||
| var dds = ((I<Dummy>)c).DefaultTypeOf(); | ||
| Assert.Equal("C.Dummy", dds); | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
...ests/Loader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_simple.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
24 changes: 24 additions & 0 deletions
24
...oader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_singlenongeneric.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,24 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| interface I | ||
| { | ||
| string DefaultTypeOf() => typeof(string).Name; | ||
| } | ||
|
|
||
| class C : I | ||
| { | ||
| } | ||
|
|
||
| public static class Program | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var c = new C(); | ||
| var dcs = ((I)c).DefaultTypeOf(); | ||
| Assert.Equal("String", dcs); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...r/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_singlenongeneric.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
25 changes: 25 additions & 0 deletions
25
...oader/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_singleoverriding.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,25 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| interface I<T> | ||
| { | ||
| string DefaultTypeOf() => typeof(T).Name; | ||
| } | ||
|
|
||
| class C : I<string> | ||
| { | ||
| public string DefaultTypeOf() => "C.String"; | ||
| } | ||
|
|
||
| public static class Program | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var c = new C(); | ||
| var dcs = ((I<string>)c).DefaultTypeOf(); | ||
| Assert.Equal("C.String", dcs); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...r/classloader/DefaultInterfaceMethods/devirtualization/dim_devirt_singleoverriding.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.