|
| 1 | +--- |
| 2 | +layout: blog-detail |
| 3 | +post-type: blog |
| 4 | +by: Paweł Marks, VirtusLab |
| 5 | +title: Scala 3.1.0 released! |
| 6 | +--- |
| 7 | +Hello from the Scala 3 team! It has already been six weeks since we have announced the release candidate for the first minor version after the initial release of Scala 3. Now, after two more RCs, we can confidently promote Scala 3.1.0-RC3 to a new stable release of the language. In other words, Scala 3.1.0 is officially out! |
| 8 | + |
| 9 | +You don't need to worry about having to migrate your projects to the new version. Scala 3 has strong compatibility guarantees, and all code working in 3.0.2 will also work in 3.1. On the other hand, switching to Scala 3.1 allows you to use many improvements and a handful of newly stabilized APIs. |
| 10 | + |
| 11 | +## What's new in 3.1 |
| 12 | + |
| 13 | +### New experimental feature: safer exceptions |
| 14 | + |
| 15 | +A new experimental feature that allows declaring and checking which exceptions can be thrown. It relies on the effects as implicit capabilities pattern. |
| 16 | + |
| 17 | +You can opt-in using following import. |
| 18 | + |
| 19 | +```scala |
| 20 | +import language.experimental.saferExceptions |
| 21 | +``` |
| 22 | + |
| 23 | +Now it is possible to mark types with exception that cna be thrown during the evalutaion: |
| 24 | + |
| 25 | +```scala |
| 26 | +def f(x: Double): Double canThrow LimitExceeded = |
| 27 | + if x < limit then f(x) else throw LimitExceeded()) |
| 28 | +``` |
| 29 | + |
| 30 | +You can read more in [the document proposing this feature](https://github.com/lampepfl/dotty/blob/release-3.1.0/docs/docs/reference/experimental/canthrow.md). |
| 31 | + |
| 32 | +### Efficient bytecode for matching over strings |
| 33 | + |
| 34 | +When Scala 3.0 has been compiling pattern matches with `Int` as a scrutinee type, it was emitting bytecode containing very efficient instructions: `lookupswitch` or `tableswitch`. Now in Scala 3.1, similar behavior was implemented for matching over `String` literals. |
| 35 | + |
| 36 | +```scala |
| 37 | +fruit match |
| 38 | + case "apple" => 1 |
| 39 | + case "orange" => 2 |
| 40 | + case "banana" => 3 |
| 41 | + case _ => 0 |
| 42 | +``` |
| 43 | + |
| 44 | +will now generate `lookupswitch` over hash codes of `String` literals instead of a chain of conditional expressions. This behavior is consistent with what Java is doing and more performant than the old approach. |
| 45 | + |
| 46 | +### Support for `-Wconf` and `@nowarn` |
| 47 | + |
| 48 | +We have added a `-Wconf` compiler flag that allows filtering and configuring compiler warnings (silence them, or turn them into errors). |
| 49 | + |
| 50 | +We have also integrated [the silencer plugin](https://github.com/ghik/silencer) into the compiler, which allows suppressing warnings locally using the `@nowarn` annotation. |
| 51 | + |
| 52 | +`-Wconf` and `@nowarn` work largely the same way as in Scala 2, but some filters for selecting warnings are different. For the more details see the output of `-Wconf:help` flag. |
| 53 | + |
| 54 | +### Simplified Manifest synthesis |
| 55 | + |
| 56 | +For the sake of compatibility with Scala 2, the Scala 3 compiler now generates given instances for the `Manifest` trait. The new implementation is a slightly simplified approximation of the Scala 2 implementation. It guarantees that any of the expressions: |
| 57 | + |
| 58 | +- `manifest[A] == manifest[B]` |
| 59 | +- `manifest[A].runtimeClass == manifest[B].runtimeClass` |
| 60 | +- `optManifest[A] == optManifest[B]` |
| 61 | +- `optManifest[A].asInstanceOf[ClassTag[A]].runtimeClass == optManifest[B].asInstanceOf[ClassTag[B]].runtimeClass` |
| 62 | + |
| 63 | +that was true in Scala 2, will also remain true when compiled with Scala 3. |
| 64 | + |
| 65 | +### Other changes |
| 66 | + |
| 67 | +- `Unapply.apply` constructor was added to the reflection API |
| 68 | +- Scastie was integrated into Scaladoc to make snippets interactive. |
| 69 | +- `@experimental` spec was changed. See more detail in [the design document](https://github.com/lampepfl/dotty/blob/release-3.1.0/docs/docs/reference/other-new-features/experimental-defs.md) |
| 70 | +- Now `TastyInspector.{inspectTastyFiles, inspectTastyFilesInJar, inspectAllTastyFiles}` return a boolean value indicating whether the process succeeded |
| 71 | +- A `Wildcard` was made a subtype of `Ident` in the reflection API |
| 72 | +- `TypedOrTest` was added as a super type of `Typed` in the reflection API |
| 73 | + |
| 74 | +Beside that scala 3.1.0 introduced multiple small improvements and fixed handful of bugs. You can see [the detailed changelog](https://github.com/lampepfl/dotty/releases/tag/3.1.0) on GitHub. |
| 75 | + |
| 76 | +## What's next |
| 77 | + |
| 78 | +During the Scala 3.1.0 stabilization period, which took the last six weeks, we haven't stopped improving the language and fixing the bugs in the compiler. You can already test the results of our work, as they are released as Scala 3.1.1-RC1. [The full changelog](https://github.com/lampepfl/dotty/releases/tag/3.1.1-RC1) is as always available on GitHub. |
| 79 | + |
| 80 | +You can expect the stable release of Scala 3.1.1 in early December. |
| 81 | + |
| 82 | +## Contributors |
| 83 | + |
| 84 | +Thank you to all the contributors who made the release of 3.1.0 possible 🎉 |
| 85 | + |
| 86 | +According to `git shortlog -sn --no-merges 3.0.2..3.1.0` these are: |
| 87 | + |
| 88 | +``` |
| 89 | + // TODO |
| 90 | +``` |
| 91 | + |
| 92 | +## Library authors: Join our community build |
| 93 | + |
| 94 | +Scala 3 now has a set of widely-used community libraries that are built against every nightly Scala 3 snapshot. |
| 95 | +Join our [community build](https://github.com/lampepfl/dotty/tree/master/community-build) |
| 96 | +to make sure that our regression suite includes your library. |
| 97 | + |
| 98 | +[Scastie]: https://scastie.scala-lang.org/?target=dotty |
| 99 | + |
| 100 | +[@odersky]: https://github.com/odersky |
| 101 | +[@DarkDimius]: https://github.com/DarkDimius |
| 102 | +[@smarter]: https://github.com/smarter |
| 103 | +[@felixmulder]: https://github.com/felixmulder |
| 104 | +[@nicolasstucki]: https://github.com/nicolasstucki |
| 105 | +[@liufengyun]: https://github.com/liufengyun |
| 106 | +[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain |
| 107 | +[@biboudis]: https://github.com/biboudis |
| 108 | +[@allanrenucci]: https://github.com/allanrenucci |
| 109 | +[@Blaisorblade]: https://github.com/Blaisorblade |
| 110 | +[@Duhemm]: https://github.com/Duhemm |
| 111 | +[@AleksanderBG]: https://github.com/AleksanderBG |
| 112 | +[@milessabin]: https://github.com/milessabin |
| 113 | +[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk |
0 commit comments