Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / Useless
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>Useless</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>Useless</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="Useless">Useless</a> is an optimization pass for the <a href="SSA">SSA</a>
32 <a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="SSASimplify">SSASimplify</a>.</p></div>
33 </div>
34 </div>
35 <div class="sect1">
36 <h2 id="_description">Description</h2>
37 <div class="sectionbody">
38 <div class="paragraph"><p>This pass:</p></div>
39 <div class="ulist"><ul>
40 <li>
41 <p>
42 removes components of tuples that are constants (use unification)
43 </p>
44 </li>
45 <li>
46 <p>
47 removes function arguments that are constants
48 </p>
49 </li>
50 <li>
51 <p>
52 builds some kind of dependence graph where
53 </p>
54 <div class="ulist"><ul>
55 <li>
56 <p>
57 a value of ground type is useful if it is an arg to a primitive
58 </p>
59 </li>
60 <li>
61 <p>
62 a tuple is useful if it contains a useful component
63 </p>
64 </li>
65 <li>
66 <p>
67 a constructor is useful if it contains a useful component or is used in a <span class="monospaced">Case</span> transfer
68 </p>
69 </li>
70 </ul></div>
71 </li>
72 </ul></div>
73 <div class="paragraph"><p>If a useful tuple is coerced to another useful tuple, then all of
74 their components must agree (exactly). It is trivial to convert a
75 useful value to a useless one.</p></div>
76 </div>
77 </div>
78 <div class="sect1">
79 <h2 id="_implementation">Implementation</h2>
80 <div class="sectionbody">
81 <div class="ulist"><ul>
82 <li>
83 <p>
84 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/useless.fun"><span class="monospaced">useless.fun</span></a>
85 </p>
86 </li>
87 </ul></div>
88 </div>
89 </div>
90 <div class="sect1">
91 <h2 id="_details_and_notes">Details and Notes</h2>
92 <div class="sectionbody">
93 <div class="paragraph"><p>It is also trivial to convert a useful tuple to one of its useful
94 components&#8201;&#8212;&#8201;but this seems hard.</p></div>
95 <div class="paragraph"><p>Suppose that you have a <span class="monospaced">ref</span>/<span class="monospaced">array</span>/<span class="monospaced">vector</span> that is useful, but the
96 components aren&#8217;t&#8201;&#8212;&#8201;then the components are converted to type <span class="monospaced">unit</span>,
97 and any primitive args must be as well.</p></div>
98 <div class="paragraph"><p>Unify all handler arguments so that <span class="monospaced">raise</span>/<span class="monospaced">handle</span> has a consistent
99 calling convention.</p></div>
100 </div>
101 </div>
102 </div>
103 <div id="footnotes"><hr></div>
104 <div id="footer">
105 <div id="footer-text">
106 </div>
107 <div id="footer-badges">
108 </div>
109 </div>
110 </body>
111 </html>