38

I am reading about Scala 3 and discovered dotty. I am trying to understand what it is. Somewhere I read "It is new compiler", somewhere I read "It is part of Scala 3", and somewhere I read "Dotty is new Scala 3".

Can somebody please explain to me what exactly dotty is? In layman's and technical terms?

PS: I have already read the tag info of on StackOverflow but didn't really understand it.

stefanobaghino
  • 11,253
  • 4
  • 35
  • 63
nomadSK25
  • 2,350
  • 3
  • 25
  • 36

6 Answers6

41

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.

Community
  • 1
  • 1
Ra Ka
  • 2,995
  • 3
  • 23
  • 31
  • 6
    `dottyc` doesn't exist, the compiler tool is called `dotc`. And the language specification will have to evolve for Scala 3. – Blaisorblade Jul 26 '18 at 11:33
  • Yes, its `dotc`, my mistake :). – Ra Ka Jul 27 '18 at 05:25
  • 4
    This is full of errors. Dotty is simply the code name for the language that is slated (imminently now) to become the next generation Scala (Scala 3.0 and beyond). There is no compiler called dotty. The Dotty compiler is currently called dotc, but will be renamed scalac in the very near future. And Dotty does not "support" DOT ... DOT is a type calculus used to prove that Dotty's type system is sound. – Jim Balter Sep 28 '20 at 00:31
13

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 .jars 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.

