scala 编译器阶段的顺序是什么?
我想加深对 scala 编译阶段的了解。我知道编译器中必须发生某些事情,但并不真正知道它们发生的顺序以及顺序如何影响我的编程。
我说以下内容是编译器功能的完整列表,对吗?
- 解析程序
- 类型 检查
- 擦除
- 隐式转换
- 字节码 生成
- 优化
如果是,那么它执行这些阶段的顺序是什么? 这个顺序如何影响程序员,特别是类型级程序员?
I want to sharpen my picture of the phases of scala compilation. I know that certain things have to happen in the compiler, but don't really know the order in which they happen and how the order should affect my programming.
Am I right in saying that the following things are the full list of what the compiler does?
- parse program
- types checked
- do erasure
- implicit conversion
- byte-code generated
- optimize
If so, what is the order that it does these phases?
How does this order affect the programmer, especially the type-level programmer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 scalac -Xshow-phases 来查看各个阶段、它们的顺序和说明。
在 2.11 中,使用
-Xshow-phases -Ydebug
显示启用和禁用的阶段。2.10.0 的情况如下:
You see the phases, their order and explanation by using
scalac -Xshow-phases
.In 2.11, use
-Xshow-phases -Ydebug
to show both enabled and disabled phases.Here is how it's for 2.10.0:
您看过此处吗?该页面指向 http://www.scala-lang.org/sites/default/files/sids/nielsen/Thu,%202009-05-28,%2008:13/compiler-phases-sid .pdf (PDF),描述了 Scala 2.8 的编译器阶段。
Have you looked here? That page points to http://www.scala-lang.org/sites/default/files/sids/nielsen/Thu,%202009-05-28,%2008:13/compiler-phases-sid.pdf (PDF), which describes the compiler phases for Scala 2.8.
你真的不应该担心编译器阶段的顺序,除非你正在编写编译器插件。即使对于类型级编程,您也应该关注语言语义。
例如,就擦除而言,了解静态类型与动态类型以及单独编译的模型非常重要。同样,了解编译器应用隐式转换的条件也很重要。这些在编译周期中发生的地方只是一个实现细节。
You really should not worry about the order of compiler phases unless you're writing a compiler plugin. Even for type-level programming, you should focus on the language semantics instead.
As far as erasure is concerned, for example, it's important to understand static vs. dynamic types and the model of separate compilation. Similarly, it's important to understand the conditions under which the compiler will apply an implicit conversion. Where these occur in the compilation cycle is just an implementation detail.
Scala.js 0.6.23
Scala-Native 0.3.7
Scala.js 0.6.23
Scala-Native 0.3.7