What exactly is Dotty?
Officially, Dotty is a research compiler that will become Scala 3 — that is, it is a new Scala compiler that implements Scala 3. Scala 3 is fundamentally the same language as Scala 2, but aims to fix warts and improve support for some programming scenarios. The set of features supported by Dotty is evolving, and language additions will be reviewed in the end by the SIP committee.
Among other changes, the type system for Scala 3 is based upon a new foundation, called the DOT calculus; using this foundation affects which types you can use in your program, and increases confidence that if a program passes Dotty's typechecker, that program will not have type errors.
The Dotty project contains three ideas:
- The Dotty programming language
- The
dotc
compiler - The TASTY serialization format
All of these contribute multiple things:
Dotty: A language based on the DOT Calculus
The DOT Calculus (Dependent Object Types) is a new calculus developed by Martin Odersky's group. It is specifically designed to model a Scala-like language well. It replaces the older ν Object Calculus (that's the Greek letter ν, pronounced something like "new") that was also designed to model Scala, but contained features that were later removed from Scala. DOT is much simpler.
Dotty is a language whose type system and semantics are deeply rooted in the DOT calculus, thus, properties and proofs of the DOT calculus also apply to Dotty.
Dotty: A testbed for further evolution of Scala
Dotty is designed not only to be a superset of DOT calculus, but also to be similar enough to Scala that features tried out and tested in Dotty can be later ported to Scala.
In particular, Dotty has now become the basis of Scala 3, which is a significant re-design of Scala (for example, with Scala 3, Scala will become the first mainstream language to remove Generics from the language, which is exactly the opposite of what other languages like Java, C♯, VB.NET, or C++ have been doing). However, even though Scala 3 is a significant re-design of Scala, it is intended that any code that compiles without warnings and without deprecations in Scala 2.13 can be automatically converted to Scala 3. IOW: the conversion process from Scala 2.13 to Scala 3 is purely mechanical and needs no human intervention.
dotc
: A testbed for novel compiler designs
The dotc
compiler uses a novel design that is inspired by temporal databases. This is completely independent of DOT, the Dotty language, or Scala. It can (and will) be used to improve the Scala compiler, but the ideas can be applied to any compiler for any language.
dotc
: The foundation for a new Scala compiler
dotc
is not just a testbed for novel ideas in compiler design in general, it is also (and that is its second main purpose, after being a compiler for Dotty) the foundation for a complete re-design of the aging New Scala Compiler (the current, second, iteration of the Scala compiler after the original one written in Java).
The design of dotc
allows a lot of features that are expected from modern compilers nowadays that aren't well catered to by traditional batch compiler designs. The job of a modern compiler is not just to turn one language into another (e.g. Scala to JVML), it should
- report (human-readable, clearly understandable) errors
- suggest (and even perform) possible fixes for those errors
- report relevant and helpful warnings
- suggest (and even perform) possible improvements for those warnings
- perform refactorings
- provide lexical, syntactic, and semantic highlighting
- assist code completion
- and do all of that with incomplete code, while the code is being written, instantaneously
NSC's presentation compiler and toolbox can do a lot of that, but dotc
was designed from the ground up with those requirements in mind.
TASTY: a serialization format for semantic trees
The third contribution from the Dotty project is TASTY. TASTY is a serialization format for an intermediate compiler representation that features forwards- and backwards-compatibility, is compact, easy to parse, and contains all information necessary to reconstruct the original program while at the same time leaving out unnecessary detail.
TASTY allows to save the internal representation of a compiler and then load it into a different compiler and continue the compilation.
Why would you want to do this? It allows you to have an intermediate distribution format between source code and binary code (e.g. .class
or .jar
files). Distributing Scala code as .jar
s loses a lot of information about the Scala code. If you then want to link this code with some other Scala code, you may run into problems, especially with Scala 3, which moves some type-safety from the compile-phase to the link-phase.
Distributing it as source code, OTOH, requires that the user needs to have a full Scala development environment in order to use the library.
For those that remember it, the goals are somewhat similar to what ANDF tried to do in the 1980s.
Can somebody please explain to me what exactly dotty is?
As the dotty github page mentions:
Dotty is a research compiler that will become Scala 3
Also, read Martin Odersky's blog post Towards Scala 3, which mentions Scala 2 vs Scala 3:
It’s worth emphasizing that Scala 2 and Scala 3 are fundamentally the same language. The compiler is new, but nearly everything Scala programmers already know about Scala 2 applies to Scala 3 as well, and most ordinary Scala 2 code will also work on Scala 3 with only minor changes.
So why dotty?
Scala 3 will be a big step towards realizing the full potential of the fusion of OOP and fp in a typed setting
And you can see they are being developed differently:
- scalac: https://github.com/scala/scala
- dotc: https://github.com/lampepfl/dotty
For more read the reddit thread Towards Scala 3
Let me explain with foundation of Scala 3:
The Dependent Object Types (DOT) is a new foundation for Scala which is to be Scala 3. DOT is a core calculus for path-dependent types which enhance Scala language and its type systems to next level.
According to this blog by Martin Odersky:
"What do you get if you boil Scala on a slow flame and wait until all incidental features evaporate and only the most concentrated essence remains? After doing this for 8 years we believe we have the answer: it’s DOT, the calculus of dependent object types, that underlies Scala."
Therefore, In Scala 3, DOT - Dependent Object Type, has been implemented as foundation of Scala and DOTTY is a project for the development of Scala 3 with DOT. In addition, Scala 3 works on new compiler which is also called Dotty that support DOT and which is more powerful that current version of Scala compiler. Technically, For Scala 2 and below, scalac
is compiler, but for Scala 3, dotc
is a compiler.
So, the language specification are the same in Scala 2(below) and Scala 3, but the compiler is new which desugar to DOT. Also, with DOT as foundation, there are additional new features in Scala 3 e.g. union types, intersection-type etc.
Is DOTTY is new programming language?
No. Dotty is the project name for a language and compiler that is slated to become Scala 3.0, That means, DOTTY is next version of Scala programming language, with a new compiler (also called Dotty).
I hope this will give you beginner insight to dotty.