Debian Codegraph @

doc/guide/src/XMLShrink.adoc

raw
1 = XMLShrink
2
3 XMLShrink is an optimization pass for the <<XML#>>
4 <<IntermediateLanguage#>>, invoked from <<XMLSimplify#>>.
5
6 == Description
7
8 This pass performs optimizations based on a reduction system.
9
10 == Implementation
11
12 * https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.sig[`shrink.sig`]
13 * https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.fun[`shrink.fun`]
14
15 == Details and Notes
16
17 The simplifier is based on <<References#AppelJim97,Shrinking Lambda
18 Expressions in Linear Time>>.
19
20 The source program may contain functions that are only called once, or
21 not even called at all. Match compilation introduces many such
22 functions. In order to reduce the program size, speed up later
23 phases, and improve the flow analysis, a source to source simplifier
24 is run on <<XML#>> after type inference and match compilation.
25
26 The simplifier implements the reductions shown below. The reductions
27 eliminate unnecessary declarations (see the side constraint in the
28 figure), applications where the function is immediate, and case
29 statements where the test is immediate. Declarations can be
30 eliminated only when the expression is nonexpansive (see Section 4.7
31 of the <<DefinitionOfStandardML#,Definition>>), which is a syntactic
32 condition that ensures that the expression has no effects
33 (assignments, raises, or nontermination). The reductions on case
34 statements do not show the other irrelevant cases that may exist. The
35 reductions were chosen so that they were strongly normalizing and so
36 that they never increased tree size.
37
38 * {empty}
39 +
40 --
41 [source,sml]
42 ----
43 let x = e1 in e2
44 ----
45
46 reduces to
47
48 [source,sml]
49 ----
50 e2 [x -> e1]
51 ----
52
53 if `e1` is a constant or variable or if `e1` is nonexpansive and `x` occurs zero or one time in `e2`
54 --
55
56 * {empty}
57 +
58 --
59 [source,sml]
60 ----
61 (fn x => e1) e2
62 ----
63
64 reduces to
65
66 [source,sml]
67 ----
68 let x = e2 in e1
69 ----
70 --
71
72 * {empty}
73 +
74 --
75 [source,sml]
76 ----
77 e1 handle e2
78 ----
79
80 reduces to
81
82 [source,sml]
83 ----
84 e1
85 ----
86
87 if `e1` is nonexpansive
88 --
89
90 * {empty}
91 +
92 --
93 [source,sml]
94 ----
95 case let d in e end of p1 => e1 ...
96 ----
97
98 reduces to
99
100 [source,sml]
101 ----
102 let d in case e of p1 => e1 ... end
103 ----
104 --
105
106 * {empty}
107 +
108 --
109 [source,sml]
110 ----
111 case C e1 of C x => e2
112 ----
113
114 reduces to
115
116 [source,sml]
117 ----
118 let x = e1 in e2
119 ----
120 --