Dotty: exploring the future of scala

Dmitry Petrashko


About me:

  • https://github.com/darkdimius/
  • doing PhD at EPFL
  • previously worked on ScalaBlitz
  • since March 2014 year working on Dotty.

How old are those languages?

  • Java: 1990;
  • Python: 1991;
  • Ruby: 1995;
  • Pizza: 2001;
  • Lisp: 1958;
  • Scheme: 1975;
  • Haskell: 1990;
  • Scala: 2004;

TIOBE language rankings

  • Java 1st
  • C/C++ 2/3rd
  • Python 4th
  • Groovy 24th
  • Scala 28th
  • Haskell 39th
  • Erlang 33rd
  • Clojure > 50

Groovy creator(James Strachan) on Scala

I can honestly say if someone had shown me the Programming Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy.

Red Monk language rankings

Dotty?

  • a new compiler for a Scala-like language
  • developed at LAMP EPFL
  • is currently not ready for production use
  • some of the new technologies explored in this project will find their way into future versions of Scala

Dotty status:

Dotty contributor stats:

git ls-tree -r -z --name-only HEAD -- |egrep -z -Z -E '\.(scala)$'\
| xargs -0 -n1 git blame --line-porcelain |grep "^author "|sort|uniq -c|sort -nr
authorcommitsadditionsdeletionsblame lines
Martin Odersky2,280
146,133
85,391
57,284
Dmitry Petrashko628
158,249
50,201
83,929
Samuel Gruetter19
62,324
12,510
36,615
Ondrej Lhotak29
2,009
340
1,874
Guillaume Martres77
2,197
1,190
1,171
Vera Salvisberg17
1,109
364
819
Jason Zaugg16
213
149
153
Alexander Myltsev5
275
65
144
Vlad Ureche13
255
77
51

Part 1: What dotty is expected to bring to the table

  • Language:
    • Union(|) and Intersection(&) types
    • SIP-23: Literal-based singleton types
    • SIP-25: Trait parameters
    • SIP-20: Improved Lazy Vals Initialization
    • Deprecations
  • Ecosystem:
    • Tasty
    • scala.meta
    • Linker
    • Compilation speed

Part 2: Internals.

  • Denotations
  • Denotation Transformers
  • Mini-phases
  • Tree Checkers and postconditions

Random discussion points

  • Functional vs Object-Oriented
  • Is Scala code more or less readable than Java?
  • Should you choose Scala for your next project?
  • Stability vs new features
  • Typed vs Untyped(vs Gradually typed)
  • GC vs malloc(vs ownership\regions)
  • Idents vs braces
  • JIT vs AOT

Intersection(&) types

what is the difference?

with is ordered, & is not

A with B is different from B with A. & is not

Ecosystem

Ecosystem: Binary compatibility

Ecosystem: Binary compatibility

Ecosystem: Binary compatibility

Ecosystem: Binary compatibility

Developing a library,
you need to consider publishing for
(2.10, 2.11, 2.12) x (java6, java8, JS) x (Typesafe, Typelevel)

Why???

This should not bother developers!!!

Ecosystem: Tasty

Ecosystem: TASTY

  • Allows to get scala source from compiled classfiles
  • Is not vulnerable to changes in implicit resolution
  • No need to push multiple artifacts to maven. Dotty can recompile from TASTY

Ecosystem: ScalaMeta

  • Metaprogramming done right

Previous project: Scalablitz

  • Tunes collection operations for your use-case
  • Gets ridiculous speedups(40x, 120x) for simple code, eg Array[Int].reduce(_+_)
  • Less garbage allocated
  • Better memory locality & cpu throuput utilization

Ecosystem: Linker

  • Does the very same for any library
  • Tunes library for your use-case
  • Removes allocations, closures, virtual calls
  • A smarter proguard
  • Details: video, slides

Compilation speed

  • Dotty has design decisions that allow to get substantial speedups
    • MiniPhases and their fusion
    • Info transformers
  • We did not yet do any performance tuning, but
    • Compiling Hello world takes 1.4 sec vs 1.6 sec by scalac
    • Compiling Dotty itself takes 27 sec vs 42 sec by scalac
    • Compiling Dotty itself takes 30 sec vs 83 sec by scalac

Part 2: Internals.

  • Not a big cake
  • Context instead of global mutable state
  • Denotations
  • Denotation Transformers
  • Mini-phases
  • Tree Checkers and postconditions

Denotations

Denotations

Macro Phases

Macro Phases

Macro Phases

  • Every phase traverses a tree independently
  • Reading cold data
  • Creating new subtrees
  • That live long and are promoted to OldGen of GC

Does LazyVals implement LazyVals?

No, Mixin does.

If you want performance, you do not want many Macro phases

Why? Macro phases cost a lot

Half of phases do `something` additionally

Mini Phases

Mini Phases

Mini Phases

Mini Phases

  • Phases share tree traversal
  • Trees you are accessing are hot
  • Trees die fast and do not get promoted to OldGen of GC

Random discussion points

  • Functional vs Object-Oriented
  • Is Scala code more or less readable than Java?
  • Should you choose Scala for your next project?
  • Stability vs new features
  • Typed vs Untyped(vs Gradually typed)
  • GC vs malloc(vs ownership\regions)
  • Idents vs braces
  • JIT vs AOT

Thank you.

See my other talks.