Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

compiler construction - What is "Lambda Lifting"?

I just ran into this while going through the Erlang compiler source.

I'm not really getting it. (go figure ;)), considering that I just realized that there is such a thing 5 minutes ago).

Forgive me for asking first without first trying to understand reasons for its existence.

There is a wikipedia article about it, but it is pretty cryptic.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Lambda lifting is used to turn a closure into a pure function. By passing extra arguments to the function, you reduce the number of its free variables. As you "lift" the lambda into higher and higher scopes, you add arguments to accommodate the local variables declared in that scope (which would be free variables otherwise). Once the lambda has no free variables it is a pure "top level" function.

Of course you can only do this if you know all the lambda's call sites; in other words, only if the lambda does not escape.

The benefit in a compiler optimizer is that closures (function environments) can be eliminated. This might make it possible to pass the arguments in registers rather than stack (or heap) allocating them as free variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...