Skip to content

Commit f1d6ce4

Browse files
committed
Add soundiness reference
and expand on typelevel restrictions.
1 parent f5e230e commit f1d6ce4

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

blog/_posts/2016-02-17-scaling-dot-soundness.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ categories:
5050
lazy val p: S = p
5151
... p.T ...
5252

53-
Note that trying to access the lazy value `p` would result in an infinite loop. But using `p` in a type does not force its evaluation, so we might never evaluate `p`. Since `p` is not initialized
54-
with a `new`, bad bounds for `T` would go undetected.
53+
Note that trying to access the lazy value `p` would result in an infinite loop. But using `p` in a type does not force its evaluation, so we might never evaluate `p`. Since `p` is not initialized with a `new`, bad bounds for `T` would go undetected.
5554

5655
2. The prefix value might be initialized to `null`, as in
5756

@@ -62,7 +61,7 @@ with a `new`, bad bounds for `T` would go undetected.
6261
with a `new` so we know nothing about the bounds of `T`.
6362

6463
3. The prefix might be a type `T` in a type projection `T # A`, where `T`
65-
is not associated with a runtime value.
64+
is not associated with a runtime value.
6665

6766
We can in fact construct soundness issues in all of these cases. Look
6867
at the discussion for issues [#50](https://github.com/lampepfl/dotty/issues/50)
@@ -118,23 +117,32 @@ an exception or `System.exit` call before reaching the initialization
118117
point of `f`. It's a valid question whether type soundness guarantees
119118
should extend to this class of "strange" programs. We might want to
120119
draw the line here and resort to runtime checks or exclude "strange"
121-
programs from any soundness guarantees we can give.
120+
programs from any soundness guarantees we can give. The research community
121+
has coined the term [soundiness](http://soundiness.org/) for
122+
this kind of approach and has [advocated](http://cacm.acm.org/magazines/2015/2/182650-in-defense-of-soundiness/fulltext) for it.
122123

123124
The necessary restrictions on type projection `T # A` are problematic
124-
because they invalidate a common idiom in type-level programming. To
125-
ease the transition, we will continue to allow unrestricted type
126-
projections for a while under a flag, even though they are
127-
potentially unsound. In the current dotty compiler, that flag is a
128-
language import `-language:Scala2`, but it could be something
129-
different for other compilers, e.g. `-unsafe`. Maybe we can find
130-
rules that are less restrictive than the ones we have now, and are
131-
still sound. But one aspect should be non-negotiable: Any fundamental
132-
deviations from the principles laid down by DOT needs to be proven
133-
mechanically correct just like DOT was. We have achieved a lot with
134-
the DOT proofs, so we should make sure not to back-slide. And if the
135-
experience of the past 10 years has taught us one thing, it is that
136-
the meta theory of type systems has many more surprises in store than
137-
one might think. That's why mechanical proofs are essential.
125+
because they invalidate some idioms in type-level programming. For
126+
instance, the cute trick of making Scala's type system Turing complete
127+
by having it [simulate SK
128+
combinators](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/)
129+
would not longer work since that one relies on unrestricted type
130+
projections. The same holds for some of the encodings of type-level
131+
arithmetic.
132+
133+
To ease the transition, we will continue for a while to allow unrestricted type
134+
projections under a flag, even though they are potentially
135+
unsound. In the current dotty compiler, that flag is a language import
136+
`-language:Scala2`, but it could be something different for other
137+
compilers, e.g. `-unsafe`. Maybe we can find rules that are less
138+
restrictive than the ones we have now, and are still sound. But one
139+
aspect should be non-negotiable: Any fundamental deviations from the
140+
principles laid down by DOT needs to be proven mechanically correct
141+
just like DOT was. We have achieved a lot with the DOT proofs, so we
142+
should make sure not to back-slide. And if the experience of the past
143+
10 years has taught us one thing, it is that the meta theory of type
144+
systems has many more surprises in store than one might think. That's
145+
why mechanical proofs are essential.
138146

139147

140148

0 commit comments

Comments
 (0)