@@ -4388,6 +4388,10 @@ let bindLhs opts (bind: Binding) fvs = boundLocalVal opts bind.Var fvs
4388
4388
4389
4389
let freeVarsCacheCompute opts cache f = if opts.canCache then cached cache f else f()
4390
4390
4391
+ let tryGetFreeVarsCacheValue opts cache =
4392
+ if opts.canCache then tryGetCacheValue cache
4393
+ else ValueNone
4394
+
4391
4395
let rec accBindRhs opts ( TBind ( _ , repr , _ )) acc = accFreeInExpr opts repr acc
4392
4396
4393
4397
and accFreeInSwitchCases opts csl dflt ( acc : FreeVars ) =
@@ -4485,13 +4489,16 @@ and accFreeInExpr (opts: FreeVarOptions) x acc =
4485
4489
and accFreeInExprLinear ( opts : FreeVarOptions ) x acc contf =
4486
4490
// for nested let-bindings, we need to continue after the whole let-binding is processed
4487
4491
match x with
4488
- | Expr.Let ( bind, e, _, cache) ->
4489
- let contf = contf << ( fun free ->
4490
- unionFreeVars ( freeVarsCacheCompute opts cache ( fun () -> bindLhs opts bind ( accBindRhs opts bind free))) acc )
4491
- accFreeInExprLinear opts e emptyFreeVars contf
4492
+ | Expr.Let ( bind, e, _, cache) ->
4493
+ match tryGetFreeVarsCacheValue opts cache with
4494
+ | ValueSome free -> contf ( unionFreeVars free acc)
4495
+ | _ ->
4496
+ accFreeInExprLinear opts e emptyFreeVars ( contf << ( fun free ->
4497
+ unionFreeVars ( freeVarsCacheCompute opts cache ( fun () -> bindLhs opts bind ( accBindRhs opts bind free))) acc
4498
+ ))
4492
4499
| _ ->
4493
- // No longer linear expr
4494
- accFreeInExpr opts x acc |> contf
4500
+ // No longer linear expr
4501
+ contf ( accFreeInExpr opts x acc)
4495
4502
4496
4503
and accFreeInExprNonLinear opts x acc =
4497
4504
match x with
0 commit comments