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 unnecessary thunks
26-- * Inlining variables
28-- * Inline Prelude.($), Prelude.(#), Prelude.(++), Prelude.(!!)
30-- * Inlining primitive Javascript operators
32-----------------------------------------------------------------------------
34module Language.PureScript.Optimizer (
38import Language.PureScript.CodeGen.JS.AST
39import Language.PureScript.Options
40import qualified Language.PureScript.Constants as C
42import Language.PureScript.Optimizer.Common
43import Language.PureScript.Optimizer.TCO
44import Language.PureScript.Optimizer.MagicDo
45import Language.PureScript.Optimizer.Inliner
46import Language.PureScript.Optimizer.Unused
47import Language.PureScript.Optimizer.Blocks
50-- Apply a series of optimizer passes to simplified Javascript code
52optimize :: Options mode -> JS -> JS
53optimize opts | optionsNoOptimizations opts = id
54 | otherwise = untilFixedPoint (applyAll
55 [ collapseNestedBlocks
59 , removeCodeAfterReturnStatements
66 , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
67 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
68 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
69 , inlineCommonOperators ])
71untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
74 go a = let a' = f a in
75 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