-
Notifications
You must be signed in to change notification settings - Fork 215
[RuntimeAsync] Fix support for pinvokes #2847
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // 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.Runtime.InteropServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Async2PInvoke | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| AsyncEntryPoint().Wait(); | ||
| } | ||
|
|
||
| private static async2 Task AsyncEntryPoint() | ||
| { | ||
| unsafe | ||
| { | ||
| Assert.Equal(5, GetFPtr()()); | ||
| } | ||
|
|
||
| await Task.Yield(); | ||
|
|
||
| unsafe | ||
| { | ||
| Assert.Equal(5, GetFPtr()()); | ||
| } | ||
|
|
||
| await Task.Yield(); | ||
|
|
||
| unsafe | ||
| { | ||
| Assert.Equal(5, GetFPtr()()); | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static unsafe delegate* unmanaged<int> GetFPtr() => &GetValue; | ||
|
|
||
| [UnmanagedCallersOnly] | ||
| private static int GetValue() => 5; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A thought: what should happen if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't checked, but I imagine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I checked. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.IL"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
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.
Do you plan to address this TODO or this is just a "good to have" comment?
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.
I do agree that relying on the presence of scratch is an arbitrary dependency that just happen to hold.
If creating on demand is not too hard, it would be better.
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.
I don't plan to address it here, this should rather be cleaned up upstream.
The frontend does ensure it:
runtimelab/src/coreclr/jit/flowgraph.cpp
Lines 2315 to 2322 in 4daa761
It's simply that this is a very long-term invariant that is error prone and which feels unnecessary to me.
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.
Exactly. Such dependencies have negative value by default. They must be justified by advantages or scenarios that they enable. If arranging a scratch block was difficult to do later, it could be a possible justification, but, as I understand, it is not the case.