Skip to content

Commit f71a545

Browse files
committed
Add initial implementation for async method and project configuration
1 parent 19a3c35 commit f71a545

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

temp_csharp/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Runtime.CompilerServices;
2+
3+
public class Test
4+
{
5+
public async Task<int> AsyncMethod()
6+
{
7+
await Task.Delay(1000);
8+
9+
return 42;
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# GitHub Copilot Instructions for csharp_asyncruntime.csproj
2+
3+
This project uses the new async/await patterns as specified in the .NET runtime design document:
4+
5+
https://github.com/dotnet/runtime/blob/main/docs/design/specs/runtime-async.md
6+
7+
To use the feature, a number of flags need to be enabled:
8+
9+
- The project must target net10.0 (note: running on net10.0 is not sufficient, it must compile against net10.0 to see the value)
10+
- <EnablePreviewFeatures>true</EnablePreviewFeatures> must be set in the project file
11+
- <Features>$(Features);runtime-async=on</Features> must be set in the project file
12+
- When running, the environment variable DOTNET_RuntimeAsync=1 must be set
13+
14+
This project has a special target called "Decompile" that will decompile the emitted IL back to C# code so you can see the emitted IL patterns.
15+
16+
The output will end up in `artifacts\bin\csharp_asyncruntime\Debug\net10.0\csharp_asyncruntime.il`.
17+
18+
Notably, you will see the new async IL patterns as specified in the design document.
19+
20+
- `AsyncMethod() cil managed async` indicates that the method is async.
21+
- Async methods also do not have matching return type conventions as sync methods. For sync methods, the stack should contain a value convertible to the stated return type before the ret instruction. For async methods, the stack should be empty in the case of Task or ValueTask, or the type argument in the case of Task<T> or ValueTask<T>.
22+
23+
Use this project as a reference for how the IL should look when emitting async methods from C# code.
24+
25+
### Relevant commands
26+
27+
`dotnet build` - builds the project
28+
`dotnet run` - runs the project
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net10.0</TargetFrameworks>
5+
<RootNamespace>csharp_asyncruntime</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<EnablePreviewFeatures>true</EnablePreviewFeatures>
9+
<Features>$(Features);runtime-async=on</Features>
10+
<NoWarn>$(NoWarn);SYSLIB5007</NoWarn>
11+
</PropertyGroup>
12+
13+
14+
<PropertyGroup>
15+
<ILDasmPath>C:\Users\jimmy\.nuget\packages\runtime.win-x64.microsoft.netcore.ildasm\10.0.0-rc.2.25502.107\runtime.win-x64.microsoft.netcore.ildasm.10.0.0-rc.2.25502.107\runtimes\win-x64\native\ildasm.exe</ILDasmPath>
16+
17+
</PropertyGroup>
18+
19+
<Target Name="Decompile" AfterTargets="AfterBuild">
20+
<Exec Command="&quot;$(ILDasmPath)&quot; &quot;$(TargetDir)$(TargetFileName)&quot; /out:&quot;$(TargetDir)$(TargetName).il&quot;" />
21+
22+
</Target>
23+
24+
</Project>

0 commit comments

Comments
 (0)