Repository navigation
JIT: Fix async analysis filter dataflow #132027
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // 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.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_132015 | ||
| { | ||
| [Fact] | ||
| public static void AssignInFilterIsVisibleAfterSuspension() | ||
| { | ||
| Assert.Equal("success", AssignInFilter().GetAwaiter().GetResult()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void AssignInNestedFinallyIsVisibleAfterSuspension() | ||
| { | ||
| Assert.Equal("success", AssignInNestedFinally().GetAwaiter().GetResult()); | ||
| Assert.Equal("success", AssignInNestedFinallyWithFilter().GetAwaiter().GetResult()); | ||
| } | ||
|
|
||
| // The filter assigns the exception variable, which must survive the | ||
| // suspension inside the handler. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task<string> AssignInFilter() | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("thrown"); | ||
| } | ||
| catch (Exception caught) when ((caught = new Exception("success")) != null) | ||
| { | ||
| await Task.Yield(); | ||
| return caught.Message; | ||
| } | ||
| } | ||
|
|
||
| // The nested finally runs during the second pass, before the handler is | ||
| // entered, so its assignment must survive the suspension in the handler. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task<string> AssignInNestedFinally() | ||
| { | ||
| string s = null; | ||
| try | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("thrown"); | ||
| } | ||
| finally | ||
| { | ||
| s = "success"; | ||
| } | ||
| } | ||
| catch (Exception) | ||
| { | ||
| await Task.Yield(); | ||
| return s ?? "<null>"; | ||
| } | ||
| } | ||
|
|
||
| // Same as above, but a filter runs before the nested finally, so the | ||
| // handler must not assume the value that the filter observed. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task<string> AssignInNestedFinallyWithFilter() | ||
| { | ||
| string s = null; | ||
| try | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("thrown"); | ||
| } | ||
| finally | ||
| { | ||
| s = "success"; | ||
| } | ||
| } | ||
| catch (Exception) when (s is null) | ||
| { | ||
| await Task.Yield(); | ||
| return s ?? "<null>"; | ||
| } | ||
| } | ||
| } |
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> |
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,72 @@ | ||
| // 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.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_132016 | ||
| { | ||
| private static readonly List<string> s_log = new List<string>(); | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| s_log.Clear(); | ||
| new Runtime_132016().M().GetAwaiter().GetResult(); | ||
|
|
||
| Assert.Equal(new[] { "outer", "outer", "inner", "inner", "outer", "inner" }, s_log); | ||
| } | ||
|
|
||
| private static bool Filter(Exception ex, bool result) | ||
| { | ||
| s_log.Add(ex.Message); | ||
| return result; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private async Task M() | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("outer"); | ||
| } | ||
| catch (Exception ex) when (Filter(ex, false)) | ||
| { | ||
| await Print(ex); | ||
| } | ||
| catch (Exception ex) when (Filter(ex, true)) | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("inner"); | ||
| } | ||
| catch (Exception ex2) when (Filter(ex2, false)) | ||
| { | ||
| await Print(ex); | ||
| await Print(ex2); | ||
| } | ||
| catch (Exception ex2) when (Filter(ex2, true)) | ||
| { | ||
| try | ||
| { | ||
| throw new Exception(); | ||
| } | ||
| catch | ||
| { | ||
| await Print(ex); | ||
| await Print(ex2); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task Print(Exception ex) | ||
| { | ||
| await Task.Yield(); | ||
| s_log.Add(ex.Message); | ||
| } | ||
| } |
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> |
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,74 @@ | ||
| // 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.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_132017 | ||
| { | ||
| private static readonly List<string> s_log = new List<string>(); | ||
| private static int s_calls; | ||
|
|
||
| // The nested catch starts this task without awaiting it; keep it around so | ||
| // that the test can wait for it deterministically. | ||
| private static Task s_pending; | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| s_log.Clear(); | ||
| s_calls = 0; | ||
| s_pending = null; | ||
|
|
||
| var test = new Runtime_132017(); | ||
| test.M(false).GetAwaiter().GetResult(); | ||
| test.M(true).GetAwaiter().GetResult(); | ||
| s_pending.GetAwaiter().GetResult(); | ||
|
jakobbotsch marked this conversation as resolved.
|
||
|
|
||
| Assert.Equal(new[] { "filter", "filter", "outer", "filter", "outer" }, s_log); | ||
| Assert.Equal(2, s_calls); | ||
| } | ||
|
|
||
| private static bool Filter(bool result) | ||
| { | ||
| s_log.Add("filter"); | ||
| return result; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private async Task M(bool first) | ||
| { | ||
| try | ||
| { | ||
| throw new Exception("outer"); | ||
| } | ||
| catch (Exception ex) when (Filter(first)) | ||
| { | ||
| await Print(ex); | ||
| } | ||
| catch (Exception ex) when (Filter(true)) | ||
| { | ||
| try | ||
| { | ||
| await Task.Yield(); | ||
| throw new Exception(); | ||
| } | ||
| catch | ||
| { | ||
| s_pending = Print(ex); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static async Task Print(Exception ex) | ||
| { | ||
| string message = ex.Message; | ||
| s_log.Add(message); | ||
| await Task.Yield(); | ||
| s_calls++; | ||
| } | ||
| } | ||
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.