ghc-9.12: The GHC API
Copyright(c) The University of Glasgow 2001
LicenseBSD-style (see the file LICENSE)
MaintainerJeffrey Young <jeffrey.young@iohk.io> Luite Stegeman <luite.stegeman@iohk.io> Sylvain Henry <sylvain.henry@iohk.io> Josh Meredith <josh.meredith@iohk.io>
Stabilityexperimental
Safe HaskellNone
LanguageGHC2021

GHC.JS.Opt.Simple

Description

  • 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

Documentation