-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add test for runtime async and update linker handling of method body #120683
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
+144
−7
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f11c68e
Add test for runtime async and update linker handling of method body
jtschuster 9598a85
Update src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCa…
jtschuster 31db132
Merge branch 'main' into RuntimeAsyncILLink
jtschuster 3e56421
Ignore test on NativeAOT
jtschuster cd12016
Merge branch 'RuntimeAsyncILLink' of https://github.com/jtschuster/ru…
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
107 changes: 107 additions & 0 deletions
107
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.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,107 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Helpers; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.DataFlow | ||
{ | ||
[SkipKeptItemsValidation] | ||
[SetupCompileArgument("/features:runtime-async=on")] | ||
[SetupCompileArgument("/nowarn:SYSLIB5007")] | ||
public class RuntimeAsyncMethods | ||
{ | ||
public static async Task Main() | ||
{ | ||
await BasicRuntimeAsyncMethod(); | ||
await RuntimeAsyncWithDataFlowAnnotations(null); | ||
await RuntimeAsyncWithCapturedLocalDataFlow(); | ||
await RuntimeAsyncWithMultipleAwaits(); | ||
await RuntimeAsyncWithReassignment(true); | ||
await RuntimeAsyncReturningAnnotatedType(); | ||
await RuntimeAsyncWithCorrectParameter(null); | ||
await RuntimeAsyncWithLocalAll(); | ||
} | ||
|
||
static async Task BasicRuntimeAsyncMethod() | ||
{ | ||
await Task.Delay(1); | ||
Console.WriteLine("Basic runtime async"); | ||
} | ||
|
||
[ExpectedWarning("IL2067", "type", nameof(DataFlowTypeExtensions.RequiresAll), nameof(RuntimeAsyncWithDataFlowAnnotations))] | ||
static async Task RuntimeAsyncWithDataFlowAnnotations([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) | ||
{ | ||
await Task.Delay(1); | ||
type.RequiresAll(); | ||
} | ||
|
||
[ExpectedWarning("IL2072", nameof(DataFlowTypeExtensions.RequiresAll), nameof(GetWithPublicMethods))] | ||
static async Task RuntimeAsyncWithCapturedLocalDataFlow() | ||
{ | ||
Type t = GetWithPublicMethods(); | ||
await Task.Delay(1); | ||
t.RequiresAll(); | ||
} | ||
|
||
[ExpectedWarning("IL2072", nameof(DataFlowTypeExtensions.RequiresAll), nameof(GetWithPublicMethods))] | ||
static async Task RuntimeAsyncWithMultipleAwaits() | ||
{ | ||
Type t = GetWithPublicMethods(); | ||
await Task.Delay(1); | ||
t.RequiresPublicMethods(); | ||
await Task.Delay(1); | ||
t.RequiresAll(); | ||
} | ||
|
||
[ExpectedWarning("IL2072", nameof(DataFlowTypeExtensions.RequiresAll), nameof(GetWithPublicMethods))] | ||
[ExpectedWarning("IL2072", nameof(DataFlowTypeExtensions.RequiresAll), nameof(GetWithPublicFields))] | ||
static async Task RuntimeAsyncWithReassignment(bool condition) | ||
{ | ||
Type t = GetWithPublicMethods(); | ||
await Task.Delay(1); | ||
if (condition) | ||
{ | ||
t = GetWithPublicFields(); | ||
} | ||
await Task.Delay(1); | ||
t.RequiresAll(); | ||
} | ||
|
||
[ExpectedWarning("IL2106", nameof(RuntimeAsyncReturningAnnotatedType))] | ||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] | ||
static async Task<Type> RuntimeAsyncReturningAnnotatedType() | ||
{ | ||
await Task.Delay(1); | ||
return GetWithPublicMethods(); | ||
} | ||
|
||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] | ||
static Type GetWithPublicMethods() => null; | ||
|
||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] | ||
static Type GetWithPublicFields() => null; | ||
|
||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] | ||
static Type GetWithAllMembers() => null; | ||
|
||
static async Task RuntimeAsyncWithCorrectParameter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) | ||
{ | ||
type ??= GetWithAllMembers(); | ||
await Task.Delay(1); | ||
type.RequiresAll(); | ||
} | ||
|
||
static async Task RuntimeAsyncWithLocalAll() | ||
{ | ||
Type t = GetWithAllMembers(); | ||
await Task.Delay(1); | ||
t.RequiresAll(); | ||
} | ||
} | ||
} |
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
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.