|
| 1 | +--- |
| 2 | +layout: blog-page |
| 3 | +title: Announcing Dotty 0.21.0-RC1 – ❄️ Feature Freeze ❄️ |
| 4 | +author: Aggelos Biboudis |
| 5 | +authorImg: /images/aggelos.png |
| 6 | +date: 2019-12-21 |
| 7 | +--- |
| 8 | + |
| 9 | +Greetings and we wish you Merry Christmas 🎄! |
| 10 | + |
| 11 | +We are excited to announce 0.21.0-RC1 of Scala 3. In this version we add support |
| 12 | +for non-nullable reference types and a flow-sensitive analysis that work |
| 13 | +complementary. We present new syntax for given extensions, matches and pattern |
| 14 | +matching over quotes. We are also happy to announce that SemanticDB extraction |
| 15 | +is now supported! |
| 16 | + |
| 17 | +# ❄️ Feature Freeze ❄️ |
| 18 | +This release is a HUGE milestone for us, for Dotty, for Scala 3, for our community. Since that |
| 19 | +[initial commit](https://github.com/lampepfl/dotty/commit/90962407e72d88f8f3249ade0f6bd60ff15af5ce) |
| 20 | +on the 6th December of 2012 when the only feature was the basic structure of a |
| 21 | +compiler based on the DOT calculus, we have come a long way. |
| 22 | + |
| 23 | +7 years and 20k commits later we are happy to announce that we are entering the |
| 24 | +*feature freeze* phase of Scala 3 ❄️❄️☃️. This means that with this release we |
| 25 | +stop adding new features ([Overview of Features](https://dotty.epfl.ch/docs/reference/overview.html)) and we focus on: |
| 26 | + |
| 27 | +- bug fixing and general quality assurance towards the final release 🐛 |
| 28 | +- performance engineering 🏎️ |
| 29 | +- documentation improvements 📕 |
| 30 | +- education 👨🏫 |
| 31 | + |
| 32 | +### Community-build |
| 33 | + |
| 34 | +Feature Freeze (FF) doesn't mean that development slows down. On the contrary! |
| 35 | +FF means that we can now put the Scala 3 compiler under heavy load, getting it |
| 36 | +ready for industrial strength applications. At the moment we have 23 |
| 37 | +projects on our community projects and we expect this number to go up! |
| 38 | + |
| 39 | +> https://github.com/lampepfl/dotty/tree/master/community-build/community-projects |
| 40 | +
|
| 41 | +This project contains tests to build and test a corpus of open sources Scala 2.x |
| 42 | +projects against Scala 3. |
| 43 | + |
| 44 | +To run the community-build on a local machine, first fetch all the git |
| 45 | +submodules with `git submodule update --init` and run `sbt community-build/test` |
| 46 | +from the root of the dotty repo. |
| 47 | + |
| 48 | +### New Issues |
| 49 | + |
| 50 | +Firstly thank you for all the hard work in issue reporting! FF means that our |
| 51 | +issue tracker will now be more important than ever. We encourage you to stress |
| 52 | +the compiler and report self contained test-cases! Bug minimization is hard and |
| 53 | +a form of art! Help us unearth those nasty bugs! ✊ |
| 54 | + |
| 55 | +Last but not least we restate the mission of Scala 3. Scala has pioneered the |
| 56 | +fusion of object-oriented and functional programming in a typed setting and Scala 3 |
| 57 | +will be a big step towards realising the full potential of these ideas. Its main |
| 58 | +objectives are to: |
| 59 | + |
| 60 | +- become more opinionated by promoting programming idioms we found to work well, |
| 61 | +- simplify where possible, |
| 62 | +- eliminate inconsistencies and surprising behaviours, |
| 63 | +- build on strong foundations to ensure the design hangs together well, |
| 64 | +- consolidate language constructs to improve the language’s consistency, safety, ergonomics, and |
| 65 | + performance. |
| 66 | + |
| 67 | +You can learn more about Dotty on our [website](https://dotty.epfl.ch). |
| 68 | + |
| 69 | +<!--more--> |
| 70 | + |
| 71 | +# What’s new in the 0.21.0-RC1 technology preview? |
| 72 | + |
| 73 | +## Dotty with explicit nulls and flow typing |
| 74 | + |
| 75 | +We add support for non-nullable reference types under the compiler option |
| 76 | +`-Yexplicit-nulls`. Nullability needs then to be expressed explicitly via unions |
| 77 | +(e.g. `String|Null`). |
| 78 | + |
| 79 | +This means the following code will no longer typecheck: |
| 80 | + |
| 81 | +```scala |
| 82 | +val x: String = null // error: found `Null`, but required `String` |
| 83 | +``` |
| 84 | + |
| 85 | +Instead, to mark a type as nullable we use a type union: |
| 86 | + |
| 87 | +```scala |
| 88 | +val x: String|Null = null // ok |
| 89 | +``` |
| 90 | + |
| 91 | +This change affects two parts of the compiler. Firstly we have a new type |
| 92 | +hierarchy for `Null` and a _translation layer_ from Java types to Scala types, |
| 93 | +which balances soundness and usability. |
| 94 | + |
| 95 | +With this release we also introduce a flow-sensitive analysis that refines the |
| 96 | +type of an expression based on control-flow. In the example below `s` is |
| 97 | +`String|Null`. The `if` branch validates the value of `s` against `Null` so `s` |
| 98 | +can be safely considered `String` in that scope. |
| 99 | + |
| 100 | +```scala |
| 101 | +val s: String|Null = ??? |
| 102 | + |
| 103 | +if (s != null) { |
| 104 | + // s: String |
| 105 | +} |
| 106 | +else { |
| 107 | + // s: String|Null |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +Note, that more complex tests are also supported like: |
| 112 | + |
| 113 | +```scala |
| 114 | +val s: String|Null = ??? |
| 115 | +val s2: String|Null = ??? |
| 116 | + |
| 117 | +if (s != null && s2 != null) // s: String and s2: String |
| 118 | +``` |
| 119 | + |
| 120 | +but also in a short-circuting manner: |
| 121 | + |
| 122 | +```scala |
| 123 | +val s: String|Null = ??? |
| 124 | + |
| 125 | +if (s != null && s.length > 0) // s: String in `s.length > 0` |
| 126 | +``` |
| 127 | + |
| 128 | +For more info refer to the docs on [Explicit Nulls](https://dotty.epfl.ch/docs/reference/other-new-features/explicit-nulls.html). |
| 129 | + |
| 130 | +## New syntax for given instances defining extension methods |
| 131 | + |
| 132 | +To make code navigation easier in the case of `given` extension methods we |
| 133 | +change the syntax in the following manner. Hereafter, we write: |
| 134 | + |
| 135 | +```scala |
| 136 | +given listOps: extension [T](xs: List[T]) { ... } |
| 137 | + |
| 138 | +given extension (s: String) { ... } |
| 139 | +``` |
| 140 | + |
| 141 | +instead of: |
| 142 | + |
| 143 | +```scala |
| 144 | +given listOps: [T](xs: List[T]) { ... } |
| 145 | + |
| 146 | +given (s: String) { ... } |
| 147 | +``` |
| 148 | + |
| 149 | +The rationale is to communicate in a clean way that the parameters go on the |
| 150 | +extension method and not the wrapper (e.g., `listOps`) . |
| 151 | + |
| 152 | +To learn more about extension methods and given instances for extension methods in particular follow the docs on [Given Instances for Extension Methods](https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html#given-instances-for-extension-methods) |
| 153 | + |
| 154 | +## New match syntax |
| 155 | + |
| 156 | +We introduce an improved treatment of `match`. We reintroduce `match` as an |
| 157 | +alphanumeric, left-associative, infix operator that can support chain matches: |
| 158 | + |
| 159 | +```scala |
| 160 | +xs match { |
| 161 | + case Nil => "empty" |
| 162 | + case x :: xs1 => "nonempty" |
| 163 | +} match { |
| 164 | + case "empty" => 0 |
| 165 | + case "nonempty" => 1 |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +By using the new treatment we can now offer `match` as a method: |
| 170 | + |
| 171 | +```scala |
| 172 | +xs.match { |
| 173 | + case Nil => false |
| 174 | + case _ => true |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +You can read more on our docs [Match Expressions](https://dotty.epfl.ch/docs/reference/changed-features/match-syntax.html) and on the interesting discussions on [contributors](https://contributors.scala-lang.org/t/pre-sip-demote-match-keyword-to-a-method/2137/2). |
| 179 | + |
| 180 | +## New quoted pattern matching |
| 181 | + |
| 182 | +We introduce a high-level API to deconstruct or extract values out of `Expr` |
| 183 | +using pattern matching. It consists of quoted patterns that allows to |
| 184 | +deconstruct complex code that contains a precise structure, types or methods. |
| 185 | +Patterns `'{ ... }` can be placed in any location where Scala expects a pattern. |
| 186 | + |
| 187 | +For example, the following snippet implements a simple, 1-level, non-recursive |
| 188 | +rewriter macro for exponents. `rewrite` is a an inline method definition |
| 189 | +designating a macro. To inspect an `expr` value we can now use the quoted syntax |
| 190 | +as patterns inside a match expression. Notice that quotes designate patterns and |
| 191 | +`$`, the familiar syntax for splices is used to _extract_ (capture) information |
| 192 | +out of a pattern. |
| 193 | + |
| 194 | +```scala |
| 195 | +inline def rewrite(expr: => Double): Double = ${rewrite('expr)} |
| 196 | + |
| 197 | +def rewrite(expr: Expr[Double])(given QuoteContext): Expr[Double] = { |
| 198 | + val res = expr match { |
| 199 | + // product rule |
| 200 | + case '{ power2($a, $x) * power2($b, $y)} if a.matches(b) => '{ power2($a, $x + $y) } |
| 201 | + // rules of 1 |
| 202 | + case '{ power2($a, 1)} => a |
| 203 | + case '{ power2(1, $a)} => '{ 1.0 } |
| 204 | + // rule of 0 |
| 205 | + case '{ power2($a, 0)} => '{ 1.0 } |
| 206 | + // power rule |
| 207 | + case '{ power2(power2($a, $x), $y)} => '{ power2($a, $x * $y ) } |
| 208 | + case _ => expr |
| 209 | + } |
| 210 | + res |
| 211 | +} |
| 212 | +``` |
| 213 | + |
| 214 | +Additionally to the quoted patterns we provide extractors in |
| 215 | +`scala.quoted.matching` that extract static information from `Expr`s. Namely |
| 216 | +`Const`, `ExprSeq` and `ConstSeq`. |
| 217 | + |
| 218 | +To learn more read our docs on [pattern matching over quotes](https://dotty.epfl.ch/docs/reference/metaprogramming/macros.html#pattern-matching-on-quoted-expressions). |
| 219 | + |
| 220 | +## Added support for SemanticDB extraction |
| 221 | + |
| 222 | +Scala 3 now offers support for SemanticDB extraction producing `.semanticdb` files. |
| 223 | +Users can use the `-Ysemanticdb` compiler flag. |
| 224 | + |
| 225 | + |
| 226 | +# Let us know what you think! |
| 227 | + |
| 228 | +If you have questions or any sort of feedback, feel free to send us a message on our |
| 229 | +[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please |
| 230 | +[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new). |
| 231 | + |
| 232 | +## Contributing |
| 233 | + |
| 234 | +Thank you to all the contributors who made this release possible! |
| 235 | + |
| 236 | +According to `git shortlog -sn --no-merges 0.20.0-RC1..0.21.0-RC1` these are: |
| 237 | + |
| 238 | +``` |
| 239 | + <todo> |
| 240 | +``` |
| 241 | + |
| 242 | +If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved! |
| 243 | +Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html), |
| 244 | +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). |
| 245 | +They make perfect entry points into hacking on the compiler. |
| 246 | + |
| 247 | +We are looking forward to having you join the team of contributors. |
| 248 | + |
| 249 | +## Library authors: Join our community build |
| 250 | + |
| 251 | +Dotty now has a set of widely-used community libraries that are built against every nightly Dotty |
| 252 | +snapshot. Currently, this includes ScalaPB, algebra, scalatest, scopt and squants. |
| 253 | +Join our [community build](https://github.com/lampepfl/dotty-community-build) |
| 254 | +to make sure that our regression suite includes your library. |
| 255 | + |
| 256 | +[Scastie]: https://scastie.scala-lang.org/?target=dotty |
| 257 | + |
| 258 | +[@odersky]: https://github.com/odersky |
| 259 | +[@DarkDimius]: https://github.com/DarkDimius |
| 260 | +[@smarter]: https://github.com/smarter |
| 261 | +[@felixmulder]: https://github.com/felixmulder |
| 262 | +[@nicolasstucki]: https://github.com/nicolasstucki |
| 263 | +[@liufengyun]: https://github.com/liufengyun |
| 264 | +[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain |
| 265 | +[@biboudis]: https://github.com/biboudis |
| 266 | +[@allanrenucci]: https://github.com/allanrenucci |
| 267 | +[@Blaisorblade]: https://github.com/Blaisorblade |
| 268 | +[@Duhemm]: https://github.com/Duhemm |
| 269 | +[@AleksanderBG]: https://github.com/AleksanderBG |
| 270 | +[@milessabin]: https://github.com/milessabin |
| 271 | +[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk |
0 commit comments