4 <:SimplifyTypes:> is an optimization pass for the <:SSA:>
5 <:IntermediateLanguage:>, invoked from <:SSASimplify:>.
9 This pass computes a "cardinality" of each datatype, which is an
10 abstraction of the number of values of the datatype.
12 * `Zero` means the datatype has no values (except for bottom).
13 * `One` means the datatype has one value (except for bottom).
14 * `Many` means the datatype has many values.
16 This pass removes all datatypes whose cardinality is `Zero` or `One`
19 * components of tuples
23 which are such datatypes.
25 This pass marks constructors as one of:
27 * `Useless`: it never appears in a `ConApp`.
28 * `Transparent`: it is the only variant in its datatype and its argument type does not contain any uses of `array` or `vector`.
31 This pass also removes `Useless` and `Transparent` constructors.
35 * <!ViewGitFile(mlton,master,mlton/ssa/simplify-types.fun)>
37 == Details and Notes ==
39 This pass must happen before polymorphic equality is implemented because
41 * it will make polymorphic equality faster because some types are simpler
42 * it removes uses of polymorphic equality that must return true
44 We must keep track of `Transparent` constructors whose argument type
45 uses `array` because of datatypes like the following:
48 datatype t = T of t array
51 Such a datatype has `Cardinality.Many`, but we cannot eliminate the
52 datatype and replace the lhs by the rhs, i.e. we must keep the
55 Must do similar things for `vectors`.
57 Also, to eliminate as many `Transparent` constructors as possible, for
58 something like the following,
61 datatype t = T of u array
64 we (arbitrarily) expand one of the datatypes first. The result will
68 datatype u = U of u array array
70 where all uses of `t` are replaced by `u array`.