Introduction to Dotty

Dotty is the new scala compiler that 2.13 Scala release will be using. It is based on the DOT in its internal structure. The calculus used in Dotty is same as that of DOT. Dotty is a faster compiler than the scala compiler that Scala 2 uses. In this blog, I’ll be discussing the advantages of dotty, its architecture and the features that have been dropped in this new compiler.

Advantages of Dotty over the current scala compiler:

– It is a bit more than half the size of current scala compiler.

– It is two times faster than the current scala compiler.

Dotty Architecture

Image result for dotty architecture scala

In this scala sources serve as an input to dotty frontend. Dotty frontend gives AST as output. ASTs are the Abstract Syntax Tree that is formed after the type checking. Then, some transformations are performed by Dotty before producing the final AST. This simplified AST looks much like a java program and it is made such that the tree has be traversed much less often. This adds to the reason why Dotty is faster. The final AST is then passed to the GenBCode that generates the bytecode that produces the class files. GenBCode uses Gen ASM standard cogeneration framework for java bytecodes. Then, there is pickled format too that essentially separates the compilation which doesn’t really have  a name. It picks up these serialized symbol tables and use them when your program needs to get compiled in different compilation unit. Then, there is a much richer format, called as TASTY type AST. It allows us to do whole program optimizations and everything is translated to TASTY and dotty transformations are performed over it.


Dropped Features in Dotty

Since Dotty is the new compiler that Scala 3 will be using, so the contributors made sure that unnecessary features be dropped. Some of the dropped features are explained in detail below:

1. Procedure Syntax

is now replaced with

Procedure Syntax can’t be used in Scala 2.13.

2. Early Initializer


If the code was written instead as

then a null pointer exception would occur when Z got initialized, because size is initialized before name in the normal ordering of initialization (superclass before class).

3. Macros

Macros are the functions that are called by the compiler during compilation. Macros have access to compiler level APIs. These micros now have been dropped. Now, Dotty provides inline and meta that can be used in place of macros.

4. Existential Types

Existential types are a way of abstracting over types. They let you “acknowledge” that there is a type involved without specifying exactly what it is, usually because you don’t know what it is and you don’t need that knowledge in the current context.  For more information, refer to Existential Types in Scala. Existential type using forSome now has been dropped from the current compiler Dotty beacuse these violate a type soundness principle on which DOT and Dotty are constructed. That principle says that every prefix (p, respectively S) of a type selection p. T or S#T must either come from a value constructed at runtime or refer to a type that is known to have only good bounds.

6. Type Projection

Scala so far allowed general type projection T#A where T is an arbitrary type and A names a type member of T.

Dotty disallows this if T is an abstract type (class types and type aliases are fine). This change was made because unrestricted type projection is unsound.

In this blog, I have given a brief introduction about Dotty. For more information, refer to the Dotty docs and Keynote: Scala’s Road Ahead by Martin Odersky. In the next blog, I’ll be covering the new features introduced by the Dotty.




Written by 

Aashrita Goel is an Intern having experience of more than 4 months. She is perceived as a cooperative person, devoted and capable expert and an innovation aficionado. She has great time administration and relational abilities. She believes in standard coding practices. Her emphasis dependably stays on functional work. Her hobbies include reading books and listening to music.

Leave a Reply

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!