我想加深对 scala 编译阶段的了解。我知道编译器中必须发生某些事情,但并不真正知道它们发生的顺序以及这些顺序如何影响我的编程。
我说以下内容是编译器功能的完整列表,对吗?
- 解析程序
- 已检查类型
- 删除
- 隐式转换
- 生成的字节码
- 优化
如果是这样,这些阶段的执行顺序是什么? 这个顺序如何影响程序员,特别是类型级程序员?
最佳答案
您可以使用scalac -Xshow-phases
查看各个阶段、它们的顺序和说明。
在 2.11 中,使用 -Xshow-phases -Ydebug
显示启用和禁用的阶段。
以下是 2.10.0 的情况:
» scalac -Xshow-phases
phase name id description
---------- -- -----------
parser 1 parse source into ASTs, perform simple desugaring
namer 2 resolve names, attach symbols to named trees
packageobjects 3 load package objects
typer 4 the meat and potatoes: type the trees
patmat 5 translate match expressions
superaccessors 6 add super accessors in traits and nested classes
extmethods 7 add extension methods for inline classes
pickler 8 serialize symbol tables
refchecks 9 reference/override checking, translate nested objects
selectiveanf 10
selectivecps 11
uncurry 12 uncurry, translate function values to anonymous classes
tailcalls 13 replace tail calls by jumps
specialize 14 @specialized-driven class and method specialization
explicitouter 15 this refs to outer pointers, translate patterns
erasure 16 erase types, add interfaces for traits
posterasure 17 clean up erased inline classes
lazyvals 18 allocate bitmaps, translate lazy vals into lazified defs
lambdalift 19 move nested functions to top level
constructors 20 move field definitions into constructors
flatten 21 eliminate inner classes
mixin 22 mixin composition
cleanup 23 platform-specific cleanups, generate reflective calls
icode 24 generate portable intermediate code
inliner 25 optimization: do inlining
inlineExceptionHandlers 26 optimization: inline exception handlers
closelim 27 optimization: eliminate uncalled closures
dce 28 optimization: eliminate dead code
jvm 29 generate JVM bytecode
terminal 30 The last phase in the compiler chain
关于scala - scala 编译器阶段的顺序是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4527902/