Wednesday, 22 June 2016

Scala Dotty: New Scala Compiler in Brief


In this post, I'm going to talk about "Dotty" in brief. Will try to deliver more and more posts about it soon.

What is Dotty?

Dotty is a Next Generation Compiler for Scala Programming Language.

Why Dotty?

Dotty is a platform to try out new language concepts and compiler technologies for Scala. The focus is mainly on simplification. We remove extraneous syntax (e.g. no XML literals), and try to boil down Scala’s types into a smaller set of more fundamental constructors. The theory behind these constructors is researched in DOT, a calculus for dependent object types.

What are the complications that I can have If I start using Dotty?

Dotty can use libraries compiled by scalac 2.11, but Scala scalac can't use libraries compiled by Dotty.
No existential types.
No macro support yet. We have big plans here.
No early initializers. No scala.DelayedInit. Use trait parameters instead.
Whole program optimizer will only work if all dependencies are compiled by Dotty.
Can I write my code in a way that is going to be compatible with Scalac & Dotty?
Yes, Dotty itself is a project that can be compiled by both Dotty and Scalac.
It's not very hard, and the biggest thing that you will likely miss is using macros.

How do I migrate my code to Dotty?

An automated rewriting tool is planned for Dotty, more on this to come. Scala 2 sources can be compiled to some degree by issuing:
./bin/dotc -language:Scala2 file.scala
when compiling your program.

What about scalac:

Scalac is the basis for stability in scala. We expect scalac & dotty to coexist for long time.
What are the features that could make me consider trying it?
Union, Intersection and Literal singleton typesImplemented
Fast compilation(phase fusion)Implemented
Trait parametersImplemented
@Static methods and fieldsImplemented
Colored ReplImplemented
Sbt incremental buildImplemented
Non-blocking lazy valsImplemented
Option-less pattern matching(based on name-based patmat)Implemented
Function arity adaptationImplemented
Non-boxed arrays of value classesIn progress
Working contravariant implicitsIn progress
Auto-SpecializationIn progress
Whole program optimizerIn progress
Library defined optimizationsIn progress
HList & HMaps\Record typesUnder consideration
Implicit functionsUnder consideration
EffectsUnder consideration
Auto-completion in replUnder consideration
Spec Option-less pattern matchingUnder consideration
Multiverse equalityUnder consideration
Exhaustivity checks in pattern matchingUnder consideration
Thank you for reading my posts.
Please drop me a comment if you have any questions/suggestions/issues.