Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / PolyEqual
CommitLineData
7f918cf1
CE
1<!DOCTYPE html>\r
2<html lang="en">\r
3<head>\r
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5<meta name="generator" content="AsciiDoc 8.6.9">\r
6<title>PolyEqual</title>\r
7<link rel="stylesheet" href="./asciidoc.css" type="text/css">\r
8<link rel="stylesheet" href="./pygments.css" type="text/css">\r
9\r
10\r
11<script type="text/javascript" src="./asciidoc.js"></script>\r
12<script type="text/javascript">\r
13/*<![CDATA[*/\r
14asciidoc.install();\r
15/*]]>*/\r
16</script>\r
17<link rel="stylesheet" href="./mlton.css" type="text/css">\r
18</head>\r
19<body class="article">\r
20<div id="banner">\r
21<div id="banner-home">\r
22<a href="./Home">MLton 20180207</a>\r
23</div>\r
24</div>\r
25<div id="header">\r
26<h1>PolyEqual</h1>\r
27</div>\r
28<div id="content">\r
29<div id="preamble">\r
30<div class="sectionbody">\r
31<div class="paragraph"><p><a href="PolyEqual">PolyEqual</a> is an optimization pass for the <a href="SSA">SSA</a>\r
32<a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="SSASimplify">SSASimplify</a>.</p></div>\r
33</div>\r
34</div>\r
35<div class="sect1">\r
36<h2 id="_description">Description</h2>\r
37<div class="sectionbody">\r
38<div class="paragraph"><p>This pass implements polymorphic equality.</p></div>\r
39</div>\r
40</div>\r
41<div class="sect1">\r
42<h2 id="_implementation">Implementation</h2>\r
43<div class="sectionbody">\r
44<div class="ulist"><ul>\r
45<li>\r
46<p>\r
47<a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/poly-equal.fun"><span class="monospaced">poly-equal.fun</span></a>\r
48</p>\r
49</li>\r
50</ul></div>\r
51</div>\r
52</div>\r
53<div class="sect1">\r
54<h2 id="_details_and_notes">Details and Notes</h2>\r
55<div class="sectionbody">\r
56<div class="paragraph"><p>For each datatype, tycon, and vector type, it builds and equality\r
57function and translates calls to <span class="monospaced">MLton_equal</span> into calls to that\r
58function.</p></div>\r
59<div class="paragraph"><p>Also generates calls to <span class="monospaced">Word_equal</span>.</p></div>\r
60<div class="paragraph"><p>For tuples, it does the equality test inline; i.e., it does not create\r
61a separate equality function for each tuple type.</p></div>\r
62<div class="paragraph"><p>All equality functions are created only if necessary, i.e., if\r
63equality is actually used at a type.</p></div>\r
64<div class="paragraph"><p>Optimizations:</p></div>\r
65<div class="ulist"><ul>\r
66<li>\r
67<p>\r
68for datatypes that are enumerations, do not build a case dispatch,\r
69just use <span class="monospaced">MLton_eq</span>, as the backend will represent these as ints\r
70</p>\r
71</li>\r
72<li>\r
73<p>\r
74deep equality always does an <span class="monospaced">MLton_eq</span> test first\r
75</p>\r
76</li>\r
77<li>\r
78<p>\r
79If one argument to <span class="monospaced">=</span> is a constant and the type will get\r
80translated to an <span class="monospaced">IntOrPointer</span>, then just use <span class="monospaced">eq</span> instead of the\r
81full equality. This is important for implementing code like the\r
82following efficiently:\r
83</p>\r
84<div class="listingblock">\r
85<div class="content monospaced">\r
86<pre>if x = 0 ... (* where x is of type IntInf.int *)</pre>\r
87</div></div>\r
88</li>\r
89<li>\r
90<p>\r
91Also convert pointer equality on scalar types to type specific\r
92primitives.\r
93</p>\r
94</li>\r
95</ul></div>\r
96</div>\r
97</div>\r
98</div>\r
99<div id="footnotes"><hr></div>\r
100<div id="footer">\r
101<div id="footer-text">\r
102</div>\r
103<div id="footer-badges">\r
104</div>\r
105</div>\r
106</body>\r
107</html>\r