Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/Compiler/Optimize/LowerStateMachines.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,7 @@ let RepresentBindingAsStateVar g (bind: Binding) (resBody: StateMachineConversio
let isExpandVar g (v: Val) =
isReturnsResumableCodeTy g v.TauType

// We allow a prefix of bindings prior to the state machine, e.g.
// task { .. }
// becomes
// let builder@ = task
// ....
let isStateMachineBindingVar g (v: Val) =
isExpandVar g v ||
(let nm = v.LogicalName
(nm.StartsWithOrdinal("builder@") || v.IsMemberThisVal))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

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.

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.

let isStateMachineBindingVar g (v: Val) = isExpandVar g v

type env =
{
Expand Down Expand Up @@ -361,7 +353,6 @@ type LowerStateMachine(g: TcGlobals, outerResumableCodeDefns: ValMap<Expr>) =
TryReduceExpr env f (args2 @ args) (fun f2 -> remake (Expr.App (f2, _fty, _tyargs, args2, _m)))

| _ ->
//let (env, expr) = BindResumableCodeDefinitions env expr
match TryReduceApp env expr args with
| Some expandedExpr ->
if sm_verbose then printfn "reduction = %A, args = %A --> %A..." expr args expandedExpr
Expand Down Expand Up @@ -408,7 +399,6 @@ type LowerStateMachine(g: TcGlobals, outerResumableCodeDefns: ValMap<Expr>) =
// Detect a state machine with a single method override
[<return: Struct>]
let (|ExpandedStateMachineInContext|_|) inputExpr =
// All expanded resumable code state machines e.g. 'task { .. }' begin with a bind of @builder or 'defn'
// Seed the env with any expand-var definitions from outer scopes (e.g. across lambda boundaries)
let initialEnv = { env.Empty with ResumableCodeDefns = outerResumableCodeDefns }
let env, expr = BindResumableCodeDefinitions initialEnv inputExpr
Expand Down
Loading
Loading