Skip to content

Commit 636af43

Browse files
Add M3 blog article
1 parent 18c84fc commit 636af43

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
layout: blog-page
3+
title: Scala 3.0.0-M3: developer's preview before RC1
4+
author: Anatolii Kmetiuk
5+
authorImg: /images/anatolii.png
6+
date: 2020-12-18
7+
---
8+
We are happy to announce the release of Scala 3.0.0-M3. This release is the Developer's Preview release intended to contain all the features meant for RC1 which is tentatively planned for January 2021. The purpose of M3 is to give the community a chance to try out all the features and give us feedback before sealing them in RC1.
9+
10+
To collect the feedback, we have designed a [Scala 3 Developer’s Preview satisfaction survey (3-5 min)](https://docs.google.com/forms/d/e/1FAIpQLSflVmTu9lhrtnSTh2tKAjUGrt3WvEgwlDqZg66O3EVSXd1aJg/viewform?usp=sf_link) – please fill it in to express how you feel about Scala 3.
11+
12+
For the weeks between M2 and M3, we were tying up all the loose ends so that to end 2020 having done everything intended for the release. Also, we have used this time as the last chance to review and fine-tune the language syntax. A large number of consultations with the community took place during this time so that to ensure everyone is on the same page.
13+
14+
In this article, you will find the summary of the most important changes that took place.
15+
16+
<!--more-->
17+
# SBT plugin bump
18+
SBT plugin was bumped to 0.5.0. Because of the changes in PR [#10607](https://github.com/lampepfl/dotty/pull/10607) this release of Scala 3 will not work with earlier versions of the SBT plugin. So if you are an early adopter of Scala 3 who has some projects in it, you will need to bump your SBT plugin version to migrate to M3.
19+
20+
# Final syntactic tweaks
21+
## `as` dropped from the `given` syntax
22+
The following syntax is obsolete:
23+
24+
```scala
25+
given intOrd as Ordering[Int]:
26+
...
27+
given listOrd[T: Ordering] as Ordering[List[T]]:
28+
...
29+
30+
given Ordering[Int]:
31+
...
32+
given [T: Ordering] as Ordering[List[T]]:
33+
...
34+
35+
given global as ExecutionContext = ForkJoinContext()
36+
given Context = ctx
37+
```
38+
39+
Here is how the above is expressed now:
40+
41+
```scala
42+
given intOrd: Ordering[Int] with
43+
...
44+
given listOrd[T: Ordering]: Ordering[List[T]] with
45+
...
46+
47+
given Ordering[Int] with
48+
...
49+
given [T: Ordering]: Ordering[List[T]] with
50+
...
51+
52+
given global: ExecutionContext = ForkJoinContext()
53+
given Context = ctx
54+
```
55+
56+
You can find an extensive discussion on the above change in its [PR #10538](https://github.com/lampepfl/dotty/pull/10538).
57+
58+
## Drop `as` in patterns
59+
Since we dropped `as` from `given`s, we lost a strong reason for having `as` at all. For this reason, we dropped them also from patterns. If previously the correct binding syntax is patterns was:
60+
61+
```scala
62+
case opt as Some(foo)
63+
```
64+
65+
Now it got reverted to the Scala 2 style:
66+
67+
```scala
68+
case opt @ Some(foo)
69+
```
70+
71+
## Switch back to the old context function closure syntax
72+
Previously, context function closures were written as follows:
73+
74+
```scala
75+
(using s: Show[String]) => s.show("foobar")
76+
```
77+
78+
Now, we have reverted to the following syntax:
79+
```scala
80+
(s: Show[String]) ?=> s.show("foobar")
81+
```
82+
83+
# `Matchable` trait – a new top-level type
84+
The motivation for this change is the fact that it is possible to access the underlying type referenced by an opaque type using pattern matching:
85+
86+
```scala
87+
val imm = IArray(1,2,3) // supposedly immutable...
88+
imm match
89+
case a: Array[Int] => a(0) = 0 // but that's shown to be lie
90+
```
91+
92+
To address this change, a new trait, `Matchable`, is introduced at the top of the type hierarchy:
93+
94+
```scala
95+
abstract class Any:
96+
def asInstanceOf
97+
def ==
98+
def !=
99+
def ##
100+
def equals
101+
def hashCode
102+
def toString
103+
104+
trait Matchable extends Any:
105+
def isInstanceOf
106+
def getClass
107+
108+
class AnyVal extends Any, Matchable
109+
110+
class Object extends Any, Matchable
111+
```
112+
113+
With the addition of this type, we now make the compiler emit warnings when trying to do a trick like the one discussed above:
114+
115+
```scala
116+
-- Warning: i7314.scala:6:12 ---------------------------------------------------
117+
6 | case a: Array[Int] =>
118+
| ^^^^^^^^^^
119+
| pattern selector should be an instance of Matchable,
120+
| but it has unmatchable type opaques.IArray[Int] instead
121+
```
122+
123+
The change involved an extensive discussion which you can read in the [PR #10670](https://github.com/lampepfl/dotty/pull/10670).
124+
125+
# Tooling improvements
126+
As the work on Scala 3 gets closer to the stable release, the focus increasingly shifts on the tooling available to get started with Scala 3.
127+
128+
As part of the tooling effort, Scala 3 documentation tool is rapidly improved. [PR #10522](https://github.com/lampepfl/dotty/pull/10522) proves that the doctool can generate documentation for the community build projects.
129+
130+
[PR #10491](https://github.com/lampepfl/dotty/pull/10491) introduced the scripting capability to Scala 3. Consider the following source named e.g. `Main.scala`:
131+
132+
```scala
133+
@main def Test(name: String): Unit =
134+
println(s"Hello ${name}!")
135+
```
136+
137+
If you have Scala 3 binaries on your path (which you can get by following the steps at the [Dotty website](https://dotty.epfl.ch/)'s section "Try DOtty"), you can run the `scala Main.scala World` command. This command will compile the source in question to a temporary directory and run the discovered main method with the argument `World`.
138+
139+
Note the difference from the Scala 2 scripting implementation. In Scala 2, we do not require the users to have a `main` method in their scripts due to it being too cumbersome to write. In Scala 3, thanks to the top-level definitions and the `@main` annotations, `main` methods are one-liners and hence are more suited for scripts.
140+
141+
The documentation for this feature is available [here](https://dotty.epfl.ch/docs/usage/getting-started.html#scala-3-for-scripting).
142+
143+
# Metaprogramming changes
144+
Metaprogramming-wise, the majority of work is focused on polishing the API and making it more uniform. The following notable metaprogramming API changes occurred between M2 and M3:
145+
146+
- Add reflect `MatchCase` `TypeRepr` (#10735)[https://github.com/lampepfl/dotty/pull/10735]
147+
- Rework reflect Symbol fields API (#10705)[https://github.com/lampepfl/dotty/pull/10705]
148+
- Remove `Expr.StringContext.unapply` (#10675)[https://github.com/lampepfl/dotty/pull/10675]
149+
- Rename `Liftable` to `ToExpr` and `Unliftable` to `FromExpr` (#10618)[https://github.com/lampepfl/dotty/pull/10618]
150+
- Remove Unliftable[Unit] (#10570)[https://github.com/lampepfl/dotty/pull/10570]
151+
- Remove reflect.LambdaType (#10548)[https://github.com/lampepfl/dotty/pull/10548]
152+
- Add `scala.quoted.Expr.unapply` as dual of `Expr.apply` (#10580)[https://github.com/lampepfl/dotty/pull/10580]
153+
- Move `Quotes` as last parameter in `ExprMap.transform` (#10519)[https://github.com/lampepfl/dotty/pull/10519]
154+
- Unify quoted.report and reflect.Reporting (#10474)[https://github.com/lampepfl/dotty/pull/10474]
155+
- Fix #10359: Add GivenSelector to reflection API (#10469)[https://github.com/lampepfl/dotty/pull/10469]
156+
- Rework reflect show API (#10661)[https://github.com/lampepfl/dotty/pull/10661]
157+
- Fix #6542: Pickle line sizes in TASTy (#10363)[https://github.com/lampepfl/dotty/pull/10363]
158+
159+
# Let us know what you think!
160+
If you have questions or any sort of feedback, feel free to send us a message on our
161+
[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please
162+
[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new).
163+
164+
165+
## Contributors
166+
Thank you to all the contributors who made this release possible 🎉
167+
168+
According to `git shortlog -sn --no-merges 3.0.0-M2..3.0.0-M3` these are:
169+
170+
```
171+
TODO
172+
```
173+
174+
If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved!
175+
Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html),
176+
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).
177+
They make perfect entry points into hacking on the compiler.
178+
179+
We are looking forward to having you join the team of contributors.
180+
181+
## Library authors: Join our community build
182+
183+
Dotty now has a set of widely-used community libraries that are built against every nightly Dotty
184+
snapshot. Currently, this includes shapeless, ScalaPB, algebra, scalatest, scopt and squants.
185+
Join our [community build](https://github.com/lampepfl/dotty/tree/master/community-build)
186+
to make sure that our regression suite includes your library.
187+
188+
[Scastie]: https://scastie.scala-lang.org/?target=dotty
189+
190+
[@odersky]: https://github.com/odersky
191+
[@DarkDimius]: https://github.com/DarkDimius
192+
[@smarter]: https://github.com/smarter
193+
[@felixmulder]: https://github.com/felixmulder
194+
[@nicolasstucki]: https://github.com/nicolasstucki
195+
[@liufengyun]: https://github.com/liufengyun
196+
[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain
197+
[@biboudis]: https://github.com/biboudis
198+
[@allanrenucci]: https://github.com/allanrenucci
199+
[@Blaisorblade]: https://github.com/Blaisorblade
200+
[@Duhemm]: https://github.com/Duhemm
201+
[@AleksanderBG]: https://github.com/AleksanderBG
202+
[@milessabin]: https://github.com/milessabin
203+
[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk

0 commit comments

Comments
 (0)