-
Notifications
You must be signed in to change notification settings - Fork 789
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
Feat: Implement builder for valuetask #14755
Conversation
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.
Looks good.
Proposal need to be approved first, before we can merge it though.
It will probably also need an RFC which will describe CE, and which methods it will have (especially, around what can be bound inside - do we support full spectrum of awaitables, or just tasks/vtasks, how conversions are handled, etc), for documentation purposes.
97ff7a1
to
6b35a2b
Compare
sure, |
6b35a2b
to
c62ccfb
Compare
btw, who is in charge of writing the RFC ? |
I don't know what triggers this error of duplicate |
It can be up to anyone, in most of the cases it's whoewer imlements the feature. The flow is usually Suggestion -> Approval -> RFC (+iterations) -> Implementation. Last two can be in parallel, to not waste time. |
To simplify the review process, can you please explain how the implementation was created ? |
I tried to make as few changes as possible compared to TaskBuilder:
Then where new tasks are created, I used the I also added a Bind for task, added to the Medium Priority to avoid conflict in cases of Last part is adding all the test by copying the tests from task, and adapting to valuetask . |
In general, I don't think it is a good idea to split codegen for FSharp.Core that much in case of ns21 as long as we still target ns20. It is very confusing to the users. Might be a better idea to have it as separate package, once we start separating FSharp.Core cc @KevinRansom |
Actually, ValueTask is available only in netstandard2.1, and is used more and more in recent frameworks. |
What I meant is - it is confusing for users to have the whole builder api in FSharp.Core - netstandard2.1, and not have it in netstandard2.0. We never did that big of the surface area difference yet (biggest one so far is TryFinally in Task available only in ns21, if I'm not mistaken). |
Yes I understand. But at some point some new features will appear only in net6. 0+... Having them in Fsharp.Core will have to follow. |
I wonder if there's a better way for us to deliver those. Maybe layer corelib as FSharp.Core and all .Control. packages separately, and give those the same treatment we have for FSharp.Core currently. |
Yes that could be a nice way to do it. Still, since the type Like I would not expect task to exist on super-old frameworks where Task did not exist. https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask?view=net-7.0 |
Also take a look over and use anything from IcedTasks ValueTask and the corresponding tests |
Why not netstandard2.0? The type is available from ns1.0 using System.Threading.Tasks.Extensions nuget package so ns2.0 or net461 should pose no problem. |
Core library doesn't have any external dependencies, nor do we want it to have any at this point without proper design (to either properly separate it to multiple packages, or bump minimal version, or split codegen, or some secret 4th option). |
Going to close it for now, until we have a better story of how to deliver layered core library for basic ns2.0 functionality and newer stuff (fsharp/fslang-suggestions#1244 (comment)) |
This is a proposition of implementation of a valuetask computation expression.
A explained in fsharp/fslang-suggestions#1244 :
The advantages of making this adjustment to F# are:
More efficient and faster code
Far lower memory impact
No need for wrapping Task in ValueTask (which is not easy to get right and is verbose)
More straightforward in case of libraries and frameworks that use ValueTask
The disadvantages of making this adjustment to F# are :
A new ValueTaskBuilder implementation quite similar to TaskBuilder.
This implementation rely on .IsCompleted to avoid accessing the underlying Task when not needed.
As noticed in tests, an helper function could be useful to make a
ValueTask
from aValueTask<unit>
. Since `ValueTask<'t>' is a struct, it cannot be cast. It could be implemented as:But I don't know yet what would be the best name, and where to put it.