Community
  • 1
  • 1
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • Hey @Jorg from where I get the complete information about TASTY? Your explanation is really nice. do you have sources of dotty for study? – Harmeet Singh Taara Jul 06 '19 at 21:48
  • 3
    "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" -- what a bizarre claim ... generics are not being removed from the language. Here's what you're presumably referring to: https://contributors.scala-lang.org/t/proposal-to-remove-existential-types-from-the-language/2785/8 "the conversion process from Scala 2.13 to Scala 3 is purely mechanical and needs no human intervention" -- for a lot of code, but certainly not all. – Jim Balter Sep 28 '20 at 00:43
  • @JimBalter: This is based on a statement made Martin Odersky, where he explained that type members can do everything generics can, and thus generics are not needed. He further said that the existing type constructor syntax will be kept, but it will simply be syntactic sugar where a type parameter in the type constructor becomes a type member that is only accessible within the template, similar to how value parameters in a constructor become fields. It may very well be the case that this has changed since then. – Jörg W Mittag Sep 28 '20 at 07:15
  • Without a citation, I will continue to think you're confused. Dotty partially removes existential types, and removes type projection, but does not remove parametric polymorphism = "generics". Even if type constructor syntax is syntactic sugar for something more basic, that does not remove generics from the language. – Jim Balter Sep 28 '20 at 13:43
  • @JimBalter [This](https://github.com/lampepfl/dotty/blob/805a2d7553c719153ead1c1f2958434194cd8de9/docs/docs/internals/higher-kinded-v2.md#the-duality) piece of documentation seems to support Jörg W Mittag's claim. As to whether or not that can be called "removing generics", I don't know. I haven't been able to find anything about how type parameters on methods will be treated, but if they are encoded the same as they used to be in Scala 2, I don't think one can say Scala 3 will have really removed generics. – user Nov 10 '20 at 20:20
  • 2
    @user " if they are encoded the same as they used to be in Scala 2, I don't think one can say Scala 3 will have really removed generics" -- so you agree with my statement that "Even if type constructor syntax is syntactic sugar for something more basic, that does not remove generics from the language". Even Jörg said "the existing type constructor syntax will be kept". – Jim Balter Nov 11 '20 at 00:17
  • @user To put it another way: classes with type parameters *are* generic classes. So the claim in the answer that "Scala will become the first mainstream language to remove Generics from the language" is simply wrong. Had "other languages like Java, C♯, VB.NET, or C++" added type parameters, with or without providing sugary syntax like 'Foo", it would have been correct to say that generics had been added to those languages. – Jim Balter Nov 11 '20 at 00:39
  • 2
    BTW, the Nim language has a "typedesc" type that allows passing type parameters to functions--they are functionally equivalent to the "[T]" syntax (which is also allowed). – Jim Balter Nov 11 '20 at 00:50
  • 2
    By the way, Martin Odersky wrote said [here](https://contributors.scala-lang.org/t/scala-3-type-parameters-and-type-members/3472/3) in 2019 that they'd dropped the type parameter-as-type member encoding and made it a first class feature again, so you may want to update your answer about that. – user Nov 21 '20 at 23:45
  • 2
    @user LOL! How ironic. Of course, it was never the case that generics were removed from the language ... as I noted above, classes with type parameters *are* generic classes. – Jim Balter Dec 08 '20 at 23:20
8

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:

For more read the reddit thread Towards Scala 3

Jens Hoffmann
  • 6,699
  • 2
  • 25
  • 31
prayagupa
  • 30,204
  • 14
  • 155
  • 192
3

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.

Blaisorblade
  • 6,438
  • 1
  • 43
  • 76
2

Dotty, a comprehensive name for all the things that are being added to Scala 3.0 has been a topic of discussion in the Scala community for the last four years. With all the promises and progress, The time for the release is very near. We can expect a release by the end of the year.

What changes to expect from Dotty?

If you would ask, “Is Scala 3.0 a new language”, Martin Ordersky says “yes Or no” in “A tour of Dotty” He has reasons for it. If you ask me, I would say yes!! It has a lot of new features.

  1. If you are a beginner, and only starting with Scala 3, you will find the new features as a new concept that was not part of the old Scala.
  2. If you are at an intermediate level in scala and already familiar with the constructs of the language, you will see some of the features which are removed and no longer supported.
  3. If you are a Scala expert and FP Enthusiast, there is a list of changes for you as well such as type-level derivation, match types, implicit function types, and Metaprogramming to name a few.
  4. These changes are shared in “A tour of Dotty” by Martin Ordersky in the last edition of the ScalaDays.

Breaking Changes!

An exhaustive list of Dropped Features is given below:

  1. DelayedInit
  2. Macros
  3. Existential Types
  4. Type Projection
  5. Do-While
  6. Procedure Syntax
  7. Package Objects
  8. Early Initializers
  9. Class Shadowing
  10. Limit 22
  11. XML literals
  12. Symbol Literals
  13. Auto-Application
  14. Weak Conformance
  15. Nonlocal Returns
  16. [this] Qualifier

IDE support for Dotty.

On the official website of Dotty, it only mentions the official IDE support for Dotty is Visual Studio Code. I do not know the reason why my favorite IDE (IJ) is not yet supported officially but there is a workaround. The workaround is described in the latest blog on “Dotty support on Intellij”.

I hope you got a glimpse of Dotty.

nomadSK25
  • 2,350
  • 3
  • 25
  • 36
himanshuIIITian
  • 5,985
  • 6
  • 50
  • 70
2

"Dotty" is the name of a programming language, much as Java, Ruby, or ... Scala are names of programming languages. The Dotty compiler is called dotc. The Dotty language looks like a fork of the Scala language, reimplemented using a different type calculus (DOT). Because of experience with DOT, Dotty drops some Scala features that aren't type-sound, and adds other features that make the type system more complete and robust. The Dotty language and toolset will soon become Scala 3.

Jim Balter
  • 16,163
  • 3
  • 43
  • 66
  • is Scala 3 based on Dotty backwards compatible, or does it break millions of lines of existing Scala code and requires painful migration across thousands of libraries? – alex Jan 25 '21 at 03:54
  • 2
    @alex See "Breaking Changes" in himanshuIIITian's answer. It's going to cause more painful migration for some people than for others. Many library writers have been busy for a while converting. I will note that your question is a bit off-topic here ... if you want a more detailed and up-to-date answer, you should probably check the Scala mailing lists and IRC channels. – Jim Balter Jan 25 '21 at 08:42