-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix composite R2R token corruption for devirtualized async-variant callees #129053
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
+159
−1
Merged
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions
20
...ompiler.ReadyToRun.Tests/TestCases/RuntimeAsync/CompositeAsyncDevirtNonAsyncCalleeMain.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,20 @@ | ||
| // Runtime-async caller for the composite devirt regression test. Awaits non-runtime-async virtuals | ||
| // (in AsyncDevirtNonAsyncCalleeLib) that the JIT devirtualizes to the sealed receiver, requesting the | ||
| // callee's synthesized async-variant thunk. | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
|
|
||
| public static class CompositeAsyncDevirtNonAsyncCallee | ||
| { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static async Task AwaitInheritedValueTask(Holder h) | ||
| { | ||
| await h.Writer.CompleteValueTaskAsync(); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static async Task AwaitInheritedTask(Holder h) | ||
| { | ||
| await h.Writer.CompleteTaskAsync(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...iler.ReadyToRun.Tests/TestCases/RuntimeAsync/Dependencies/AsyncDevirtNonAsyncCalleeLib.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,23 @@ | ||
| // Helper for the composite runtime-async devirt regression test. Compiled WITHOUT runtime-async, so | ||
| // WriterBase's virtuals are classic methods that get an "async variant" thunk when a runtime-async | ||
| // caller in another module awaits them. ConcreteWriter is sealed and doesn't override, and Holder | ||
| // exposes it base-typed, so the caller late-devirtualizes to the inherited base method. | ||
| using System.Threading.Tasks; | ||
|
|
||
| public class WriterBase | ||
| { | ||
| public virtual ValueTask CompleteValueTaskAsync() => default; | ||
|
|
||
| public virtual Task CompleteTaskAsync() => Task.CompletedTask; | ||
| } | ||
|
|
||
| public sealed class ConcreteWriter : WriterBase | ||
| { | ||
| } | ||
|
|
||
| public sealed class Holder | ||
| { | ||
| private readonly ConcreteWriter _writer = new ConcreteWriter(); | ||
|
|
||
| public WriterBase Writer => _writer; | ||
| } |
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
58 changes: 58 additions & 0 deletions
58
src/tests/async/devirtualize-inherited-nonasync/devirtualize-inherited-nonasync.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,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| // A runtime-async caller awaits a devirtualized call to a NON-runtime-async virtual method that a | ||
| // sealed receiver inherits without overriding. Resolving the callee's synthesized async-variant thunk | ||
| // must unwrap it to the underlying method instead of indexing the thunk's small token table with the | ||
| // callee's real methoddef token; otherwise composite ReadyToRun compilation corrupts token resolution | ||
| // and crossgen2 aborts. | ||
| public class Async2DevirtualizeInheritedNonAsync | ||
| { | ||
| public class WriterBase | ||
| { | ||
| // Non-runtime-async virtuals with bodies: awaited from a runtime-async caller via a thunk. | ||
| [RuntimeAsyncMethodGeneration(false)] | ||
| public virtual ValueTask CompleteValueTaskAsync() => default; | ||
|
|
||
| [RuntimeAsyncMethodGeneration(false)] | ||
| public virtual Task CompleteTaskAsync() => Task.CompletedTask; | ||
| } | ||
|
|
||
| // Sealed and does NOT override: late devirtualization resolves to the inherited base methods. | ||
| public sealed class ConcreteWriter : WriterBase | ||
| { | ||
| } | ||
|
|
||
| public sealed class Holder | ||
| { | ||
| private readonly ConcreteWriter _writer = new ConcreteWriter(); | ||
|
|
||
| // Base-typed accessor over the sealed concrete type, so the exact receiver is only known via | ||
| // late devirtualization. | ||
| public WriterBase Writer => _writer; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task AwaitInheritedValueTask(Holder h) | ||
| { | ||
| await h.Writer.CompleteValueTaskAsync(); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task AwaitInheritedTask(Holder h) | ||
| { | ||
| await h.Writer.CompleteTaskAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var h = new Holder(); | ||
| AwaitInheritedValueTask(h).GetAwaiter().GetResult(); | ||
| AwaitInheritedTask(h).GetAwaiter().GetResult(); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/tests/async/devirtualize-inherited-nonasync/devirtualize-inherited-nonasync.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,5 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
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.