Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Scala Experimental Platform Dotty Bootstraps

Scala Experimental Platform Dotty Bootstraps


Dotty, a platform aimed to develop new technology for Scala tooling as well as try out new concepts for future Scala versions, has reached bootstrap status. This means that its compiler is written in Dotty and can compile itself, thus providing a drop-in replacement for the original one.

Dotty was announced in early 2014 by Martin Odersky (@odersky) with the goal of providing a platform where new ideas for Scala can be tried out without incurring the limitations of backward compatibility requirements. Mostly, Odersky noted, Dotty tries to do away with Scala features that are deemed to be inessential, such as XML literals as part of the language, and to streamline Scala type system using a set of more fundamental constructors. One of the future goals for Dotty could also be, as Odersky noted in a Stack Overflow answer, simplifying the type system so it is not Turing complete anymore. This would require removing such features as type members in structural types.

The Dotty language roadmap includes new language features such as:

  • Union and intersection types, denoted respectively by | and &. Intersection types are similar to with types provided by Scala 2 but are not ordered, so A & B is the same as B & A.

    def foo(arg: Serializable & Comparable): Unit
    trait A {
      type T = Int
    trait B {
      type T = Double
    (A with B) # T == Int
    (A & B) # T == Int & Double

    Union types have no equivalent in Scala, though:

    class A(x: Int)
    class B(x: Int)
    class C(x: Array[Int])
    object Test{
      def foo(x: A | B): Int = x.x
      def bar(x: A | C): Int | Array[Int] = x.x

    Union types can also be used inside enumerations.

  • Literal-based singleton types, which will allow to write:

    object Literals{
      val fortyTwo: 42 = 42
      val `2`: 2 = 2
      val fortyFour: 44 = fortyTwo + `2`
      val text: "text" = "text"
      def id[T](a: T) = a
      val two: 2 = id(`2`)

    Other language features that Dotty already implements include repeated by name parameters, trait parameters, and improved lazy vals initialization.

On the tooling front, dotty supports TASTY, an interchange format that stores typed syntax trees. The basic idea of TASTY originates form Scala.meta, a friend project of Dotty developed by Eugene Burmako (@xeno_by) and his team, which aims to improve Scala metaprogramming.

Dotty has a strong focus on performance and is developed with compilation speed in mind. As Dmitry Petrashko (@DarkDimius), major contributor to Dotty along with Odersky, stated to InfoQ, "though no hand-tuning of performance was performed, dotc it is already on par with scalac".

Another friend project of Dotty is Linker, that addresses performance of compiled code. This play a key role in Petrashko's aim to allow developer to "write code that is easy to maintain", while leaving the task of optimization to semantic-aware optimisers.

InfoQ has spoken with Petrashko to learn more about this project.

Could you explain the importance of bootstrapping Dooty? What does it mean for the evolution of the language?

Dotty is a platform where we experiment on new technologies for Scala. The heart of this platform is the dotc compiler that is a rewrite of scalac. Starting with a new and clean design allows us to iterate faster on new ideas.

Before we start experimenting with new language features we need be verify that we can trust our compiler. Bootstrapping the compiler means that the compiler can compile itself and the resulting application can be used instead of the original compiler.

Compilers are huge beasts that exercise various hard-to-compile combinations of language features. Multiple things could go wrong. Having a successful bootstrap gives us confidence that the compiler is mature enough to start experimenting with new language features.

What projects are you using to test out new language features and the tools you are developing?

Martin has recently kicked off a discussion about a redesign of the standard collection library. There have already been a number of exciting proposals that improve upon the state of the art. We are currently experimenting on how new features of Dotty could help in making collections easier to use and maintain.

Scala.meta is involved in Dotty from the metaprogramming point of view. We want Dotty to have a consistent and compatible API for compile-time metaprogramming and tooling (linters, formatters, etc), and for that we need support from scala.meta.

Dotty-Linker is a project that aims at optimising highly generic Scala code. With presence of TASTY in the ecosystem new optimisation opportunities are arising, such as on-demand specialization and smart inlining that would improve runtime performance and decrease allocation rates. We want to allow people to write code in functional style without worrying about abstraction overheads.

What are the next major milestones you have defined?

The next major milestones are expected on the tooling side:

We are currently working on making dotc available as a compiler for sbt. This should give us incremental compilation and will simplify compiling real-world projects with Dotty;

Given new language features, we will need an IDE that would support them. We are currently considering the options, and it seems that the best way would be to implement a Scala.meta-based presentation compiler API that could then be used by ENSIME and others. It’s too early to say if we will actually go this way though.

Dotty is available on GitHub.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p