| 1 |
= LambdaFree |
| 2 |
|
| 3 |
<<LambdaFree#>> is an analysis pass for the <<SXML#>> |
| 4 |
<<IntermediateLanguage#>>, invoked from <<ClosureConvert#>>. |
| 5 |
|
| 6 |
== Description |
| 7 |
|
| 8 |
This pass descends the entire <<SXML#>> program and attaches a property |
| 9 |
to each `Lambda` `PrimExp.t` in the program. Then, you can use |
| 10 |
`lambdaFree` and `lambdaRec` to get free variables of that `Lambda`. |
| 11 |
|
| 12 |
== Implementation |
| 13 |
|
| 14 |
* https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig[`lambda-free.sig`] |
| 15 |
* https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun[`lambda-free.fun`] |
| 16 |
|
| 17 |
== Details and Notes |
| 18 |
|
| 19 |
For `Lambda`-s bound in a `Fun` dec, `lambdaFree` gives the union of |
| 20 |
the frees of the entire group of mutually recursive functions. Hence, |
| 21 |
`lambdaFree` for every `Lambda` in a single `Fun` dec is the same. |
| 22 |
Furthermore, for a `Lambda` bound in a `Fun` dec, `lambdaRec` gives |
| 23 |
the list of other functions bound in the same dec defining that |
| 24 |
`Lambda`. |
| 25 |
|
| 26 |
For example: |
| 27 |
---- |
| 28 |
val rec f = fn x => ... y ... g ... f ... |
| 29 |
and g = fn z => ... f ... w ... |
| 30 |
---- |
| 31 |
|
| 32 |
---- |
| 33 |
lambdaFree(fn x =>) = [y, w] |
| 34 |
lambdaFree(fn z =>) = [y, w] |
| 35 |
lambdaRec(fn x =>) = [g, f] |
| 36 |
lambdaRec(fn z =>) = [f] |
| 37 |
---- |