Skip to content

Commit ef2153c

Browse files
committed
fix 116 - no method splitting in loops
1 parent f97dcf6 commit ef2153c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/fsharp/Optimizer.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ type IncrementalOptimizationEnv =
331331
// contains any of these variables then don't split it, for fear of mucking up tailcalls.
332332
// See FSharp 1.0 bug 2892
333333
dontSplitVars: ValMap<unit>;
334+
// Disable method splittingin loops
335+
inLoop: bool;
334336
/// The Val for the function binding being generated, if any.
335337
functionVal: (Val * Tast.ValReprInfo) option;
336338
typarInfos: (Typar * TypeValueInfo) list;
@@ -343,6 +345,7 @@ type IncrementalOptimizationEnv =
343345
typarInfos = [];
344346
functionVal = None;
345347
dontSplitVars = ValMap.Empty;
348+
inLoop = false
346349
localExternalVals = LayeredMap.Empty;
347350
globalModuleInfos = LayeredMap.Empty }
348351

@@ -1856,8 +1859,8 @@ and OptimizeExprOp cenv env (op,tyargs,args,m) =
18561859
MightMakeCriticalTailcall = false;
18571860
Info = UnknownValue }
18581861
(* Handle these as special cases since mutables are allowed inside their bodies *)
1859-
| TOp.While (spWhile,marker),_,[Expr.Lambda(_,_,_,[_],e1,_,_);Expr.Lambda(_,_,_,[_],e2,_,_)] -> OptimizeWhileLoop cenv env (spWhile,marker,e1,e2,m)
1860-
| TOp.For(spStart,dir),_,[Expr.Lambda(_,_,_,[_],e1,_,_);Expr.Lambda(_,_,_,[_],e2,_,_);Expr.Lambda(_,_,_,[v],e3,_,_)] -> OptimizeFastIntegerForLoop cenv env (spStart,v,e1,dir,e2,e3,m)
1862+
| TOp.While (spWhile,marker),_,[Expr.Lambda(_,_,_,[_],e1,_,_);Expr.Lambda(_,_,_,[_],e2,_,_)] -> OptimizeWhileLoop cenv { env with inLoop=true } (spWhile,marker,e1,e2,m)
1863+
| TOp.For(spStart,dir),_,[Expr.Lambda(_,_,_,[_],e1,_,_);Expr.Lambda(_,_,_,[_],e2,_,_);Expr.Lambda(_,_,_,[v],e3,_,_)] -> OptimizeFastIntegerForLoop cenv { env with inLoop=true } (spStart,v,e1,dir,e2,e3,m)
18611864
| TOp.TryFinally(spTry,spFinally),[resty],[Expr.Lambda(_,_,_,[_],e1,_,_); Expr.Lambda(_,_,_,[_],e2,_,_)] -> OptimizeTryFinally cenv env (spTry,spFinally,e1,e2,m,resty)
18621865
| TOp.TryCatch(spTry,spWith),[resty],[Expr.Lambda(_,_,_,[_],e1,_,_); Expr.Lambda(_,_,_,[vf],ef,_,_); Expr.Lambda(_,_,_,[vh],eh,_,_)] -> OptimizeTryCatch cenv env (e1,vf,ef,vh,eh,m,resty,spTry,spWith)
18631866
| TOp.TraitCall(traitInfo),[],args -> OptimizeTraitCall cenv env (traitInfo, args, m)
@@ -2818,6 +2821,7 @@ and ComputeSplitToMethodCondition flag threshold cenv env (e,einfo) =
28182821
// REVIEW: This should only apply to methods that actually make self-tailcalls (tested further below).
28192822
// Old comment "don't mess with taking guaranteed tailcalls if used with --no-tailcalls!"
28202823
cenv.emitTailcalls &&
2824+
not env.inLoop &&
28212825
einfo.FunctionSize >= threshold &&
28222826

28232827
// We can only split an expression out as a method if certain conditions are met.

0 commit comments

Comments
 (0)