4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>PolyEqual</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
19 <body class="article">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="PolyEqual">PolyEqual</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>
36 <h2 id="_description">Description</h2>
37 <div class="sectionbody">
38 <div class="paragraph"><p>This pass implements polymorphic equality.</p></div>
42 <h2 id="_implementation">Implementation</h2>
43 <div class="sectionbody">
44 <div class="ulist"><ul>
47 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/poly-equal.fun"><span class="monospaced">poly-equal.fun</span></a>
54 <h2 id="_details_and_notes">Details and Notes</h2>
55 <div class="sectionbody">
56 <div class="paragraph"><p>For each datatype, tycon, and vector type, it builds and equality
57 function and translates calls to <span class="monospaced">MLton_equal</span> into calls to that
59 <div class="paragraph"><p>Also generates calls to <span class="monospaced">Word_equal</span>.</p></div>
60 <div class="paragraph"><p>For tuples, it does the equality test inline; i.e., it does not create
61 a separate equality function for each tuple type.</p></div>
62 <div class="paragraph"><p>All equality functions are created only if necessary, i.e., if
63 equality is actually used at a type.</p></div>
64 <div class="paragraph"><p>Optimizations:</p></div>
65 <div class="ulist"><ul>
68 for datatypes that are enumerations, do not build a case dispatch,
69 just use <span class="monospaced">MLton_eq</span>, as the backend will represent these as ints
74 deep equality always does an <span class="monospaced">MLton_eq</span> test first
79 If one argument to <span class="monospaced">=</span> is a constant and the type will get
80 translated to an <span class="monospaced">IntOrPointer</span>, then just use <span class="monospaced">eq</span> instead of the
81 full equality. This is important for implementing code like the
82 following efficiently:
84 <div class="listingblock">
85 <div class="content monospaced">
86 <pre>if x = 0 ... (* where x is of type IntInf.int *)</pre>
91 Also convert pointer equality on scalar types to type specific
99 <div id="footnotes"><hr></div>
101 <div id="footer-text">
103 <div id="footer-badges">