Skip to content

Commit

Permalink
Better comment again
Browse files Browse the repository at this point in the history
  • Loading branch information
TIHan committed Jan 15, 2020
1 parent c4223c8 commit 174c293
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,9 +1852,9 @@ let IsILMethodRefSystemStringConcatArray (mref: ILMethodRef) =
ilTy.TypeRef.Name = "System.String" -> true
| _ -> false))

let rec IsExpressionWrappingFunctionApplication expr =
let rec IsSimplePartialFunctionApplicationExpression expr =
match expr with
| Expr.Let(_, body, _, _) -> IsExpressionWrappingFunctionApplication body
| Expr.Let(_, body, _, _) -> IsSimplePartialFunctionApplicationExpression body
| Expr.Lambda(_, _, _, _, Expr.App(Expr.Val _, _, _, _, _), _, _)
| Expr.TyLambda(_, _, Expr.App(Expr.Val _, _, _, _, _), _, _) -> true
| _ -> false
Expand Down Expand Up @@ -3188,12 +3188,10 @@ and OptimizeBinding cenv isRec env (TBind(vref, expr, spBind)) =
let env = if vref.IsCompilerGenerated && Option.isSome env.latestBoundId then env else {env with latestBoundId=Some vref.Id}
let cenv = if vref.InlineInfo = ValInline.PseudoVal then { cenv with optimizing=false} else cenv
let cenv =
// Do not optimize the binding's body if it simply wraps a function call and the bound value is local (not top-level).
// This means the value is a local function wrapping another function.
// We do this to prevent unwanted closure allocations when the local function cannot be inlined due to its size being increased
// by the inlining of the inner function.
// Instead, when this kind of local function is called, it will inline at the callsite and then the optimizer will decide if it can inline the inner function.
if not vref.IsCompiledAsTopLevel && isFunTy cenv.g vref.Type && IsExpressionWrappingFunctionApplication expr then
// Do not optimize the body if it is a simple partial function app expression and the value is local.
// We do this to prevent unwanted closure allocations due to its size being increased when the body's inner function app expresion is inlined.
// Instead, when this kind of local function is called, it will inline at the callsite and then the optimizer will decide if it can inline the inner function app.
if not vref.IsCompiledAsTopLevel && isFunTy cenv.g vref.Type && IsSimplePartialFunctionApplicationExpression expr then
{ cenv with optimizing = false }
else
cenv
Expand Down

0 comments on commit 174c293

Please sign in to comment.