Repository navigation
Description
Context
👋 .NET 10 is bringing support for Runtime-Async. I started playing around with it in an IcedTasks PR. 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:
[<MethodImpl(MethodImplOptions.Async)>]
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#
public static Task<int> fsharp_tenBindAsync_TaskBuilderRuntime()
{
YieldAwaitable.YieldAwaiter awaiter1 = Task.Yield().GetAwaiter();
if (!awaiter1.IsCompleted)
AsyncHelpers.UnsafeAwaitAwaiter<YieldAwaitable.YieldAwaiter>(awaiter1);
awaiter1.GetResult();
ValueTaskAwaiter<int> awaiter11 = ValueTask.FromResult<int>(100).GetAwaiter();
if (!awaiter11.IsCompleted)
AsyncHelpers.UnsafeAwaitAwaiter<ValueTaskAwaiter<int>>(awaiter11);
return Task.FromResult<int>(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.
fsharp/src/Compiler/AbstractIL/ilprint.fs
Lines 717 to 730 in 6ec56c2
| if md.IsSynchronized then | |
| output_string os "synchronized " | |
| if md.IsMustRun then | |
| output_string os "/* mustrun */ " | |
| if md.IsPreserveSig then | |
| output_string os "preservesig " | |
| if md.IsNoInline then | |
| output_string os "noinlining " | |
| if md.IsAggressiveInline then | |
| output_string os "aggressiveinlining " |
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)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
roboz0r commentedon Nov 6, 2025
Possibly this should be a separate issue (though it could be addressed at the same time) is that the
int16overload forMethodImplappears not to be supported at all. Looking at the decompiled C#, the C# version always appliesMethodImplOptions.AggressiveInliningand F# ignores theint16version.T-Gro commentedon Nov 6, 2025
T-Gro commentedon Nov 10, 2025
@TheAngryByrd :
Does it make sense to solve the explicit manual declaration in isolation, or is that of lesser help and you would really want the automatic CE mechanism ?
Definitely happy to brainstorm the alternatives (another idea would be a defined CE-keyword, like
add_attributes, which would copy over attributes from the builder's method declaration over to the user-space owning IL method)TheAngryByrd commentedon Nov 10, 2025
Ive got some local fork thats writing the IL if you add the attribute manually, but its supposed to be only generated by the compiler (C# disallows you writing it manually).
I was playing with the idea of writing the attribute whenever a method has “AsyncHelpler.Await” or any of the other overloads. But im definitely open to other options that you think make sense.
T-Gro commentedon Nov 10, 2025
I would prefer a smaller non-specialized addition to the compiler now, just to enable experimentation within libraries (since compiler is by nature slow to change due to release cycle) and be ready to changes/additions in the runtime implementation.
Once the feature stabilizes, a compiled detection based on method calls at IL codegen time is OK (pending if/how/if at all do anything for Fable to be aware of it)
TheAngryByrd commentedon Nov 10, 2025
Ok I'll submit the small change to let people use the Attribute for now.
Should we hide it behind a feature flag since we'll probably want to disallow people from using it directly in the future?
T-Gro commentedon Nov 10, 2025
Can use the LanguageFeature mechanism and be in preview (and likely stay in preview)
TheAngryByrd commentedon Nov 10, 2025
This was the bare minimum I got to this weekend but I still need to do more verifications/testing + FeatureFlag
#19065
davidglassborow commentedon Aug 14, 2026
Latest net11 notes on runtime async in C#: https://github.com/dotnet/core/blob/main/release-notes/11.0/preview/preview7/runtime.md#runtime-async-tiering-and-tail-await-optimizations