|
| 1 | +--- |
| 2 | +layout: blog-page |
| 3 | +title: Announcing Dotty 0.16.0-RC3 – the Scala Days 2019 Release |
| 4 | +author: Aggelos Biboudis and Anatolii Kmetiuk |
| 5 | +date: 2019-06-11 |
| 6 | +--- |
| 7 | + |
| 8 | +Hello again! Today, we are excited to announce the 16th release of Dotty. The |
| 9 | +development of Dotty continues according to our schedule but today, Tuesday June |
| 10 | +the 11th, we are electrified as it is the first day of [Scala Days 2019](https://scaladays.org/) |
| 11 | +which marks the *10th* anniversary of Scala Days. |
| 12 | +With this release we are getting closer to the _envelope_ of the new features |
| 13 | +that Dotty plans to offer. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +This release serves as a technology preview that demonstrates new |
| 18 | +language features and the compiler supporting them. |
| 19 | + |
| 20 | +Dotty is the project name for technologies that are being considered for |
| 21 | +inclusion in Scala 3. Scala has pioneered the fusion of object-oriented and |
| 22 | +functional programming in a typed setting. Scala 3 will be a big step towards |
| 23 | +realising the full potential of these ideas. Its main objectives are to |
| 24 | + |
| 25 | +- become more opinionated by promoting programming idioms we found to work well, |
| 26 | +- simplify where possible, |
| 27 | +- eliminate inconsistencies and surprising behaviours, |
| 28 | +- build on strong foundations to ensure the design hangs together well, |
| 29 | +- consolidate language constructs to improve the language’s consistency, safety, ergonomics, and |
| 30 | + performance. |
| 31 | + |
| 32 | +You can learn more about Dotty on our [website](https://dotty.epfl.ch). |
| 33 | + |
| 34 | +<!--more--> |
| 35 | + |
| 36 | +This is our 16th scheduled release according to our |
| 37 | +[6-week release schedule](https://dotty.epfl.ch/docs/contributing/release.html). |
| 38 | + |
| 39 | +# What’s new in the 0.16.0-RC3 technology preview? |
| 40 | + |
| 41 | +<!-- https://github.com/lampepfl/dotty/pulls?q=is%3Apr+closed%3A%3E2019-05-23+is%3Aclosed+sort%3Acomments-desc --> |
| 42 | + |
| 43 | +## Syntax Change: Type Lambdas |
| 44 | + |
| 45 | +We reconsider the syntax of type lambdas in an effort to provide an improved |
| 46 | +visual cue for two categories of types: types that relate to normal function |
| 47 | +types and types that operate on a higher level. The _fat_ arrow `=>` definitely |
| 48 | +relates to the first, while we reserve now `->` to mean _pure function_ in the |
| 49 | +future. As a result, we disengage `=>` from type lambdas, which are now |
| 50 | +represented by `=>>`. As a result a function from types to types is written as |
| 51 | +`[X] =>> F[X]`. |
| 52 | + |
| 53 | +For those who are interested in the discussions, |
| 54 | +[#6558](https://github.com/lampepfl/dotty/pull/6558) introduced the new syntax. |
| 55 | + |
| 56 | +## Syntax Change: Wildcard Arguments in Types |
| 57 | + |
| 58 | +The syntax of wildcard arguments in types has changed from `_` to `?`. Example: |
| 59 | + |
| 60 | +```scala |
| 61 | +List[?] |
| 62 | +Map[? <: AnyRef, ? >: Null] |
| 63 | +``` |
| 64 | + |
| 65 | +Again, in an effort to fine-tune our syntax we put two features, from the world |
| 66 | +of terms and types, side-by-side and drew parallels at the syntactic level. |
| 67 | +Consequently, as `f(_)` is a shorthand for the lambda `x => f(x)` and as we plan |
| 68 | +ahead for making `C[_]` to be a shorthand for the type lambda `[X] =>> C[X]` in |
| 69 | +the future we pick `?` as a replacement syntax for wildcard types, since it |
| 70 | +aligns with Java's syntax. |
| 71 | + |
| 72 | +For more information please read our documentation on |
| 73 | +[Wildcards](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html). |
| 74 | + |
| 75 | +# Syntax Change: Contextual Abstractions |
| 76 | + |
| 77 | +We reconsider the syntax for contextual abstractions introducing `delegates` |
| 78 | +(formerly known as `implied`). `delegate`, in the context of contextual |
| 79 | +abstraction means that we declare a _representative of a type_. We use |
| 80 | +`delegate` as a noun. Note that this change is solely syntactical/grammatical |
| 81 | +and its motivation is to give a clearer meaning to those _canonical_ values of |
| 82 | +certain types (like `Ord[Int]`), that serve for synthesizing arguments to |
| 83 | +`given` clauses. |
| 84 | + |
| 85 | +```scala |
| 86 | +delegate IntOrd for Ord[Int] { |
| 87 | + def compare(x: Int, y: Int) = |
| 88 | + if (x < y) -1 else if (x > y) +1 else 0 |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +```scala |
| 93 | +delegate ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { |
| 94 | +``` |
| 95 | + |
| 96 | +For more information, the documentation has been updated as part of the relevant |
| 97 | +PR [#6649](https://github.com/lampepfl/dotty/pull/6649) |
| 98 | + |
| 99 | +## Polymorphic function types |
| 100 | + |
| 101 | +We add preliminary support for _polymorphic function types_. Nowadays, when we |
| 102 | +want to write a universally quantified function over elements of lists of type |
| 103 | +`T` we write e.g., `List[T] => List[(T, T)]` where `T` is bound at an enclosing |
| 104 | +definition. With polymorphic function types (PFT hereafter) we can quantify the |
| 105 | +parametric type locally. For example: |
| 106 | + |
| 107 | +```scala |
| 108 | +[T <: AnyVal] => List[T] => List[(T, T)] |
| 109 | +``` |
| 110 | + |
| 111 | +As you notice, this gives us the ability to impose restrictions on the type |
| 112 | +variable `T` locally. Assume, you have an identity function with `type id = T => T`. |
| 113 | +By writing it as `type id = [T] => T => T` we abstract further the concept |
| 114 | +of a _polymorphic function_ and make it a *true* _family of functions_. |
| 115 | + |
| 116 | +The code below (correctly) fails to type check because `T` needs to be bounded |
| 117 | +in the enclosing class: |
| 118 | + |
| 119 | +```scala |
| 120 | + val id: T => T = t => t |
| 121 | + println(s"${id(1)} , ${id(7.0d)}") |
| 122 | +``` |
| 123 | + |
| 124 | +With PFTs we can now achieve what we want: |
| 125 | + |
| 126 | +```scala |
| 127 | + val id = [T] => (t: T) => t |
| 128 | + println(s"${id(1)} , ${id(7.0d)}") |
| 129 | +``` |
| 130 | + |
| 131 | +For those who are interested in the discussions and more test cases, |
| 132 | +[#4672](https://github.com/lampepfl/dotty/pull/4672/) introduced PFTs. |
| 133 | + |
| 134 | +## lazy vals are now thread-safe by default |
| 135 | + |
| 136 | +Previously thread-safety was required using `@volatile` but that would not be |
| 137 | +consistent with Scala 2. The old behavior of non-volatile lazy vals can be |
| 138 | +recovered by using the newly-introduced `@threadUnsafe`. |
| 139 | + |
| 140 | +For more information please read our documentation on the |
| 141 | +[threadUnsafe annotation](https://dotty.epfl.ch/docs/reference/other-new-features/threadUnsafe-annotation.html). |
| 142 | + |
| 143 | +## Introducing `for` clauses for importing delegate imports by type |
| 144 | + |
| 145 | +Since delegate instances can be anonymous it is not always practical to import |
| 146 | +them by their name, and wildcard imports are typically used instead. By-type |
| 147 | +imports provide a more specific alternative to wildcard imports, which makes it |
| 148 | +clearer what is imported. Example: |
| 149 | + |
| 150 | + ```scala |
| 151 | +import delegate A.{for TC} |
| 152 | +``` |
| 153 | + |
| 154 | +This imports any delegate instance in `A` that has a type which conforms tp `TC`. |
| 155 | +There can be several bounding types following a `for` and bounding types can |
| 156 | +contain wildcards. |
| 157 | +For instance, assuming the object |
| 158 | + |
| 159 | +```scala |
| 160 | +object Delegates { |
| 161 | + delegate intOrd for Ordering[Int] |
| 162 | + delegate [T: Ordering] listOrd for Ordering[List[T]] |
| 163 | + delegate ec for ExecutionContext = ... |
| 164 | + delegate im for Monoid[Int] |
| 165 | +} |
| 166 | +``` |
| 167 | +the import |
| 168 | +``` |
| 169 | +import delegate Delegates.{for Ordering[_], ExecutionContext} |
| 170 | +``` |
| 171 | +would import the `intOrd`, `listOrd`, and `ec` instances but leave out the `im` |
| 172 | +instance, since it fits none of the specified bounds. |
| 173 | + |
| 174 | +## New typeclass derivation scheme |
| 175 | + |
| 176 | +Summary of measured differences with the old scheme: |
| 177 | + |
| 178 | +- About 100 lines more compiler code - the rest of the lines changed diff is |
| 179 | +tests. |
| 180 | +- About 13-15% more code generated for typeclass instances |
| 181 | +- About 3-4% slower to compile typeclass instances |
| 182 | + |
| 183 | +Advantages of new scheme: |
| 184 | + |
| 185 | +- Fewer allocations, since mirrors (`Generic` has been renamed to `Mirror`) are |
| 186 | + usually shared instead of being allocated at runtime. |
| 187 | +- It works well even if there are no derives clauses. The old scheme would |
| 188 | + generate more code in that case. |
| 189 | +- Complete decoupling between derives clauses and mirror generation. |
| 190 | + |
| 191 | +For the technical details of these changes please consule the corresponding PR |
| 192 | +[#6531](https://github.com/lampepfl/dotty/pull/6531). |
| 193 | + |
| 194 | +# Let us know what you think! |
| 195 | + |
| 196 | +If you have questions or any sort of feedback, feel free to send us a message on our |
| 197 | +[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please |
| 198 | +[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new). |
| 199 | + |
| 200 | +## Contributing |
| 201 | + |
| 202 | +Thank you to all the contributors who made this release possible! |
| 203 | + |
| 204 | +According to `git shortlog -sn --no-merges 0.15.0-RC1..0.16.0-RC3` these are: |
| 205 | + |
| 206 | +``` |
| 207 | +88 Martin Odersky |
| 208 | +51 Anatolii |
| 209 | +48 Nicolas Stucki |
| 210 | +26 Guillaume Martres |
| 211 | +21 Miles Sabin |
| 212 | +19 Liu Fengyun |
| 213 | +12 Aleksander Boruch-Gruszecki |
| 214 | +11 Sébastien Doeraene |
| 215 | + 8 Aggelos Biboudis |
| 216 | + 4 Olivier Blanvillain |
| 217 | + 3 Eugene Yokota |
| 218 | + 1 Dale Wijnand |
| 219 | + 1 Allan Renucci |
| 220 | + 1 Olivier ROLAND |
| 221 | +``` |
| 222 | + |
| 223 | +If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved! |
| 224 | +Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html), |
| 225 | +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). |
| 226 | +They make perfect entry points into hacking on the compiler. |
| 227 | + |
| 228 | +We are looking forward to having you join the team of contributors. |
| 229 | + |
| 230 | +## Library authors: Join our community build |
| 231 | + |
| 232 | +Dotty now has a set of widely-used community libraries that are built against every nightly Dotty |
| 233 | +snapshot. Currently this includes ScalaPB, algebra, scalatest, scopt and squants. |
| 234 | +Join our [community build](https://github.com/lampepfl/dotty-community-build) |
| 235 | +to make sure that our regression suite includes your library. |
| 236 | + |
| 237 | +[Scastie]: https://scastie.scala-lang.org/?target=dotty |
| 238 | + |
| 239 | +[@odersky]: https://github.com/odersky |
| 240 | +[@DarkDimius]: https://github.com/DarkDimius |
| 241 | +[@smarter]: https://github.com/smarter |
| 242 | +[@felixmulder]: https://github.com/felixmulder |
| 243 | +[@nicolasstucki]: https://github.com/nicolasstucki |
| 244 | +[@liufengyun]: https://github.com/liufengyun |
| 245 | +[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain |
| 246 | +[@biboudis]: https://github.com/biboudis |
| 247 | +[@allanrenucci]: https://github.com/allanrenucci |
| 248 | +[@Blaisorblade]: https://github.com/Blaisorblade |
| 249 | +[@Duhemm]: https://github.com/Duhemm |
| 250 | +[@AleksanderBG]: https://github.com/AleksanderBG |
| 251 | +[@milessabin]: https://github.com/milessabin |
| 252 | +[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk |
0 commit comments