dotnet / dotnet/fsharp

net10.0: Support MethodImpl.Async

Open
#19,056 9 comments 6 reactions 0 assignees View on GitHub
Area-Compiler-ImportAndInterop Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

## Context

👋 .NET 10 is bringing support for [Runtime-Async](https://github.com/dotnet/runtime/blob/main/docs/design/specs/runtime-async.md). I started playing around with it in an [IcedTasks PR](https://github.com/TheAngryByrd/IcedTasks/pull/62). However, I noticed some of benchmarks being off considerably. One of the requirements is having `MethodImplOptions.Async` set. I manually added the atttribute, but it doesn't get written to the IL.

**Repro steps**

Provide the steps required to reproduce the problem:

```fsharp
[]
let fsharp_tenBindAsync_TaskBuilderRuntime () =
IcedTasks.Polyfill.TasksRuntime.TaskBuilder.task {
do! taskYield ()
return 100
}
```

see that the compiled DLL doesn't contain it in the IL/decompiled c#

```csharp

public static Task fsharp_tenBindAsync_TaskBuilderRuntime()
{
YieldAwaitable.YieldAwaiter awaiter1 = Task.Yield().GetAwaiter();
if (!awaiter1.IsCompleted)
AsyncHelpers.UnsafeAwaitAwaiter(awaiter1);
awaiter1.GetResult();
ValueTaskAwaiter awaiter11 = ValueTask.FromResult(100).GetAwaiter();
if (!awaiter11.IsCompleted)
AsyncHelpers.UnsafeAwaitAwaiter>(awaiter11);
return Task.FromResult(awaiter11.GetResult());
}
```

`ilprint` seems to need to have detection and output for it done. However, the current detection relies on `MethodImpl` being in `netstandard2.0`, since this is part of `net10.0`, there would have to be some compat layer here.

https://github.com/dotnet/fsharp/blob/6ec56c25f451e887185fd918b83891249b00357a/src/Compiler/AbstractIL/ilprint.fs#L717-L730

---

Secondly, as a separate discussion point. Having people manually add this attribute would be extremely inconvenient. What options do you see as possible for a CE to add attributes to the methods that get written out? (We can move to a separate discussion if needed)

**Expected behavior**

MethodImpl is preserved

**Actual behavior**

MethodImpl is not preserved

**Known workarounds**

Hand editing the IL?

**Related information**

Provide any related information (optional):

* Operating system
* .NET Runtime kind (.NET Core, .NET Framework, Mono)
* Editing Tools (e.g. Visual Studio Version, Visual Studio)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.