Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / Useless.adoc
1 Useless
2 =======
3
4 <:Useless:> is an optimization pass for the <:SSA:>
5 <:IntermediateLanguage:>, invoked from <:SSASimplify:>.
6
7 == Description ==
8
9 This pass:
10
11 * removes components of tuples that are constants (use unification)
12 * removes function arguments that are constants
13 * builds some kind of dependence graph where
14 ** a value of ground type is useful if it is an arg to a primitive
15 ** a tuple is useful if it contains a useful component
16 ** a constructor is useful if it contains a useful component or is used in a `Case` transfer
17
18 If a useful tuple is coerced to another useful tuple, then all of
19 their components must agree (exactly). It is trivial to convert a
20 useful value to a useless one.
21
22 == Implementation ==
23
24 * <!ViewGitFile(mlton,master,mlton/ssa/useless.fun)>
25
26 == Details and Notes ==
27
28 It is also trivial to convert a useful tuple to one of its useful
29 components -- but this seems hard.
30
31 Suppose that you have a `ref`/`array`/`vector` that is useful, but the
32 components aren't -- then the components are converted to type `unit`,
33 and any primitive args must be as well.
34
35 Unify all handler arguments so that `raise`/`handle` has a consistent
36 calling convention.