diff --git a/_data/scala-releases.yml b/_data/scala-releases.yml index e6b7bec6d..998860fd1 100644 --- a/_data/scala-releases.yml +++ b/_data/scala-releases.yml @@ -1,7 +1,7 @@ - category: current_version - title: Current 3.4.x release - version: 3.4.2 - release_date: May 16, 2024 + title: Current 3.5.x release + version: 3.5.0 + release_date: August 22, 2024 - category: current_version title: Current 3.3.x LTS release version: 3.3.3 diff --git a/_downloads/2024-10-22-3.5.0.md b/_downloads/2024-10-22-3.5.0.md new file mode 100644 index 000000000..ca67aec15 --- /dev/null +++ b/_downloads/2024-10-22-3.5.0.md @@ -0,0 +1,10 @@ +--- +title: Scala 3.5.0 +start: 22 August 2024 +layout: downloadpage +release_version: 3.5.0 +release_date: "August 22, 2024" +permalink: /download/3.5.0.html +license: Apache License, Version 2.0 +api_docs: https://www.scala-lang.org/api/3.5.0/ +--- diff --git a/blog/_posts/2024-08-22-scala-3.5.0-released.md b/blog/_posts/2024-08-22-scala-3.5.0-released.md new file mode 100644 index 000000000..0c9724086 --- /dev/null +++ b/blog/_posts/2024-08-22-scala-3.5.0-released.md @@ -0,0 +1,192 @@ +--- +layout: blog-detail +post-type: blog +by: Paweł Marks, VirtusLab +title: Scala 3.5.0 released! +--- + +![Scala 3.5]({{ site.baseurl }}/resources/img/scala-3.5-launch.jpg) + +We are happy to announce that after long and hard work by the entire compiler team, and after seven release candidates, the first version of the Scala 3.5 line is officially out! + +## New default runner - Scala CLI + +[Scala CLI](https://scala-cli.virtuslab.org/) is a popular tool among Scala devs. It allows lightning-fast running, testing, and prototyping of Scala scripts and single-module projects. In 3.5.0, it becomes part of the default Scala distribution. If you install Scala through popular package managers, such as Brew or SDKMAN!, the installed `scala` command allows you to compile, run, test, and even publish your code on Maven Central. It has out-of-the-box support for `using` directives, toolkits, compilation to JavaScript and native binaries, and other goodies formerly available only if you installed a separate tool. + +### Short example + +Given the following file named `biggerThan.scala` + +```scala +//> using dep com.lihaoyi::os-lib:0.10.3 + +@main def run(path: String, size: Int) = + os.list(os.Path(path, os.pwd)) + .filter: p => + os.size(p) > size * 1024 + .foreach(println) +``` + +We can run `scala biggerThan.scala -- ../my-directory 10`. This will download os-lib and its transitive dependencies, compile the source code, and finally run the compiled program, printing all files in `../my-directory` bigger than 10 kB. Subsequent invocations of the command will use cached bytecode, or if the source code changed, trigger incremental compilation. + +As os-lib is a part of the default Scala Toolkit, we can replace `//> using dep com.lihaoyi::os-lib:0.10.3` with `//> using toolkit default`. Furthermore, we can add `#!/usr/bin/env -S scala shebang` at the top of the file. Then, after setting the permissions (`chmod +x biggerThan.scala`), we can treat `biggerThan.scala` like any executable script. Invoking `./biggerThan.scala ../my-directory 10` will incrementally compile the file and then run it. + +To learn the full scope of the new capabilities, read about Scala CLI [commands](https://scala-cli.virtuslab.org/docs/commands/basics/) and [using-directives](https://scala-cli.virtuslab.org/docs/reference/directives) or glance at [the cookbook](https://scala-cli.virtuslab.org/docs/cookbooks/intro). + +Merging Scala CLI into the distribution doesn't change the behavior of popular build tools that work with Scala, such as sbt, Mill, Maven, and Gradle. It does, however, allow for maintaining and publishing single-module multiplatform libraries without any build tool. + +## What's new in 3.5.0? + +### Best effort compilation + +When using Metals, the IDE functions work great on code that compiles. However, once the user starts changing the code, the support drops in quality. This gets worse with a larger number of compilation errors and subsequent modifications. In 3.5.0, we have fixed this problem. We introduced a new mode of compilation called Best Effort Compilation. When enabled, the compiler will output BETASTy files for not-currently-compiling code. It can be used by tooling to provide autocompletion and other IDE features. + +To enable the use of BETASTy files in Metals, start the language server with `-Dmetals.enable-best-effort=true` or put that into `metals.serverProperties` setting in VS Code. We plan to enable this feature by default soon after gathering feedback from users. + +### Support for pipelined builds + +Scala 3.5.0 supports pipelined compilation. It can be enabled by setting `ThisBuild/usePipelining := true` in sbt build definition. This can result in significant speedups in compilation time for multi-module projects. + +You can learn more about how the pipelined compilation works and what benefits you can expect from [the talk by Jamie Thompson](https://www.youtube.com/watch?v=1uuFxEAiPuQ&t=1473s). + +### `var` in refinements + +Until now, only types, `val`s, and `def`s were allowed in type refinements. In 3.5.0, `var`s can also be declared. + +```scala +type A = { var number: Int } +``` + +is now legal and equivalent to + +```scala +type A = { def number: Int, def number_=($number: Int): Unit } +``` + +This change can simplify libraries based on metaprogramming using type refinements. + +### Support for binary integer literals + +Integer literals can now start with `0b` or `0B`. They will be interpreted as numbers in base 2. + +```scala +assert(0B1 == 1) +assert(0B10 == 2) +assert(0B_1000_0010 == 130) +assert(0B_1000_0010 == 0x82) +``` + +### Experimental: named tuples + +Scala 3.5 introduces experimental support for named tuples. The feature, hidden behind the `language.experimental.namedTuples` import, allows you to give meaningful names to tuple elements and use those names during constructing, destructuring, and pattern matching. + +```scala +import scala.language.experimental.namedTuples + +type Point = (x: Int, y: Int) +val point: Point = (x = 1, y = 2) +val is_it_point = (x = 5, y = 3) +val it_is: Point = is_it_point + +println(point.x) // prints 1 + +point match + case (x = real, y = 0) => println(s"Real number: $real") + case _ => println("Point doesn't represent a real number") +``` + +This is an implementation of [SIP-58](https://github.com/scala/improvement-proposals/blob/d649f6e6f333cd9232d85a12bd0445d18a673f10/content/named-tuples.md). + +### Experimental: new givens and context bounds syntax + +Another experimental feature introduced in Scala 3.5 is the new syntax for type classes. Some of these improvements are: `Self` type member instead of the type parameter, auxiliary type alias `is` or named context bounds, just to name a few. +The full list of proposed improvements and their examples can be found under [Modularity Improvements](https://scala-lang.org/api/3.5.0/docs/docs/reference/experimental/modularity.html) and [Better Support for Type Classes](https://scala-lang.org/api/3.5.0/docs/docs/reference/experimental/typeclasses.html). +To test the new syntax you would be required to use both the source version `future` and the additional language import `experimental.modularity`. + +```scala +//> using options -source:future -language:experimental.modularity + +trait Ord: + type Self + extension (x: Self) + def compareTo(y: Self): Int + def < (y: Self): Boolean = compareTo(y) < 0 + def > (y: Self): Boolean = compareTo(y) > 0 + +given intOrd: (Int is Ord) with + extension (x: Int) def compareTo(y: Int) = if x < y then -1 else if x > y then +1 else 0 + +def descending[T: Ord as asc]: T is Ord = new: + extension (x: T) def compareTo(y: T) = asc.compareTo(y)(x) + +def maximum[T](xs: List[T])(using T is Ord): T = + xs.reduceLeft((x, y) => if (x < y) y else x) + +val xs = List(1, 2, 3) +val _ = maximum(xs) +val _ = maximum(xs)(using descending) +val _ = maximum(xs)(using descending(using intOrd)) +``` + +This is an implementation of [SIP-64](https://github.com/scala/improvement-proposals/blob/db5cc6ab92758272f1a3528eacb46182ea216323/content/typeclasses-syntax.md). + +## Work on a better scheme for given prioritization + +Givens in Scala 3 have a peculiar problem with prioritization. The compiler tries to always select the instance with *the most specific subtype* of the requested type. This can lead to confusing situations, when user faces ambiguity errors in code that should intuitively work. Changing the scheme of given prioritization to always select the instance with *the most general subtype* that satisfies the context bound, would resolve such cases. We have conducted experiments that showed that the proposed scheme will result in a more intuitive and predictable given resolution. The negative impact on the existing projects is very small. We have tested 1500 open-source libraries, and new rules are causing problems for less than a dozen of them. We have already submitted PRs with changes that will make them work the same way under both the current and proposed rules. + +For the detailed motivation of changes with examples of code that will be easier to write and understand, see our recent blogpost - [Upcoming Changes to Givens in Scala 3.7](https://scala-lang.org/2024/08/19/given-priority-change-3.7.html). + +Our current plan is to introduce the new scheme in Scala 3.7. Starting from Scala 3.6, code whose behavior can differ between new and old rules (ambiguity on new, passing on old, or vice versa) will emit warnings, but the old rules will still be applied. 3.5 gives you a chance to detect if those changes affect your codebase. Running the compiler with `-source 3.6` will give you warnings; with `-source 3.7` or `-source future` you will get the new scheme. + +## What's next? + +There is already 3.5.1-RC2 published on Maven Central. This release contains multiple fixes and small improvements merged after we branched off the 3.5.0 to focus on polishing it. The release of the next version in the LTS line is coming soon. Scala 3.3.4-RC1 is available for testing. It contains all the forward and backward-compatible fixes available in Scala 3.5.0. + +## Contributors + +Thank you to all the contributors who made this release possible 🎉 + +According to `git shortlog -sn --no-merges 3.4.2..3.5.0` these are: + +``` + 153 Martin Odersky + 53 Eugene Flesselle + 41 Jamie Thompson + 29 Wojciech Mazur + 25 Nicolas Stucki + 22 Sébastien Doeraene + 18 noti0na1 + 16 Matt Bovel + 13 Guillaume Martres + 11 Paweł Marks + 10 Hamza REMMAL + 9 Yichen Xu + 8 Jan Chyb + 7 Hamza Remmal + 7 Som Snytt + 6 Jędrzej Rochala + 5 Fengyun Liu + 5 dependabot[bot] + 3 Mikołaj Fornal + 2 Aviv Keller + 2 EnzeXing + 1 Chris Pado + 1 Filip Zybała + 1 Georgi Krastev + 1 Jisoo Park + 1 Katarzyna Marek + 1 Lucas Nouguier + 1 Lucy Martin + 1 Ola Flisbäck + 1 Pascal Weisenburger + 1 Quentin Bernet + 1 Raphael Jolly + 1 Seth Tisue + 1 Stephane Bersier + 1 Tomasz Godzik + 1 Yoonjae Jeon + 1 aherlihy + 1 rochala + 1 willerf + +``` \ No newline at end of file diff --git a/resources/img/scala-3.5-launch.jpg b/resources/img/scala-3.5-launch.jpg new file mode 100644 index 000000000..fa3f9aa88 Binary files /dev/null and b/resources/img/scala-3.5-launch.jpg differ