Copyright | (c) The University of Glasgow 2001 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Jeffrey Young <jeffrey.young@iohk.io> Luite Stegeman <luite.stegeman@iohk.io> Sylvain Henry <sylvain.henry@iohk.io> Josh Meredith <josh.meredith@iohk.io> |
Stability | experimental |
Safe Haskell | None |
Language | GHC2021 |
Simple optimizer for the JavaScript IR
This is a simple optimizer for the JavaScript IR. It is intended to be the first optimization pass after generating the JavaScript IR.
Design
The optimizer is invoked on the top-level JStat. It leaves the top-level scope alone, but traverses into each function body and optimizes it. Nested functions are mostly left alone, since they are uncommon in generated code.
The optimizations are:
- rename local variables to shorter names
- remove unused variables
- remove trivial assignments: x = x
- "float" expressions without side effects:
- var x = 1; var y = x + 1; -> var y = 1 + 1;
Limitations
The simple optimization pass is intended to be fast and applicable to almost all generated JavaScript code. Limitations are:
- optimization is disabled if an
eval
statement is encountered - variables declared in nested scopes are not renamed
- optimization is disabled if an