Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / DeadCode.adoc
CommitLineData
7f918cf1
CE
1DeadCode
2========
3
4<:DeadCode:> is an optimization pass for the <:CoreML:>
5<:IntermediateLanguage:>, invoked from <:CoreMLSimplify:>.
6
7== Description ==
8
9This pass eliminates declarations from the
10<:BasisLibrary:Basis Library> not needed by the user program.
11
12== Implementation ==
13
14* <!ViewGitFile(mlton,master,mlton/core-ml/dead-code.sig)>
15* <!ViewGitFile(mlton,master,mlton/core-ml/dead-code.fun)>
16
17== Details and Notes ==
18
19In order to compile small programs rapidly, a pass of dead code
20elimination is run in order to eliminate as much of the Basis Library
21as possible. The dead code elimination algorithm used is not safe in
22general, and only works because the Basis Library implementation has
23special properties:
24
25* it terminates
26* it performs no I/O
27
28The dead code elimination includes the minimal set of
29declarations from the Basis Library so that there are no free
30variables in the user program (or remaining Basis Library
31implementation). It has a special hack to include all
32bindings of the form:
33[source,sml]
34----
35 val _ = ...
36----
37
38There is an <:MLBasisAnnotations:ML Basis annotation>,
39`deadCode true`, that governs which code is subject to this unsafe
40dead-code elimination.