@@ -4388,6 +4388,10 @@ let bindLhs opts (bind: Binding) fvs = boundLocalVal opts bind.Var fvs
43884388
43894389let freeVarsCacheCompute opts cache f = if opts.canCache then cached cache f else f()
43904390
4391+ let tryGetFreeVarsCacheValue opts cache =
4392+ if opts.canCache then tryGetCacheValue cache
4393+ else ValueNone
4394+
43914395let rec accBindRhs opts ( TBind ( _ , repr , _ )) acc = accFreeInExpr opts repr acc
43924396
43934397and accFreeInSwitchCases opts csl dflt ( acc : FreeVars ) =
@@ -4485,13 +4489,16 @@ and accFreeInExpr (opts: FreeVarOptions) x acc =
44854489and accFreeInExprLinear ( opts : FreeVarOptions ) x acc contf =
44864490 // for nested let-bindings, we need to continue after the whole let-binding is processed
44874491 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+ ))
44924499 | _ ->
4493- // No longer linear expr
4494- accFreeInExpr opts x acc |> contf
4500+ // No longer linear expr
4501+ contf ( accFreeInExpr opts x acc)
44954502
44964503and accFreeInExprNonLinear opts x acc =
44974504 match x with
0 commit comments