-
Notifications
You must be signed in to change notification settings - Fork 1.1k
0.15.0-RC1 Blog Post Draft #6544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
362a363
a26301b
ac825ae
8c0e910
a7f477c
48774aa
b03720c
3dfc323
ec90a57
9bb0de8
6ac7e5c
85358b7
04865a7
a3ffc2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
--- | ||
layout: blog-page | ||
title: Announcing Dotty 0.15.0-RC1 – the fully bootstrapped compiler | ||
author: Anatolii Kmetiuk | ||
authorImg: /images/anatolii.png | ||
date: 2019-05-24 | ||
--- | ||
|
||
Hi! In this article, we'd like to announce the 15th release of Dotty. The most exciting thing in this release is the full bootstrap for Dotty introduced by PR [#5923](https://github.com/lampepfl/dotty/pull/5923). This means that we are able to compile Dotty with Dotty itself, and hence use all the new features in the compiler code base. | ||
|
||
With this release comes a bunch of new features and improvements, such as the ability to enforce whether an operator is intended to be used in an infix position, the type safe pattern bindings and more. | ||
|
||
This release serves as a technology preview that demonstrates new | ||
language features and the compiler supporting them. | ||
|
||
Dotty is the project name for technologies that are being considered for | ||
inclusion in Scala 3. Scala has pioneered the fusion of object-oriented and | ||
functional programming in a typed setting. Scala 3 will be a big step towards | ||
realising the full potential of these ideas. Its main objectives are to | ||
|
||
- become more opinionated by promoting programming idioms we found to work well, | ||
- simplify where possible, | ||
- eliminate inconsistencies and surprising behaviours, | ||
- build on strong foundations to ensure the design hangs together well, | ||
- consolidate language constructs to improve the language’s consistency, safety, ergonomics, and | ||
performance. | ||
|
||
You can learn more about Dotty on our [website](https://dotty.epfl.ch). | ||
|
||
<!--more--> | ||
|
||
This is our 15th scheduled release according to our | ||
[6-week release schedule](https://dotty.epfl.ch/docs/contributing/release.html). | ||
|
||
# What’s new in the 0.15.0-RC1 technology preview? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would write a small paragraph:
|
||
## Operator Rules | ||
This change addresses the problem of the regulation of whether an operator is supposed to be used in an infix position. The motivation is for the library authors to be able to enforce whether a method or a type is supposed to be used in an infix position by the users. This ability will help to make code bases more consistent in the way the calls to methods are performed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change addresses ... position. -> We introduce two annotations that regulate the use of operators. The first is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually only one annotation, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I thought it was in @anatoliykmetyuk. @odersky since |
||
|
||
Methods with symbolic names like `+` are allowed to be used in an infix position by default: | ||
|
||
```scala | ||
scala> case class Foo(x: Int) { def +(other: Foo) = x + other.x } | ||
// defined case class Foo | ||
|
||
scala> Foo(1) + Foo(2) | ||
val res0: Int = 3 | ||
``` | ||
|
||
Methods with alphanumeric names are not allowed to be used in an infix position. Breaking this constraint will raise a deprecation warning: | ||
|
||
```scala | ||
scala> case class Foo(x: Int) { def plus(other: Foo) = x + other.x } | ||
// defined case class Foo | ||
|
||
scala> Foo(1) plus Foo(2) | ||
1 |Foo(1) plus Foo(2) | ||
| ^^^^ | ||
|Alphanumeric method plus is not declared @infix; it should not be used as infix operator. | ||
|The operation can be rewritten automatically to `plus` under -deprecation -rewrite. | ||
|Or rewrite to method syntax .plus(...) manually. | ||
val res1: Int = 3 | ||
|
||
scala> Foo(1).plus(Foo(2)) | ||
val res2: Int = 3 | ||
``` | ||
|
||
As the warning says, if you want the users of the method to be able to use it in an infix position, you can do so as follows: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can do so -> they can do so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "you", since that's the author of the code that has the control over how the method is used. If it is not marked as |
||
|
||
```scala | ||
scala> import scala.annotation.infix | ||
|
||
scala> case class Foo(x: Int) { @infix def plus(other: Foo) = x + other.x } | ||
// defined case class Foo | ||
|
||
scala> Foo(1) plus Foo(2) | ||
val res3: Int = 3 | ||
``` | ||
|
||
To smoothen the migration, the deprecation warnings will only be emitted if you compile with the `-strict` flag under Scala 3. Alphanumeric methods that are defined without the `@infix` annotation used in an infix position will be deprecated by default starting with Scala 3.1. | ||
|
||
For more information, see the the [documentation](http://dotty.epfl.ch/docs/reference/changed-features/operators.html#the-infix-annotation). Note that the `@alpha` annotation also described in the documentation is planned for the future and is not available in this release. | ||
|
||
## `given` clause comes last | ||
In the previous release, you could write something like this: | ||
|
||
```scala | ||
implied for String = "foo" | ||
def f(x: Int) given (y: String) (z: Int) = x + z | ||
f(1)(3) | ||
``` | ||
|
||
Now, however, `given` clauses must come last. The above code will fail with: | ||
|
||
``` | ||
-- Error: ../issues/Playground.scala:3:34 -------------------------------------- | ||
3 | def f(x: Int) given (y: String) (z: Int) = x + z | ||
| ^ | ||
| normal parameters cannot come after `given' clauses | ||
one error found | ||
``` | ||
|
||
The following snippet is the correct way to express the program in question: | ||
|
||
```scala | ||
implied for String = "foo" | ||
def f(x: Int)(z: Int) given (y: String) = x + z | ||
f(1)(3) | ||
``` | ||
|
||
We changed this to reduce confusion when calling functions with mixed explicit and implied parameters. | ||
|
||
## Type-safe Pattern Bindings | ||
```scala | ||
val xs: List[Any] = List(1, 2, 3) | ||
val (x: String) :: _ = xs // error: pattern's type String is more specialized | ||
// than the right hand side expression's type Any | ||
``` | ||
|
||
The above code will fail with a compile-time error in Scala 3.1 and in Scala 3 with the `-strict` flag. In contrast, in Scala 2, the above would have compiled fine but failed on runtime with an exception. | ||
|
||
Dotty compiler will allow such a pattern binding only if the pattern is *irrefutable* – that is, if the right-hand side conforms to the pattern's type. E.g. the following is OK: | ||
|
||
```scala | ||
val pair = (1, true) | ||
val (x, y) = pair | ||
``` | ||
|
||
If we want to force the pattern binding if the pattern is not irrefutable, we can do so with an annotation: | ||
|
||
```scala | ||
val xs: List[Any] = List("1", "2", "3") | ||
val (x: String) :: _: @unchecked = xs | ||
``` | ||
|
||
The same is implemented for pattern bindings in `for` expressions: | ||
|
||
```scala | ||
val elems: List[Any] = List((1, 2), "hello", (3, 4)) | ||
for ((x, y) <- elems) yield (y, x) // error: pattern's type (Any, Any) is more specialized | ||
// than the right hand side expression's type Any | ||
``` | ||
|
||
For the migration purposes, the above change will only take effect in Scala 3.1. You can use it in Scala 3 with the `-strict` flag. | ||
|
||
For more information, see the [documentation](http://dotty.epfl.ch/docs/reference/changed-features/pattern-bindings.html). | ||
|
||
## Further improvements to Generalised Algebraic Data Types (GADTs) support | ||
In this release, we've further improved our support for GADTs. Most notably, we now support variant GADTs: | ||
|
||
```scala | ||
enum Expr[+T] { | ||
case StrLit(s: String) extends Expr[String] | ||
case Pair[A, B](a: Expr[A], b: Expr[B]) extends Expr[(A, B)] | ||
} | ||
|
||
def eval[T](e: Expr[T]): T = e match { | ||
case Expr.StrLit(s) => s | ||
case Expr.Pair(a, b) => (eval(a), eval(b)) | ||
} | ||
``` | ||
|
||
We've also plugged a few soundness problems caused by inferring too much when matching on abstract, union and intersection types. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add the PR number (this right #2985)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AleksanderBG is that issue correct here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be better placed in the first line, which talks about variant GADTs. We can mention #5667 for an example of the soundness problems as well, though I didn't really create an issue for that. |
||
|
||
## Other changes | ||
Some of the other notable changes include the following: | ||
|
||
- Singletons are now allowed in union types. E.g. the following is allowed: `object foo; type X = Int | foo.type`. | ||
- A bunch of improvements was made for the type inference system – see, e.g., PRs [#6454](https://github.com/lampepfl/dotty/pull/6454) and [#6467](https://github.com/lampepfl/dotty/pull/6467). | ||
- Improvements to the Scala 2 code support which, in particular, improves Cats support – see PRs [#6494](https://github.com/lampepfl/dotty/pull/6494) and [#6498](https://github.com/lampepfl/dotty/pull/6498). | ||
|
||
# Let us know what you think! | ||
|
||
If you have questions or any sort of feedback, feel free to send us a message on our | ||
[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please | ||
[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new). | ||
|
||
## Contributing | ||
|
||
Thank you to all the contributors who made this release possible! | ||
|
||
According to `git shortlog -sn --no-merges 0.14.0-RC1..0.15.0-RC1` these are: | ||
|
||
``` | ||
TODO | ||
``` | ||
|
||
If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved! | ||
Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html), | ||
and have a look at some of the [good first issues](https://github.com/lampepfl/dotty/issues?q=is%3Aissue+is%3Aopen+label%3Aexp%3Anovice). | ||
They make perfect entry points into hacking on the compiler. | ||
|
||
We are looking forward to having you join the team of contributors. | ||
|
||
## Library authors: Join our community build | ||
|
||
Dotty now has a set of widely-used community libraries that are built against every nightly Dotty | ||
snapshot. Currently this includes ScalaPB, algebra, scalatest, scopt and squants. | ||
Join our [community build](https://github.com/lampepfl/dotty-community-build) | ||
to make sure that our regression suite includes your library. | ||
|
||
[Scastie]: https://scastie.scala-lang.org/?target=dotty | ||
|
||
[@odersky]: https://github.com/odersky | ||
[@DarkDimius]: https://github.com/DarkDimius | ||
[@smarter]: https://github.com/smarter | ||
[@felixmulder]: https://github.com/felixmulder | ||
[@nicolasstucki]: https://github.com/nicolasstucki | ||
[@liufengyun]: https://github.com/liufengyun | ||
[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain | ||
[@biboudis]: https://github.com/biboudis | ||
[@allanrenucci]: https://github.com/allanrenucci | ||
[@Blaisorblade]: https://github.com/Blaisorblade | ||
[@Duhemm]: https://github.com/Duhemm | ||
[@AleksanderBG]: https://github.com/AleksanderBG | ||
[@milessabin]: https://github.com/milessabin | ||
[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk |
Uh oh!
There was an error while loading. Please reload this page.