Dotty: exploring the future of scala

Dmitry Petrashko


Video of this talk on Youtube:

https://youtu.be/aftdOFuVU1o

Follow my slides

http://goo.gl/kVXZqu

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

About me:

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

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

Talk Structure

  • Part 1: What dotty is expected to bring to the table
    • Language:
      • Union(|) and Intersection(&) Types
      • SIP-23: Literal-based Singleton Types
      • SIP-24: Repeated By Name Parameters
      • SIP-25: Trait Parameters
      • SIP-20: Improved Lazy Vals Initialization
      • Deprecations
    • Ecosystem:
      • Tasty
      • scala.meta
      • Linker
      • Compilation speed

Talk Structure

  • Part 2: Internals
    • Denotations
    • Denotation Transformers
    • Mini-phases
    • Tree Checkers and postconditions

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
  • 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

Thank you.

See my other talks.