-
Notifications
You must be signed in to change notification settings - Fork 825
Description
#13573 would have included one optimization which #16650, et seq., did not, namely the optimization of for
-loops over integral ranges with steps other than 1
and -1
in resumable code computation expressions (like task
). I figured I might as well record it here (cc @psfinaki).
It seems like it might be relatively straightforward to add this optimization now by wiring up the IntegralRange
and mkOptimizedRangeLoop
constructs exposed in #16650.
-
Supplement the existing match on
IntegerForLoopExpr
with another match onCompiledForEachExpr
andIntegralRange
:fsharp/src/Compiler/Optimize/LowerStateMachines.fs
Lines 485 to 486 in 5fd6800
| IntegerForLoopExpr (sp1, sp2, style, e1, e2, v, e3, m) -> ConvertResumableIntegerForLoop env pcValInfo (sp1, sp2, style, e1, e2, v, e3, m) -
There is an existing translation using
mkIntegerForLoop
; add a new one that usesmkOptimizedRangeLoop
:{ phase1 = mkIntegerForLoop g (spFor, spTo, v, res1.phase1, style, res2.phase1, res3.phase1, m)
However, the existing optimization for for
-loops over int32
ranges with steps of 1
or -1
doesn't always seem to kick in — in fact, I haven't been able to get it to kick in at all, even when using the syntax for n = start to finish do …
instead of for n in start..finish do …
. So figuring out why that is, and what the TAST actually looks like by the time it gets to LowerStateMachines.fs
, might end up being the harder problem to solve.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status