Debian Codegraph @

doc/guide/src/SimplifyTypes.adoc

raw
1 = SimplifyTypes
2
3 <<SimplifyTypes#>> is an optimization pass for the <<SSA#>>
4 <<IntermediateLanguage#>>, invoked from <<SSASimplify#>>.
5
6 == Description
7
8 This pass computes a "cardinality" of each datatype, which is an
9 abstraction of the number of values of the datatype.
10
11 * `Zero` means the datatype has no values (except for bottom).
12 * `One` means the datatype has one value (except for bottom).
13 * `Many` means the datatype has many values.
14
15 This pass removes all datatypes whose cardinality is `Zero` or `One`
16 and removes:
17
18 * components of tuples
19 * function args
20 * constructor args
21
22 which are such datatypes.
23
24 This pass marks constructors as one of:
25
26 * `Useless`: it never appears in a `ConApp`.
27 * `Transparent`: it is the only variant in its datatype and its argument type does not contain any uses of `array` or `vector`.
28 * `Useful`: otherwise
29
30 This pass also removes `Useless` and `Transparent` constructors.
31
32 == Implementation
33
34 * https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify-types.fun[`simplify-types.fun`]
35
36 == Details and Notes
37
38 This pass must happen before polymorphic equality is implemented because
39
40 * it will make polymorphic equality faster because some types are simpler
41 * it removes uses of polymorphic equality that must return true
42
43 We must keep track of `Transparent` constructors whose argument type
44 uses `array` because of datatypes like the following:
45 [source,sml]
46 ----
47 datatype t = T of t array
48 ----
49
50 Such a datatype has `Cardinality.Many`, but we cannot eliminate the
51 datatype and replace the lhs by the rhs, i.e. we must keep the
52 circularity around.
53
54 Must do similar things for `vectors`.
55
56 Also, to eliminate as many `Transparent` constructors as possible, for
57 something like the following,
58 [source,sml]
59 ----
60 datatype t = T of u array
61 and u = U of t vector
62 ----
63 we (arbitrarily) expand one of the datatypes first. The result will
64 be something like
65 [source,sml]
66 ----
67 datatype u = U of u array vector
68 ----
69 where all uses of `t` are replaced by `u array`.