1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Optimizer
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- This module optimizes code in the simplified-Javascript intermediate representation.
14-- The following optimizations are supported:
16-- * Collapsing nested blocks
18-- * Tail call elimination
20-- * Inlining of (>>=) and ret for the Eff monad
22-- * Removal of unused variables
24-- * Removal of unnecessary thunks
28-- * Inlining variables
30-- * Inline Prelude.($), Prelude.(#), Prelude.(++), Prelude.(!!)
32-- * Inlining primitive Javascript operators
34-----------------------------------------------------------------------------
36module Language.PureScript.Optimizer (
40import Language.PureScript.CodeGen.JS.AST
41import Language.PureScript.Options
42import qualified Language.PureScript.Constants as C
44import Language.PureScript.Optimizer.Common
45import Language.PureScript.Optimizer.TCO
46import Language.PureScript.Optimizer.MagicDo
47import Language.PureScript.Optimizer.Inliner
48import Language.PureScript.Optimizer.Unused
49import Language.PureScript.Optimizer.Blocks
52-- Apply a series of optimizer passes to simplified Javascript code
54optimize :: Options -> JS -> JS
55optimize opts | optionsNoOptimizations opts = id
56 | otherwise = untilFixedPoint $ applyAll
57 [ collapseNestedBlocks
60 , removeUnusedVariables
64 , inlineOperator (C.$) $ \f x -> JSApp f [x]
65 , inlineOperator (C.#) $ \x f -> JSApp f [x]
66 , inlineOperator (C.!!) $ flip JSIndexer
67 , inlineOperator (C.++) $ JSBinary Add
68 , inlineCommonOperators ]
70untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
73 go a = let a' = f a in
74 if a' == a then a' else go a'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list