Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / PolyEqual.adoc
1 PolyEqual
2 =========
3
4 <:PolyEqual:> is an optimization pass for the <:SSA:>
5 <:IntermediateLanguage:>, invoked from <:SSASimplify:>.
6
7 == Description ==
8
9 This pass implements polymorphic equality.
10
11 == Implementation ==
12
13 * <!ViewGitFile(mlton,master,mlton/ssa/poly-equal.fun)>
14
15 == Details and Notes ==
16
17 For each datatype, tycon, and vector type, it builds and equality
18 function and translates calls to `MLton_equal` into calls to that
19 function.
20
21 Also generates calls to `Word_equal`.
22
23 For tuples, it does the equality test inline; i.e., it does not create
24 a separate equality function for each tuple type.
25
26 All equality functions are created only if necessary, i.e., if
27 equality is actually used at a type.
28
29 Optimizations:
30
31 * for datatypes that are enumerations, do not build a case dispatch,
32 just use `MLton_eq`, as the backend will represent these as ints
33
34 * deep equality always does an `MLton_eq` test first
35
36 * If one argument to `=` is a constant and the type will get
37 translated to an `IntOrPointer`, then just use `eq` instead of the
38 full equality. This is important for implementing code like the
39 following efficiently:
40 +
41 ----
42 if x = 0 ... (* where x is of type IntInf.int *)
43 ----
44
45 * Also convert pointer equality on scalar types to type specific
46 primitives.