Skip to content

Computational expressions tail calls support, revived - #18804

Merged
T-Gro merged 21 commits into
dotnet:mainfrom
majocha:tailcalls-ce
Aug 6, 2025
Merged

T-Gro merged 21 commits into
dotnet:mainfrom
majocha:tailcalls-ce

Conversation

@majocha

@majocha majocha commented Jul 31, 2025 •

Copy link
Copy Markdown
Contributor

Revived #17018

Implements fsharp/fslang-suggestions#1006

TODO:

  • write some tests
  • decide how to deal with DoBang
  • RFC FS-1330
  • add example usage / implementations for some basic CEs to tests.
@github-actions

github-actions Bot commented Jul 31, 2025 •

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
LanguageFeatures.fsi docs/release-notes/.Language/preview.md
@vzarytovskii

Copy link
Copy Markdown
Member

Nice

@majocha

majocha commented Aug 1, 2025

Copy link
Copy Markdown
Contributor Author

So, some tests are up and running. I will fill them up with all imaginable tail call / non-tailcall combinations.

OTOH Applying this to TaskBuilder is very tricky and probably hopeless, given its type signature.
It returns just a running task and binds to awaitables that also may or may not be already running. I cannot come up with anything that wouldn't be horrendous (like for example communicating between TaskBuilder state machines via an AsyncLocal side channel to signal that we're executing in a recursive taill-call context).

It might be more useful for other computation expressions.

@majocha majocha changed the title WIP: Computational expressions tail calls support, revived Aug 1, 2025
@majocha
majocha marked this pull request as ready for review August 3, 2025 10:56
@majocha
majocha requested a review from a team as a code owner August 3, 2025 10:56
majocha and others added 2 commits August 3, 2025 19:10
Comment thread docs/release-notes/.Language/preview.md Resolved
@edgarfgp
edgarfgp requested a review from T-Gro August 6, 2025 09:17
@dsyme

dsyme commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

@majocha Just to say a huge, huge thank you for getting this in. We should always have done tailcalls in computation expressions like this, and it's a relief to see it finally in place

@dsyme

dsyme commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Thank you also to @T-Gro for your work in facilitating both the design repos and the implementation!

github-actions Bot pushed a commit to fsprojects/FSharp.Control.TaskSeq that referenced this pull request Mar 8, 2026
- Add YieldFromFinal(IAsyncEnumerable<'T>) in MediumPriority (= YieldFrom)
- Add YieldFromFinal(seq<'T>) in MediumPriority (= YieldFrom)
- Add YieldFromFinal for generic unit-returning task-likes in LowPriority
- Add YieldFromFinal(Task<unit>) and YieldFromFinal(Async<unit>) in HighPriority
- Update TaskSeqBuilder.fsi with matching signatures
- Update release-notes.txt

The F# 10 compiler (dotnet/fsharp#18804) calls YieldFromFinal instead of
YieldFrom when yield! or do! appears in a tail-call position. These overloads
ensure taskSeq compiles without errors under F# 10.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants