Scala 2.13.4:
- Restores default global
ExecutionContext
to 2.12 behavior
- Improves pattern matching, especially in exhaustivity checking
- Adds experimental support for consuming some libraries built by Scala 3
and more! Details below.
Concurrency
NOTE The following change affects parallelism and performance. If you use scala.concurrent.ExecutionContext.global
you may
want to adapt your code. (But note that Akka is unaffected, because it uses its own execution contexts.)
In 2.13.0 we made ExecutionContext.global
“opportunistic”. This enabled “batching” of nested tasks
to execute on the same thread, avoiding an expensive context switch. That strategy requires
user code to wrap long-running and/or blocking tasks with blocking { ... }
to maintain parallel
execution.
For 2.13.4, we restore 2.12’s default non-batching behavior, which is safer for arbitrary user code. Users wanting
increased performance may override the default, if they believe their code uses blocking
correctly.
We make that choice available via ExecutionContext.opportunistic
.
Using ExecutionContext.opportunistic
requires a bit of extra boilerplate, made necessary by binary
compatibility constraints on the standard library. Detailed instructions are in
ExecutionContext.global’s Scaladoc.
Further detail: #9270/#9296/scala/bug#12089,
Pattern matching
The pattern matcher is now much better at warning you if a match isn’t exhaustive.
The following types of matches no longer disable exhaustivity checking:
- guards (
case <pattern> if <condition> => ...
) #9140
- custom extractors (user-defined
unapply
or unapplySeq
) #9140/#9162
- unsealed types, if you opt in via
-Xlint
or -Xlint:strict-unsealed-patmat
#9140/#9299
Additionally,
- private classes are now treated as if sealed #9211
- singleton types no longer prematurely widen #9209
- tuples are handled properly #9147/#9163/#9147
New warnings reported can be resolved by:
- adding any missing cases
- in the case of complementary guards (e.g.
if n > 0
and if n <= 0
) by dropping the last guard
- for custom extractors: demarking irrefutable extractors as such, by defining the return type as
Some
- for sealed types: marking traits or parent classes sealed, parent classes abstract, and classes final
- explicitly declaring the default case:
case x => throw new MatchError(x)
Otherwise, your options for suppressing warnings include:
- annotate the scrutinee with
@unchecked
, such as (foo: @unchecked) match { ... }
- disable exhaustivity checking in the presence of guards and custom extractors with
-Xnon-strict-patmat-analysis
- disable exhaustivity checking of unsealed types with
-Xlint:-strict-unsealed-patmat
- use
-Wconf
to suppress the warnings globally, with e.g. -Wconf:msg=match may not be exhaustive:i
Scala 3 interop
This release enables the Scala 2 compiler to consume some libraries built in Scala 3. #9109/#9293
The new capability is experimental. To enable it, add -Ytasty-reader
to your compiler options.
Not all Scala 3 built libraries are supported, because not all Scala 3 features can be supported.
The library author must stay within the supported subset.
For more details and caveats see the blog post Forward Compatibility for the Scala 3 Transition.
Standard library changes
- When compiling on JDK 15, avoid clash with new
CharSequence#isEmpty
method #9292
- The clash is avoided by making
CharSequence
wrappers in Predef
non-implicit.
- The change is binary compatible, but not source compatible. Call sites may need updating.
- Make
LazyList.cons.apply
lazier #9095
- Make
MapView#values
preserve laziness #9090
- Make
ListBuffer
's iterator fail when the buffer is mutated #9174
- Un-deprecate useful
StringOps
methods, despite Unicode concerns #9246
Compiler changes
- Allow using
classOf
with object type (e.g. classOf[Foo.type]
) #9279
- Fix back-quoted constructor params with identical prefixes #9008
- Enable range positions (
-Yrangepos
) by default #9146
Compatibility
As usual for our minor releases, Scala 2.13.4 is binary-compatible with the whole Scala 2.13 series.
Upgrading from 2.12? Enable -Xmigration
while upgrading to request migration advice from the compiler.
Contributors
A big thank you to everyone who’s helped improve Scala by reporting bugs, improving our documentation, spreading kindness in discussions around Scala, and submitting and reviewing pull requests! You are all magnificent.
This release was brought to you by 40 contributors, according to git shortlog -sn --no-merges HEAD ^v2.13.3 ^2.12.x
. Thank you Jamie Thompson, Dale Wijnand, A. P. Marki, NthPortal, Lukas Rytz, Seth Tisue, Jason Zaugg, Georgi Krastev, Eugene Yokota, Martijn Hoekstra, Trey Cahill, Rado Buransky, Ergys Dona, Mike Skells, Greg Pfeil, Kazuhiro Sera, Mitsuhiro Shibuya, NagaChaitanya Vellanki, Sergei Petunin, Sébastien Doeraene, Takahashi Osamu, Viktor Klang, mwielocha, Nicolas Stucki, Jan Arne Sparka, Philippus Baalman, Glenn Liwanag, Rafał Sumisławski, Renato Cavalcanti, Sergei, nooberfsh, Dmitrii Naumenko, Simão Martins, counter2015, Jian Lan, Liu Fengyun, Kanishka, Julien Richard-Foy, Janek Bogucki, Björn Regnell.
Thanks to Lightbend for their continued sponsorship of the Scala core team’s efforts. Lightbend offers commercial support for Scala.
Scala 2.13 notes
The release notes for Scala 2.13.0 have important information applicable to the whole 2.13 series.
Obtaining Scala
Scala releases are available through a variety of channels, including (but not limited to):