什么是“Lambda 提升"? [英] What is "Lambda Lifting"?

查看:29
本文介绍了什么是“Lambda 提升"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在浏览 Erlang 编译器源代码时遇到了这个问题.

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

我不太明白.(去图;)),考虑到我刚刚意识到 5 分钟前有这样的事情).

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.

推荐答案

Lambda 提升用于将闭包转换为纯函数.通过向函数传递额外的参数,您可以减少其自由变量的数量.当您将 lambda 提升"到越来越高的范围时,您添加参数以容纳在该范围内声明的局部变量(否则将是自由变量).一旦 lambda 没有自由变量,它就是一个纯粹的顶级"函数.

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.

当然,只有在您了解 lambda 的所有调用站点的情况下才能执行此操作;换句话说,只有当 lambda 没有逃逸时.

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.

这篇关于什么是“Lambda 提升"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