Skip to content

JS: perform loopification

Following on https://github.com/haskell/bytestring/pull/631 bytestring will be adding a -fpure-haskell flag to remove all FFI (https://github.com/haskell/bytestring/pull/660) but the JS backend cannot yet generate efficient code for tight loops like the ones that are required for the flag.

Why? Because the JS backend does no loopification (See also this Note). This ticket is to:

  1. add loopification in the StgToJS pass
  2. add a test that detects this optimization has fired

What should it look like?

  • use continue to self-tail call
  • use break to finish the loop
  • generate while (true) { ... } for the loop.
Edited by jeffrey young
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information