24

scala コンパイルのフェーズのイメージを明確にしたいと思います。コンパイラで特定のことが発生する必要があることは知っていますが、それらが発生する順序と、その順序がプログラミングにどのように影響するかはよくわかりません。

次のことは、コンパイラが行うことの完全なリストであると言っているのは正しいですか?

  • 解析プログラム
  • タイプをチェック
  • 消去する
  • 暗黙の変換
  • 生成されたバイトコード
  • 最適化

もしそうなら、これらのフェーズを実行する順序は何ですか? この順序は、プログラマー、特に型レベルのプログラマーにどのように影響しますか?

4

4 に答える 4

51

を使用すると、フェーズ、その順序、および説明が表示され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
于 2010-12-24T19:45:21.553 に答える
10

ここを見ましたか?そのページはhttp://www.scala-lang.org/sites/default/files/sids/nielsen/Thu,%202009-05-28,%2008:13/compiler-phases-sid.pdf (PDF)を指しています、Scala 2.8 のコンパイラ フェーズについて説明します。

于 2010-12-24T19:07:06.520 に答える
2

コンパイラ プラグインを作成する場合を除き、コンパイラ フェーズの順序を気にする必要はありません。型レベルのプログラミングであっても、代わりに言語のセマンティクスに注目する必要があります。

たとえば、消去に関する限り、静的型と動的型、および個別のコンパイルのモデルを理解することが重要です。同様に、コンパイラが暗黙的な変換を適用する条件を理解することも重要です。これらがコンパイル サイクルで発生する場所は、単なる実装の詳細です。

于 2010-12-25T00:15:41.947 に答える