Dotty Documentation

0.17.0-bin-SNAPSHOT

Workflow

Edit this page on GitHub

Check Getting Started for instructions on how to obtain the source code of dotty and Eclipse or IntelliJ-IDEA. This document details common workflow patterns when working with Dotty before using the debugging tools.

Compiling files with dotc

As we have seen you can compile a test file either from sbt:

$ sbt
> dotc <OPTIONS> <FILE>

or from terminal:

$ dotc <OPTIONS> <FILE>

Here are some useful debugging <OPTIONS>:

  • -Xprint:PHASE1,PHASE2,... or -Xprint:all: prints the AST after each specified phase. Phase names can be found by examining the dotty.tools.dotc.transform.* classes for their phaseName field e.g., -Xprint:erasure. You can discover all phases in the dotty.tools.dotc.Compiler class
  • -Ylog:PHASE1,PHASE2,... or -Ylog:all: enables ctx.log("") logging for the specified phase.
  • -Ycheck:all verifies the consistency of AST nodes between phases, in particular checks that types do not change. Some phases currently can't be Ychecked, therefore in the tests we run: -Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef.
  • the last frontier of debugging (before actual debugging) is the range of logging capabilities that can be enabled through the dotty.tools.dotc.config.Printers object. Change any of the desired printer from noPrinter to default and this will give you the full logging capability of the compiler.

Inspecting Trees with Type Stealer

There is no power mode for the REPL yet, but you can inspect types with the type stealer:

$ sbt 
> repl
scala> import dotty.tools.DottyTypeStealer._; import dotty.tools.dotc.core._; import Contexts._,Types._

Now, you can define types and access their representation. For example:

scala> val s = stealType("class O { type X }", "O#X")
scala> implicit val ctx: Context = s._1
scala> val t = s._2(0)
t: dotty.tools.dotc.core.Types.Type = TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),O),X)
scala> val u = t.asInstanceOf[TypeRef].underlying
u: dotty.tools.dotc.core.Types.Type = TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing), TypeRef(ThisType(TypeRef(NoPrefix,scala)),Any))

Pretty-printing

Many objects in the dotc compiler implement a Showable trait (e.g. Tree, Symbol, Type). These objects may be prettyprinted using the .show method

SBT Commands Cheat Sheet

The basics of working with Dotty codebase are documented here and here. Below is a cheat sheet of some frequently used commands (to be used from SBT console – sbt).

CommandDescription
dotc ../issues/Playground.scalaCompile the given file – path relative to the Dotty directory. Output the compiled class files to the Dotty directory itself.
dotr PlaygroundRun the compiled class Playground. Dotty directory is on classpath by default.
replStart REPL
testOnly dotty.tools.dotc.CompilationTests -- *posRun test (method) pos from CompilationTests suite.
testCompilation sampleIn all test suites, run test files containing the word sample in their title.