Skip to content

Resumable state machines: Don't capture definitions by "builder@" prefix. EXPERIMENTAL#19482

Draft
majocha wants to merge 2 commits intodotnet:mainfrom
majocha:builder-resumable
Draft

Resumable state machines: Don't capture definitions by "builder@" prefix. EXPERIMENTAL#19482
majocha wants to merge 2 commits intodotnet:mainfrom
majocha:builder-resumable

Conversation

@majocha
Copy link
Copy Markdown
Contributor

@majocha majocha commented Mar 24, 2026

AI says: Refactored LowerStateMachines.fs to identify state machine binding variables using only "expand var" or member "this" checks, removing the "builder@" name prefix logic. Updated TaskGeneratedCode.fs to align the generated IL for Generic1InGeneric1<'T>.run with the new binding logic, introducing a TaskBuilder local and adjusting closure variable handling.

Description

I don't yet have a good small repro.
Situations of mixed use of both resumable and standard computation expressions can in some rare cases result in:

error FS0971: Undefined value 'builder@'

on a non-resumable CE let binding.

It is not clear to me why there's a need to special case builder@ vals during state machine lowering. Some builders may not be resuamble and are erroneously added to ResumableCodeDefns.

This is an experiment to eliminate the string prefix "builder@" logic to see if things still work.

Refactored LowerStateMachines.fs to identify state machine binding variables using only "expand var" or member "this" checks, removing the "builder@" name prefix logic. Updated TaskGeneratedCode.fs to align the generated IL for Generic1InGeneric1<'T>.run with the new binding logic, introducing a TaskBuilder local and adjusting closure variable handling.
@github-actions
Copy link
Copy Markdown
Contributor

❗ 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/11.0.100.md No release notes found or release notes format is not correct

.locals init (class [FSharp.Core]Microsoft.FSharp.Control.TaskBuilder V_0,
valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A> V_1,
valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>& V_2)
IL_0000: call class [FSharp.Core]Microsoft.FSharp.Control.TaskBuilder [FSharp.Core]Microsoft.FSharp.Control.TaskBuilderModule::get_task()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this getter call is the only substantial change in the IL. It gets eliminated with "--optimize+"

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.

1 participant