Skip to content

Commit 45757f1

Browse files
committed
Add posts from dotty-website
1 parent d0c472b commit 45757f1

6 files changed

+471
-12
lines changed

docs/blog/2015-10-23-dotty-compiler-bootstraps.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
2-
layout: blog
3-
post-type: blog
4-
by: Martin Odersky and Dmitry Petrashko
5-
title: We Got LiftOff! The Dotty Compiler for Scala Bootstraps.
2+
author: Martin Odersky and Dmitry Petrashko
3+
title: "We got liftoff!"
4+
subTitle: The Dotty compiler for Scala bootstraps.
65
---
76

8-
## We Got Liftoff!
7+
## We got liftoff!
98

109
The [Dotty project](https://github.com/lampepfl/dotty)
1110
is a platform to develop new technology for Scala
@@ -14,7 +13,7 @@ Its compiler is a new design intended to reflect the
1413
lessons we learned from work with the Scala compiler. A clean redesign
1514
today will let us iterate faster with new ideas in the future.
1615

17-
Today we reached an important milestone: The Dotty compiler can
16+
Today we reached an important milestone: the Dotty compiler can
1817
compile itself, and the compiled compiler can act as a drop-in for the
1918
original one. This is what one calls a *bootstrap*.
2019

@@ -35,29 +34,36 @@ go unnoticed, precisely because every part of a compiler feeds into
3534
other parts and all together are necessary to produce a correct
3635
translation.
3736

38-
## Are We Done Yet?
37+
## Are we done yet?
3938

4039
Far from it! The compiler is still very rough. A lot more work is
4140
needed to
4241

4342
- make it more robust, in particular when analyzing incorrect programs,
4443
- improve error messages and warnings,
4544
- improve the efficiency of some of the generated code,
45+
- improve compilation speed,
4646
- embed it in external tools such as sbt, REPL, IDEs,
4747
- remove restrictions on what Scala code can be compiled,
4848
- help in migrating Scala code that will have to be changed.
4949

50-
## What Are the Next Steps?
50+
## What are the next steps?
5151

5252
Over the coming weeks and months, we plan to work on the following topics:
5353

5454
- Make snapshot releases.
55-
- Get the Scala standard library to compile.
5655
- Work on SBT integration of the compiler.
5756
- Work on IDE support.
5857
- Investigate the best way to obtaining a REPL.
5958
- Work on the build infrastructure.
6059

61-
If you want to get your hands dirty with any of this, now is a good moment to get involved!
62-
To get started: <https://github.com/lampepfl/dotty>.
60+
If you want to get your hands dirty with any of this, now is a good
61+
moment to get involved! Join the team of contributors, including
62+
Dmitry Petrashko ([@DarkDimius](https://github.com/DarkDimius)),
63+
Guillaume Martres ([@smarter](https://github.com/smarter)),
64+
Ondrey Lhotak ([@olhotak](https://github.com/olhotak)),
65+
Samuel Gruetter ([@samuelgruetter](https://github.com/samuelgruetter)),
66+
Vera Salvis ([@vsalvis](https://github.com/vsalvis)),
67+
and Jason Zaugg ([@retronym](https://github.com/retronym)).
6368

69+
To get started: <https://github.com/lampepfl/dotty>.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: New Year Resolutions
3+
author: Martin Odersky
4+
authorImg: /images/martin.jpg
5+
---
6+
7+
For most of us, the change of the year is an occasion for thinking
8+
about what we missed doing last year and where we want to improve. I decided
9+
there are a couple of things where I would like to do better in 2016
10+
than in 2015. The first is that I would like to do more blogging and
11+
writing in general. I have been pretty silent for most of the last
12+
year. This was mostly caused by the fact that I had been heads down to
13+
work on DOT, Scala's foundations, and _dotty_, the new Scala compiler
14+
platform we are working on. It's been a lot of work, but we are finally
15+
getting good results. DOT now has a mechanized proof of type soundness
16+
and the dotty compiler [can now compile
17+
itself](http://www.scala-lang.org/blog/2015/10/23/dotty-compiler-bootstraps.html)
18+
as well as large parts of Scala's standard library.
19+
20+
The dotty compiler has a completely new and quite unusual
21+
architecture, which makes it resemble a functional database or a
22+
functional reactive program. My [talk at the JVM language
23+
summit](https://www.youtube.com/watch?v=WxyyJyB_Ssc) gives an
24+
overview. In the coming months I want to write together with my
25+
collaborators a series of blog posts
26+
that explain details of the code base. The
27+
aim of these posts will be to present the new architectural patterns
28+
to a larger audience and also to help existing and potential
29+
contributors get familiar with the code base.
30+
31+
My second resolution is to take a larger effort to promote simplicity
32+
in Scala. I believe the recent [blog post by Jim
33+
Plush](http://jimplush.com/talk/2015/12/19/moving-a-team-from-scala-to-golang/) should be a wakeup call for our
34+
community. Scala is a very powerful and un-opinionated language. This
35+
means we have a large spectrum of choice how to write a Scala
36+
application or library. It's very important for all of us to use this
37+
power wisely, and to promote simplicity of usage wherever possible.
38+
Unfortunately, most of us fall all too easily into the complexity
39+
trap, as Alex Payne's tweet sums it up very nicely.
40+
41+
<blockquote class="twitter-tweet" lang="en"><p lang="en" dir="ltr">“Complexity is like a bug light for smart people. We can&#39;t resist it, even though we know it&#39;s bad for us.” <a href="https://t.co/V9Izi573CF">https://t.co/V9Izi573CF</a></p>&mdash; Alex Payne (@al3x) <a href="https://twitter.com/al3x/status/683036775942496256">January 1, 2016</a></blockquote>
42+
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
43+
44+
I have been as guilty of complication as everybody else. Is
45+
`CanBuildFrom` the most appropriate solution to deal with the
46+
constraints of embedding special types such as arrays and strings in a
47+
collection library? It achieves its purpose of providing a uniform
48+
user-level API on disparate datatypes. But I now think with more
49+
effort we might be able come up with a solution that works as well and
50+
is simpler. Another example, where I have doubts if not regrets are
51+
the `/:` and `:\` operators in scala.collections. They are cute
52+
synonyms for folds, and I am still fond of the analogy with falling
53+
dominoes they evoke. But in retrospect I think maybe they did give a
54+
bad example for others to go overboard with symbolic operators.
55+
56+
So my main agenda for the coming year is to work on making Scala
57+
simpler: The language, its foundations, its libraries. I hope you
58+
will join me in that venture.
59+
60+
With that thought, I wish you a happy new year 2016.
61+
62+
63+
64+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: The Essence of Scala
3+
author: Martin Odersky
4+
authorImg: /images/martin.jpg
5+
---
6+
7+
What do you get if you boil Scala on a slow flame and wait until all
8+
incidental features evaporate and only the most concentrated essence
9+
remains? After doing this for 8 years we believe we have the answer:
10+
it's DOT, the calculus of dependent object types, that underlies Scala.
11+
12+
A [paper on DOT](http://infoscience.epfl.ch/record/215280) will be
13+
presented in April at [Wadlerfest](http://events.inf.ed.ac.uk/wf2016),
14+
an event celebrating Phil Wadler's 60th birthday. There's also a prior
15+
technical report ([From F to DOT](http://arxiv.org/abs/1510.05216))
16+
by Tiark Rompf and Nada Amin describing a slightly different version
17+
of the calculus. Each paper describes a proof of type soundness that
18+
has been machine-checked for correctness.
19+
20+
## The DOT calculus
21+
22+
A calculus is a kind of mini-language that is small enough to be
23+
studied formally. Translated to Scala notation, the language covered
24+
by DOT is described by the following abstract grammar:
25+
26+
Value v = (x: T) => t Function
27+
new { x: T => ds } Object
28+
29+
Definition d = def a = t Method definition
30+
type A = T Type
31+
32+
Term t = v Value
33+
x Variable
34+
t1(t2) Application
35+
t.a Selection
36+
{ val x = t1; t2 } Local definition
37+
38+
Type T = Any Top type
39+
Nothing Bottom type
40+
x.A Selection
41+
(x: T1) => T2 Function
42+
{ def a: T } Method declaration
43+
{ type T >: T1 <: T2 } Type declaration
44+
T1 & T2 Intersection
45+
{ x => T } Recursion
46+
47+
The grammar uses several kinds of names:
48+
49+
x for (immutable) variables
50+
a for (parameterless) methods
51+
A for types
52+
53+
The full calculus adds to this syntax formal _typing rules_ that
54+
assign types `T` to terms `t` and formal _evaluation rules_ that
55+
describe how a program is evaluated. The following _type soundness_
56+
property was shown with a mechanized, (i.e. machine-checked) proof:
57+
58+
> If a term `t` has type `T`, and the evaluation of `t` terminates, then
59+
the result of the evaluation will be a value `v` of type `T`.
60+
61+
## Difficulties
62+
63+
Formulating the precise soundness theorem and proving it was unexpectedly hard,
64+
because it uncovered some technical challenges that had not been
65+
studied in depth before. In DOT - as well as in many programming languages -
66+
you can have conflicting definitions. For instance you might have an abstract
67+
type declaration in a base class with two conflicting aliases in subclasses:
68+
69+
trait Base { type A }
70+
trait Sub1 extends Base { type A = String }
71+
trait Sub2 extends Base { type A = Int }
72+
trait Bad extends Sub1 with Sub2
73+
74+
Now, if you combine `Sub1` and `Sub2` in trait `Bad` you get a conflict,
75+
since the type `A` is supposed to be equal to both `String` and `Int`. If you do
76+
not detect the conflict and assume the equalities at face value you
77+
get `String = A = Int`, hence by transitivity `String = Int`! Once you
78+
are that far, you can of course engineer all sorts of situations where
79+
a program will typecheck but cause a wrong execution at runtime. In
80+
other words, type soundness is violated.
81+
82+
Now, the problem is that one cannot always detect these
83+
inconsistencies, at least not by a local analysis that does not need
84+
to look at the whole program. What's worse, once you have an
85+
inconsistent set of definitions you can use these definitions to
86+
"prove" their own consistency - much like a mathematical theory that
87+
assumes `true = false` can "prove" every proposition including its own
88+
correctness.
89+
90+
The crucial reason why type soundness still holds is this: If one
91+
compares `T` with an alias, one does so always relative to some _path_
92+
`x` that refers to the object containing `T`. So it's really `x.T =
93+
Int`. Now, we can show that during evaluation every such path refers
94+
to some object that was created with a `new`, and that, furthermore,
95+
every such object has consistent type definitions. The tricky bit is
96+
to carefully distinguish between the full typing rules, which allow
97+
inconsistencies, and the typing rules arising from runtime values,
98+
which do not.
99+
100+
## Why is This Important?
101+
102+
There are at least four reasons why insights obtained in the DOT
103+
project are important.
104+
105+
1. They give us a well-founded explanation of _nominal typing_.
106+
Nominal typing means that a type is distinguished from others
107+
simply by having a different name.
108+
For instance, given two trait definitions
109+
110+
trait A extends AnyRef { def f: Int }
111+
trait B extends AnyRef { def f: Int }
112+
113+
we consider `A` and `B` to be different types, even though both
114+
traits have the same parents and both define the same members.
115+
The opposite of
116+
nominal typing is structural typing, which treats types
117+
that have the same structure as being the same. Most programming
118+
languages are at least in part nominal whereas most formal type systems,
119+
including DOT, are structural. But the abstract types in DOT
120+
provide a way to express nominal types such as classes and traits.
121+
The Wadlerfest paper contains examples that show how
122+
one can express classes for standard types such as `Boolean` and `List` in DOT.
123+
124+
2. They give us a stable basis on which we can study richer languages
125+
that resemble Scala more closely. For instance, we can encode
126+
type parameters as type members of objects in DOT. This encoding
127+
can give us a better understanding of the interactions of
128+
subtyping and generics. It can explain why variance rules
129+
are the way they are and what the precise typing rules for
130+
wildcard parameters `[_ <: T]`, `[_ >: T]` should be.
131+
132+
3. DOT also provides a blueprint for Scala compilation. The new Scala
133+
compiler _dotty_ has internal data structures that closely resemble DOT.
134+
In particular, type parameters are immediately mapped to type members,
135+
in the way we propose to encode them also in the calculus.
136+
137+
4. Finally, the proof principles explored in the DOT work give us guidelines
138+
to assess and treat other possible soundness issues. We now know much
139+
better what conditions must be fulfilled to ensure type soundness.
140+
This lets us put other constructs of the Scala language to the test,
141+
either to increase our confidence that they are indeed sound, or
142+
to show that they are unsound. In my next blog I will
143+
present some of the issues we have discovered through that exercise.
144+

0 commit comments

Comments
 (0)