Inline Expansion (

The next optimization is the most effective one: inline expansion. It replaces calls to small functions with their bodies. MinCaml implements it in function Inline.g.

First, in the case of function definition let rec f x1 ... xn = e in ..., we compute the size of body e of the function f by Inline.size. If this size is less than integer reference Inline.threshold, we add the correspondence from the function name f to formal arguments x1, ..., xn and body e in the mapping env. Then, in the case of function call f y1 ... yn, we look up the formal arguments x1, ..., xn of f its body e from the mapping env, and return e with x1, ..., xn replaced by y1, ..., yn.

However, since inlined expressions are copies of function bodies, their variables may be duplicated and therefore must be α-converted again. Accidentally or not, the previous process of "replacing formal arguments with actual arguments" can be done by Alpha.g together with α-conversion, just by using the correspondence from x1, ..., xn to y1, ..., yn (instead of an empty mapping) as the initial mapping env.