Skip to content

Integral range optimizations in resumable code computation expressions #17253

Open
@brianrourkeboll

Description

@brianrourkeboll

#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.

  1. Supplement the existing match on IntegerForLoopExpr with another match on CompiledForEachExpr and IntegralRange:

    | IntegerForLoopExpr (sp1, sp2, style, e1, e2, v, e3, m) ->
    ConvertResumableIntegerForLoop env pcValInfo (sp1, sp2, style, e1, e2, v, e3, m)

  2. There is an existing translation using mkIntegerForLoop; add a new one that uses mkOptimizedRangeLoop:

    { 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

No one assigned

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions