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