Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integral range optimizations in resumable code computation expressions #17253

Open
brianrourkeboll opened this issue May 26, 2024 · 0 comments
Open
Labels
Area-Compiler-Optimization The F# optimizer, release code gen etc. Feature Improvement
Milestone

Comments

@brianrourkeboll
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Optimization The F# optimizer, release code gen etc. Feature Improvement
Projects
Status: New
Development

No branches or pull requests

3 participants