<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>XMLShrink</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>XMLShrink</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>XMLShrink is an optimization pass for the <a href="XML">XML</a>
<a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="XMLSimplify">XMLSimplify</a>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph"><p>This pass performs optimizations based on a reduction system.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_implementation">Implementation</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<a href="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.sig"><span class="monospaced">shrink.sig</span></a>
</p>
</li>
<li>
<p>
<a href="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.fun"><span class="monospaced">shrink.fun</span></a>
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_details_and_notes">Details and Notes</h2>
<div class="sectionbody">
<div class="paragraph"><p>The simplifier is based on <a href="References#AppelJim97"> Shrinking Lambda
Expressions in Linear Time</a>.</p></div>
<div class="paragraph"><p>The source program may contain functions that are only called once, or
not even called at all.  Match compilation introduces many such
functions.  In order to reduce the program size, speed up later
phases, and improve the flow analysis, a source to source simplifier
is run on <a href="XML">XML</a> after type inference and match compilation.</p></div>
<div class="paragraph"><p>The simplifier implements the reductions shown below.  The reductions
eliminate unnecessary declarations (see the side constraint in the
figure), applications where the function is immediate, and case
statements where the test is immediate.  Declarations can be
eliminated only when the expression is nonexpansive (see Section 4.7
of the <a href="DefinitionOfStandardML"> Definition</a>), which is a syntactic
condition that ensures that the expression has no effects
(assignments, raises, or nontermination).  The reductions on case
statements do not show the other irrelevant cases that may exist.  The
reductions were chosen so that they were strongly normalizing and so
that they never increased tree size.</p></div>
<div class="ulist"><ul>
<li>
<p>
</p>
<div class="openblock">
<div class="content">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>reduces to</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">e2</span><span class="w"> </span><span class="p">[</span><span class="n">x</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">e1</span><span class="p">]</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>if <span class="monospaced">e1</span> is a constant or variable or if <span class="monospaced">e1</span> is nonexpansive and <span class="monospaced">x</span> occurs zero or one time in <span class="monospaced">e2</span></p></div>
</div></div>
</li>
<li>
<p>
</p>
<div class="openblock">
<div class="content">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e1</span><span class="p">)</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>reduces to</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">e2</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">e1</span><span class="w"></span>
</pre></div></div></div>
</div></div>
</li>
<li>
<p>
</p>
<div class="openblock">
<div class="content">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">e1</span><span class="w"> </span><span class="k">handle</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>reduces to</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">e1</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>if <span class="monospaced">e1</span> is nonexpansive</p></div>
</div></div>
</li>
<li>
<p>
</p>
<div class="openblock">
<div class="content">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">case</span><span class="w"> </span><span class="k">let</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="k">end</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">p1</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="p">...</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>reduces to</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">let</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">p1</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</div></div>
</li>
<li>
<p>
</p>
<div class="openblock">
<div class="content">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">case</span><span class="w"> </span><span class="n">C</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">C</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>reduces to</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
</pre></div></div></div>
</div></div>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
