ghc-9.8.0.20230929: 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
LanguageHaskell2010

GHC.JS.Optimizer

Description

  • Domain and Purpose

    GHC.JS.Optimizer is a shallow embedding of a peephole optimizer. That is, this module defines transformations over the JavaScript IR in Syntax, transforming the IR forms from inefficient, or non-idiomatic, JavaScript to more efficient and idiomatic JavaScript. The optimizer is written in continuation passing style so optimizations compose.

  • Architecture of the optimizer

The design is that each optimization pattern matches on the head of a block by pattern matching onto the head of the stream of nodes in the JavaScript IR. If an optimization gets a successful match then it performs whatever rewrite is necessary and then calls the loop continuation. This ensures that the result of the optimization is subject to the same optimization, and the rest of the optimizations. If there is no match then the optimization should call the next continuation to pass the stream to the next optimization in the optimization chain. We then define the last "optimization" to be tailLoop which selects the next block of code to optimize and begin the optimization pipeline again.

Documentation