编程语言与软件工程2022dakkak.dev
Wolfram Language 编译器的设计与实现
The Design and Implementation of the Wolfram Language Compiler (2020)
进阶 · 约 60 分钟读完前置知识:编译器基础、中间表示与 SSA、运行时与去优化
导读
这篇论文(CGO 2020)介绍了 Wolfram 语言编译器的设计与实现,包括从 Wolfram 表达式到机器码的编译流水线、自定义中间表示(MExpr→WIR→TWIR→code)、SSA 形式以及软失败/去优化机制。论文还讨论了基准测试与测试套件,展示了将高层脚本语言编译为高效机器码的工程实践。
HN 关注点:这是首次详细披露 Wolfram 语言(Mathematica)内部编译机制,评论者将其与 JavaScript 引擎的编译技术(如 JSC 的 DFG、OSR exit)进行对比,并讨论基准测试和测试套件的充分性。
HN 评论精选
这几条评论里:补充 1
补充专业解读:将 Wolfram 的编译技术(软失败、自定义 IR、SSA)与 JavaScript 引擎(如 JSC 的 DFG/OSR exit)对比,并指出基准测试和测试套件的不足。
很高兴看到 Wolfram 编译过程的描述。我用 Wolfram 语言很久了,但从未真正了解其内部。几点想法: - 论文似乎暗示脚本语言的编译在学术界之外不常用。实际上这非常普遍——所有主流浏览器都对 JavaScript 做编译。 - 他们所说的“软失败模式”就是我所说的“OSR 退出”或别人所说的“去优化”。知道 Wolfram 也这么做很有趣! - 我喜欢他们设计了新的 IR,而不是复用其他东西,或者更糟地在字节码或 AST 上跑优化。直接采用 SSA 也很棒。MExpr->WIR->TWIR->code 流水线类似于 JavaScriptCore 的 DFG 编译器。我们用“DFG IR”指代有类型和无类型形式,但这和他们的做法完全一样。 - 他们可以用更好的基准测试,并且更多。简单的编译器在小基准上表现良好。一旦工作负载非常大且复杂,你就开始在编译器里加入更疯狂的东西。当你的基准语料库达到 100 万行代码以上时,你会学到很多。 - 有数千个测试让我觉得“真可爱”。JavaScriptCore 有近 10 万个测试。但数千个测试总比没有好,当然不同人对“一个测试”的定义不同——可能他们的一个测试覆盖了我们的数百个测试。
pizlonator查看英文原文
Super cool to see a description of how Wolfram is compiled. I've used the Wolfram language for a long time but never really took a peak inside. Some thoughts: - The paper seems to suggest that compilation of scripting languages is not widely used outside academia. In fact, it's super common - all major browsers do it for JavaScript. - What they call "soft failure mode" is what I would call "OSR exit" or what others would call "deoptimization". It's neat to know that Wolfram does this! - I love that they designed a new IR rather than trying to reuse something else, or worse, trying to run optimizations over bytecode or AST. Also great that they go straight to SSA. The MExpr->WIR->TWIR->code pipeline is similar to what happens in JavaScriptCore's DFG compiler. We use the term "DFG IR" to refer to both the typed and untyped form, but it's exactly the same idea as what they're doing. - They could use better benchmarks and more of them. Simple compilers do well on small benchmarks. Once workloads get very large and complex, you start to add even more crazy to the compiler. You learn a ton when your benchmark corpus goes to 1,000,000 LoC or beyond. - The fact that there are thousands of tests makes me say "awww how cute". JavaScriptCore has close to 100,000 tests. But, thousands of tests is better than no tests, and of course different folks mean different things by "one test" - it's possible that one of their tests covers the equivalent of what 100s of our tests would cover. Anyway, congratulations are in order - this is great work. It's always fun to see new compiler work for interesting languages, and Wolfram definitely qualifies as a particularly interesting language.
历次讨论
- 2022Hacker News 讨论帖145 分 · 18 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选