Scala 3.1.1 and forward compatibility news

Tuesday 1 February 2022

Paweł Marks, VirtusLab

Hello from the Scala 3 team! We are back with a new release of the Scala compiler and some exciting news about improvements in forward compatibility.

Improvements in Scala 3.1.1

Scala 3.1.1 is a patch release focused on bug fixes. Although there are no new additions to the language, you can still spot some noticeable improvements:

  • You can use using clauses to introduce subtyping relations between types in the function body.

    Now, code like the following should compile. Any value of type A can be used where a value of type B is expected as long as a given instance of A <:< B is in scope:

      def example[A, B](a: A)(using A <:< B) =
        val b: B = a
        ???
    

    To learn more see PR #13662 and related issue.

  • Mirrors can be correctly summoned for hierarchical sum types compiled by Scala 3.0.x. It is now safe to derive a type class for a type dependency that was compiled with a pre-3.1.0 compiler. (PR #14100).
  • Dual Scala 2/3 macros can be now declared in non-experimental scopes (PR #13795).
  • Scaladoc documentation has an improved UI.

For a comprehensive list of fixes, take a look at the full changelog on GitHub.

3.1.2-RC1 and forward compatibility improvements

Alongside 3.1.1 we have released the first RC version of the next patch release of the compiler. 3.1.2-RC1 contains further fixes, but most importantly it is our first step in improving forward compatibility in Scala.

Scala 3 has excellent backward compatibility guarantees between the minor versions. Right now, that means that code compiled with Scala 3.1 can depend on libraries published with 3.0 without any problems. The opposite, hovewer, is not true. Code compiled with 3.0 is not able to read dependencies compiled with 3.1. After the recent release of Scala 3.1.0, we can see that libraries should be really cautious with updating the compiler version, as it forces a bump on every user of that library. We do not want library authors to be stuck on old versions of the compiler as that would mean that they are locked out of many bugfixes, or we would need to spend enormous effort on backporting every bugfix to all past versioning lines.

Our current plan to mitigate those difficulties is described in the contributors discussion, where you are free to leave your feedback. We already have implemented the first and most important part of the solution and have it ready for public testing. Beginning with Scala 3.1.2-RC1 the compiler is able to generate outputs that can be consumed by its older versions. To enable that, you need to specify the minimal targeted minor language version by using the experimental -Yscala-release flag.

We expect that in the future authors will use the newest available version of the compiler with -Yscala-release set to the lowest language version that support all features they need. This way they will be able to benefit from all the bugfixes without restricting their potential audience.

So, for example, compiling your library using Scala 3.1.2-RC2 with -Yscala-release:3.0 flag, you make it possible for people still using Scala 3.0 to depend on your library. This has some limitations, especially your library cannot have any dependencies compiled with -Yscala-release version higher than 3.0. You also won’t be able to use any symbol added to the standard library after 3.0. They are marked in the code and in the documentation by the @since annotation that was also added in this version.

One important note is that the -Yscala-release flag is experimental and not yet available in any stable release of the compiler. It means the build tools, such as SBT or Mill, are not yet aware of its existence. Of course, you can declare usage of the flag in your build file, and the compiler will respect it. However, there may still be some hiccups, like generated artifacts depending on the incorrect version of the stdlib. We will do our best to help fix those minor issues before the stable release of 3.1.2.

Detailed description of the new flag can be found in the reference page for the binary compatibility.

If you are interested in other changes brought by 3.1.2-RC1, there is, as always, a changelog on GitHub.

Contributors

Thank you to all the contributors who made this release possible.

According to git shortlog -sn --no-merges 3.1.0..3.1.1 these are:

    50  Fengyun Liu
    43  Martin Odersky
    26  Olivier Blanvillain
    24  Kacper Korban
    21  Filip Zybała
    18  Dale Wijnand
    18  Nicolas Stucki
    17  Phil
    13  Andrzej Ratajczak
    10  Guillaume Martres
    10  noti0na1
     8  Paweł Marks
     7  Jamie Thompson
     5  soronpo
     5  Tom Grigg
     3  Yichen Xu
     3  Dmitrii Naumenko
     3  ghostbuster91
     3  Julien Richard-Foy
     2  Stéphane Micheloud
     2  bjornregnell
     2  Vadim Chelyshov
     1  ysthakur
     1  Daniel Esik
     1  EnzeXing
     1  Jasper Moeys
     1  Katja Goltsova
     1  Matthieu Bovel
     1  Ondrej Lhotak
     1  Oron Port
     1  Rikito Taniguchi
     1  Seth Tisue
     1  Som Snytt
     1  Sébastien Doeraene
     1  Tomasz Godzik
     1  oronpo