Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the order of the scala compiler phases?

Tags:

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?

like image 796
dsg Avatar asked Dec 24 '10 18:12

dsg


People also ask

How does Scala compiler work?

Scala has both a compiler and an interpreter which can execute Scala code. The Scala compiler compiles your Scala code into Java Byte Code which can then be executed by the scala command. The scala command is similar to the java command, in that it executes your compiled Scala code.

Which compiler is used in Scala?

Scala Native is a Scala compiler that targets the LLVM compiler infrastructure to create executable code that uses a lightweight managed runtime, which uses the Boehm garbage collector.

What is Scalacoptions?

The Scala compiler scalac offers various compiler options, or flags, that change the compiler's default behavior. Some options just generate more compiler output in the form of diagnostics or warnings, while others change the result of compilation.

What is a plugin in Scala?

A compiler plugin is a compiler component that lives in a separate JAR file from the main compiler. The compiler can then load that plugin and gain extra functionality. This tutorial briefly walks you through writing a plugin for the Scala compiler.


1 Answers

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:

 » 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 
like image 162
pedrofurla Avatar answered Oct 21 '22 03:10

pedrofurla