Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / doc / guide / src / Shrink.adoc
1 Shrink
2 ======
3
4 <:Shrink:> is a rewrite pass for the <:SSA:> and <:SSA2:>
5 <:IntermediateLanguage:>s, invoked from every optimization pass (see
6 <:SSASimplify:> and <:SSA2Simplify:>).
7
8 == Description ==
9
10 This pass implements a whole family of compile-time reductions, like:
11
12 * `#1(a, b)` => `a`
13 * `case C x of C y => e` => `let y = x in e`
14 * constant folding, copy propagation
15 * eta blocks
16 * tuple reconstruction elimination
17
18 == Implementation ==
19
20 * <!ViewGitFile(mlton,master,mlton/ssa/shrink.sig)>
21 * <!ViewGitFile(mlton,master,mlton/ssa/shrink.fun)>
22 * <!ViewGitFile(mlton,master,mlton/ssa/shrink2.sig)>
23 * <!ViewGitFile(mlton,master,mlton/ssa/shrink2.fun)>
24
25 == Details and Notes ==
26
27 The <:Shrink:> pass is run after every <:SSA:> and <:SSA2:>
28 optimization pass.
29
30 The <:Shrink:> implementation also includes functions to eliminate
31 unreachable blocks from a <:SSA:> or <:SSA2:> program or function.
32 The <:Shrink:> pass does not guarantee to eliminate all unreachable
33 blocks. Doing so would unduly complicate the implementation, and it
34 is almost always the case that all unreachable blocks are eliminated.
35 However, a small number of optimization passes require that the input
36 have no unreachable blocks (essentially, when the analysis works on
37 the control flow graph and the rewrite iterates on the vector of
38 blocks). These passes explicitly call `eliminateDeadBlocks`.
39
40 The <:Shrink:> pass has a special case to turn a non-tail call where
41 the continuation and handler only do `Profile` statements into a tail
42 call where the `Profile` statements precede the tail call.