Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Resumable cancellable with trampolined binds #18733

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

majocha
Copy link
Contributor

@majocha majocha commented Jul 5, 2025

Description

Just to see if it works at all. Don't worry about it.

This is revived #18285 with cancellable CE reimplemented using resumable code.
Binds are trampolined so if things do work, deep recursion should not be a problem regardless of tailcalls.

The complexity probably makes it not worth it to reimplement just the cancellable, but it could be a starting point to replace internally all the asyncs (and cancellables) in FCS with a compatible and more effective resumable async2 implementation.

Copy link
Contributor

github-actions bot commented Jul 5, 2025

❗ Release notes required

@majocha,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md No release notes found or release notes format is not correct

@@ -4869,7 +4869,7 @@ module TcDeclarations =
//-------------------------------------------------------------------------
// Bind module types
//-------------------------------------------------------------------------

#nowarn FS3511
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing to compile statically, which is another problem.

@T-Gro
Copy link
Member

T-Gro commented Jul 7, 2025

(side thought - if we had a compiler-only usage of an async variant, we could use it to dogfood under flags when we decide to use runtime's async implementation. The compiler could also provide testing of deeply recursive scenarios there - might be valuable even for the runtime impl itself. But obviously we would have to accept the change of semantics, which will not work for the general library usage of async)

@majocha
Copy link
Contributor Author

majocha commented Jul 9, 2025

This is currently driven be an explicit synchronous loop.

Another approach would be to use something similar to CancellableTask. That would mean a (mostly) synchronous execution driven by AsyncMethodBuilder, with occasional yields in Bind to allow unlimited recursion without stack overflow.

The problem would be with propagating exceptions (including cancellation) from deep call chains. It could get very expensive, because of async stack trace stitching, see (TheAngryByrd/IcedTasks#3 (comment)).

As a side note, current async implementation has very fast zero-cost cancellation, unlimited recursion and while stack traces are problematic, throwing from deeply nested code is not. This is something valuable to preserve in a potential resumable async2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

2 participants