Resumable state machines: Don't capture definitions by "builder@" prefix. EXPERIMENTAL#19482
Resumable state machines: Don't capture definitions by "builder@" prefix. EXPERIMENTAL#19482majocha wants to merge 4 commits intodotnet:mainfrom
Conversation
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.
❗ Release notes requiredCaution 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:
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
|
| .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() |
There was a problem hiding this comment.
this getter call is the only substantial change in the IL. It gets eliminated with "--optimize+"
| let isStateMachineBindingVar g (v: Val) = | ||
| isExpandVar g v || | ||
| (let nm = v.LogicalName | ||
| (nm.StartsWithOrdinal("builder@") || v.IsMemberThisVal)) |
There was a problem hiding this comment.
Do we know why it was needed before?
Are the recent state machine bug fixes the reason why we no longer need this special casing?
There was a problem hiding this comment.
Are the recent state machine bug fixes the reason why we no longer need this special casing?
No, this is completely independent. I did a checkout of old commit and applied this fix to check it.
Do we know why it was needed before?
Ha, this is not entirely clear. That's why I'm a bit wary about this.
|
OK, before, it eliminates the whole desugared builder code: After, it leaves the This clears up the purpose of the "builder@" special casing. |
|
It seems the goal of (let nm = v.LogicalName
(nm.StartsWithOrdinal("builder@") || v.IsMemberThisVal))was just to eliminate these bindings generated during CE compilation But aren't they are optimized out of existence anyway? |
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:
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.