javascript - 世界上有没有针对简单函数式语言自身的强大优化编译器?

标签 javascript haskell optimization compiler-construction scheme

<分区>

世界上是否存在针对简单函数式语言的编译器,例如定义 on this article 的编译器? ,或者只是 Scheme 甚至 ML 本身?也就是说,一个编译器会分析该简单函数式语言的代码,执行复杂的优化(例如流融合)并返回优化后的代码?

我需要这个的原因是我正在尝试将我的简单玩具语言(相当多的 lambda 演算 + 数字和数组)编译为 JavaScript,但事实上,由于天真的编译器,它非常慢完全没有优化。函数不是 uncurried,诸如 (map f (map g h)) 之类的东西不会融合到 (map (f . g) h) 中。实现优化编译器会造成 much work .我考虑过利用现有的编译器,例如 GHC,但我还没有决定如何实现。例如,我可以将我的语言编译为 Haskell,然后将其编译回 JavaScript,但大多数 Haskell->JS 解决方案都不是最优的,并且会产生大量开销。这种现有的针对简单函数式语言的强大优化编译器本身会减少很多工作。世界上有吗?

最佳答案

GHC可以产生GHC-Core,这是一种中间原始的类Haskell语言。它是在编译器的所有优化之后上演的,包括像流融合这样的高级东西。所以我想它可能是您任务的完美人选。

来自 the docs :

The Glasgow Haskell Compiler (GHC) uses an intermediate language, called “Core,” as its internal program representation within the compiler’s simplification phase. Core resembles a subset of Haskell, but with explicit type annotations in the style of the polymorphic lambda calculus (Fω).

GHC’s front-end translates full Haskell 98 (plus some extensions) into Core. The GHC optimizer then repeatedly transforms Core programs while preserving their meaning. A “Core Lint” pass in GHC typechecks Core in between transformation passes (at least when the user enables linting by setting a compiler flag), verifying that transformations preserve type-correctness. Finally, GHC’s back-end translates Core into STG-machine code [stg-machine] and then into C or native code.

关于javascript - 世界上有没有针对简单函数式语言自身的强大优化编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20921134/

相关文章:

javascript - D3 旭日。如何设置不同的环\层宽度

asp.net - 是否可以优化ASP.NET WebForms以使其执行速度与ASP.NET MVC一样快?

c++ - 将 39567865 个无符号字符加载到 RAM : Valid approach?

javascript - 有什么方法可以实现 "optimize"这个简单的函数吗? (我没有遵循最佳实践吗?)

haskell - 在枚举上构建 absurd 谓词的证明时,有什么技巧可以摆脱样板文件?

javascript - 在 Angular 6 中使用 toPromise 的正确方法

javascript - 如何像 Ember.js 那样抽象 ajax 请求的异步行为?

javascript - AngularJS : Guidance to implement a factory, 服务、指令或其他

haskell - 有没有办法断言编译器将函数识别为尾递归?

function - 具有不同数量参数的函数的类型类