Skip to content

Releases: scala/scala

Scala 2.13.0-M2

29 Jul 01:13
v2.13.0-M2
Compare
Choose a tag to compare
Scala 2.13.0-M2 Pre-release
Pre-release

This Scala 2.13 milestone contains only a few big changes. The main goal is to catch up with the changes in 2.12.3.

Release highlights

Significant changes since 2.13.0-M1:

  • #5903: The REPL is undergoing renovations in 2.13 for better positioning of errors, a cleaner internal implementation, multi-line editing and syntax highlighting. Some parts of this are available in M1.

Note that the planned and previously announced changes to the handling of lazy right-associative operators have been postponed to 2.13.0-M3, pending SIP approval.

For more information, check out all closed bugs and merged PRs.

2.13.0-M2 also includes all the 2.12.3 changes.

Overview of the 2.13 series

Scala 2.13 will focus on cleaning up and improving the standard library, and on improving the performance of the compiler. The Scala 2.13 roadmap is available on GitHub for review.

An overhaul of the collections library is being worked on in a separate repository.

Like Scala 2.12, the 2.13 series targets Java 8.

This release is not binary compatible with the 2.12.x series, to allow us to keep improving the Scala standard library.

Libraries

We are working with the community to ensure availability of core projects for the Scala 2.13 ecosystem. We maintain an up-to-date list of available libraries.

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.

According to git shortlog -sn --no-merges v2.13.0-M1..v2.13.0-M2, 32 people contributed to this release: Jason Zaugg, Lukas Rytz, Adriaan Moors, A. P. Marki, Janek Bogucki, Dale Wijnand, Seth Tisue, Kenji Yoshida, Earl St Sauver, Eugene Yokota, Miles Sabin, Jasper Moeys, Iulian Dragos, Mike Skells, Stefan Zeiger, 杨博 (Yang Bo), Rui Gonçalves, Cody Allen, Harrison Houghton, Adrien Suree, Vladimir Parfinenko, chengpohi, joymufeng, NthPortal, Edmund Noble, BrianLondon, Arnout Engelen, Masaru Nomura, Ganesh Prasad Kumble, Oscar Boykin, Rory Graves, Sayyed, Atiq (Agoda). Thank you!

Reporting bugs

Please file any bugs you encounter on our issue tracker.

Obtaining Scala

Scala releases are available through a variety of channels, including (but not limited to):

Scala 2.13.0-M1

18 Apr 14:49
v2.13.0-M1
Compare
Choose a tag to compare
Scala 2.13.0-M1 Pre-release
Pre-release

This first Scala 2.13 milestone contains only a few changes. Its main goal is to bootstrap the 2.13 release infrastructure. It also begins further modularization of the standard library.

Release highlights

Significant changes since 2.12.2 include:

  • #5603: The parallel collections are now a separate module. There are instructions on the linked page for adding the dependency to your build.
  • #5790: The following modules are no longer included in the distribution: scala-swing, scala-parser-combinators. (They remain available from Maven Central.) We also no longer build or publish scala-library-all.jar.
  • #5683: Remove deprecated stuff from Predef, scala._, scala.runtime
  • #5698: Eliminate non-matching overloads early for partial function literals
  • #5548: Added Java 1.6. and 1.8 java.lang.Math methods into scala.math package (scala/bug#9813)
  • #5830: A number of internal dependencies were cut to prepare for the creation of additional modules. (see also scala/scala-dev#323)

For more information, check out all closed bugs and merged PRs.

2.13.0-M1 also includes all the 2.11.11 changes and all the 2.12.2 changes.

Overview of the 2.13 series

Scala 2.13 will focus on cleaning up and improving the standard library, and on improving the performance of the compiler. The Scala 2.13 roadmap is available on GitHub for review.

An overhaul of the collections library is being worked on in a separate repository.

Like Scala 2.12, the 2.13 series targets Java 8.

This release is not binary compatible with the 2.12.x series, to allow us to keep improving the Scala standard library.

Libraries

We are working with the community to ensure availability of core projects for the Scala 2.13 ecosystem. We maintain an up-to-date list of available libraries.

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.

According to git shortlog -sn --no-merges 2.12.x..v2.13.0-M1, 13 people contributed to this release: Seth Tisue, Adriaan Moors, Lukas Rytz, Janek Bogucki, Stefan Zeiger, Kenji Yoshida, A. P. Marki, Zizheng Tai, Faiz Halde, Masaru Nomura, Pap Lőrinc, Pavel Petlinsky, Sébastien Doeraene. Thank you!

Reporting bugs

Please file any bugs you encounter on our issue tracker.

Obtaining Scala

Scala releases are available through a variety of channels, including (but not limited to):

Scala 2.12.2

18 Apr 14:32
v2.12.2
Compare
Choose a tag to compare

Scala 2.12.2 includes support for trailing commas, the first proposal (SIP-27) to make it all the way through the revived Scala Improvement Process. Congratulations, @dwijnand!

Changes

Significant changes since 2.12.1 include:

  • #5245 Allow trailing commas before newlines (SIP-27)
  • #5402 Improve unused warnings
    • note: these changes are included under -Xlint unless explicitly excluded with -Xlint:-unused,_
  • #5589 Types with symbolic names print in infix by default
  • #5724 Support direct-dependency-only compilation (Scala Center Proposal SCP-009)
  • #5816 Allow user-defined [un]apply in case companion
  • #5667 -Xmaxerrs to limit compiler messages
  • #5592 Don't keep JarFile open in ZipArchive (with -Dscala.classpath.closeZip=true)
  • #5659 Fix endless cycle in runtime reflection
  • #5602 Modules w. serializable type alias "companions" are not serializable
  • #5550 Fix detection of term-owned companions
  • #5663 Enable colored output by default on Unix
  • #5625 Bundle newer scala-parser-combinators (1.0.5)

For more information, check out all closed bugs and merged PRs.

2.12.2 also includes all the 2.11.11 changes, including these especially notable ones:

  • #5730, #5846 Allow custom apply and unapply methods in case class companions. Also allows case class constructors and apply methods to be private.
  • #5343 Add support for higher order unification under -Ypartial-unification (SI-2712)
  • #5341 Fix for higher-kinded GADT refinement

As usual for minor releases, Scala 2.12.2 is binary compatible with the whole Scala 2.12 series.

To share your feedback on this release, please use our new GitHub-based bug tracker and Discourse-based contributors forum.

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 48 contributors, according to git shortlog -sn --no-merges v2.12.1..v2.12.2. Thank you A. P. Marki, Jason Zaugg, Adriaan Moors, Seth Tisue, Lukas Rytz, Pap Lőrinc, Philippus Baalman, Rory Graves, Dale Wijnand, Janek Bogucki, Iulian Dragos, Stefan Zeiger, Johannes Rudolph, Edmund Noble, Lars Hupel, Masaru Nomura, allisonhb, jvican, Sébastien Doeraene, Mike Skells, Antoine Gourlay, Aaron S. Hawley, Viktor Klang, Vlad Ureche, piyush-jaiswal, ptrcarta, teldosas, wpopielarski, Alessandro Cifani, Alexey Romanov, Ben Hutchison, Carsten Varming, Evgeny Slutsky, Hao Xia, Jasper-M, Jon Pretty, Kenji Yoshida, Markus Jura, Martijn Hoekstra, Martynas Mickevičius, Miles Sabin, Oscar Boykin, Pablo Fco. Pérez Hidalgo, Paul Phillips, Rui Gonçalves, Sam Halliday, Tamer Mohammed Abdul-Radi, and Tobias Schlatter!

Scala 2.12 Notes

The release notes for Scala 2.12.0 have important information applicable to the whole 2.12 series.

Obtaining Scala

Scala releases are available through a variety of channels, including (but not limited to):

Scala 2.11.11: all the way to eleven!

18 Apr 14:32
v2.11.11
Compare
Choose a tag to compare

The 2.11.11 release concludes the 2.11.x series, with no further releases planned. Please consider upgrading to 2.12!

Do not use 2.11.9 or 2.11.10, which introduced significant regressions (see below). This also means this series goes to eleven. (No further, though.)

Changes

Significant changes since 2.11.8 include:

  • #5730, #5846 Allow custom apply and unapply methods in case class companions. Also allows case class constructors and apply methods to be private. (In 2.11.11, -Xsource:2.12 is needed to enable these changes. In Scala 2.12.2, they are on by default.)
  • #5343 Add support for higher order unification under -Ypartial-unification (SI-2712)
  • #5341 Fix for higher-kinded GADT refinement
  • #5061 JMH-based benchmark framework for contributors
  • #5026 Upgrade to newer scala-xml (1.0.5)

2.11.11 resolves regressions introduced in 2.11.9 and 2.11.10: #5730 (fixed by #5828 and #5846), #5664 (fixed by #5821). Special thanks to @xuwei-k and @sjrd for reporting and helping diagnose these.

For more information, check out all closed bugs and merged PRs.

As usual for minor releases, Scala 2.11.11 is binary compatible with the whole Scala 2.11 series (with the exception of 2.11.9, which should not be used to publish artifacts, see #5821).

To share your feedback on this release, please use our new GitHub-based bug tracker and Discourse-based contributors forum.

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 33 contributors, according to git shortlog -sn --no-merges v2.11.8..v2.11.11. Thank you Adriaan Moors, A. P. Marki, Jason Zaugg, Seth Tisue, Lukas Rytz, Performant Data LLC, Stefan Zeiger, Pap Lőrinc, Iulian Dragos, Rory Graves, Miles Sabin, Martijn Hoekstra, Mike Skells, Sébastien Doeraene, Dale Wijnand, Raphael Jolly, ptrcarta, Łukasz Gieroń, Carsten Varming, CodingTwinky, Jasper-M, Johannes Rudolph, Krzysztof Romanowski, Martynas Mickevičius, Masaru Nomura, Nicolas Stucki, Oscar Boykin, Paul Kernfeld, Philippus Baalman, Tobias Schlatter, Viktor Klang, af, and jvican!

Scala 2.11 Notes

The release notes for Scala 2.11.0 have important information applicable to the whole 2.11 series.

Obtaining Scala

Scala releases are available through a variety of channels, including (but not limited to):

[Do not use] Scala 2.11.10, please upgrade to 2.11.11

13 Apr 00:17
v2.11.10
Compare
Choose a tag to compare

Not suitable for use due to a regression caused by #5730, fixed in 2.11.11 by #5846.

[Do not use] Scala 2.11.9, please upgrade to 2.11.11

13 Apr 00:16
v2.11.9
Compare
Choose a tag to compare

This release contains a binary incompatible change introduce by #5664 and fixed by the reversion in #5821, which is available in 2.11.11 (yes, 2.11.10 was also flawed).

Scala 2.12.1

05 Dec 20:29
v2.12.1
Compare
Choose a tag to compare

We are pleased to announce the availability of Scala 2.12.1!

Changes

Significant changes since 2.12.0 include:

  • #5516 Improved runtime speed for Vector, restoring previous performance
  • #5509 SI-10032 Fix code gen with returns in nested try-finally blocks
  • #5482 Fix 2.12 regression, backend crash: Cannot create ClassBType from non-class symbol; also fix SI-7139
  • #5469 SI-10020 SI-10027 Scaladoc: keep Java comment scanning stack-friendly
  • #5376 Make -Xexperimental features available separately
  • #5284 SI-7046 partial fix to knownDirectSubclasses for reflection users and macro authors
  • #5410 Upgrade to scala-xml 1.0.6

In total, this release resolves 28 issues. We merged 88 pull requests.

As usual for minor releases, Scala 2.12.1 is binary compatible with the whole Scala 2.12 series.

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.

According to git shortlog -sn --no-merges v2.12.0..v2.12.1, 28 people contributed to this minor release: A. P. Marki, Jason Zaugg, Lukas Rytz, Seth Tisue, Adriaan Moors, Stefan Zeiger, Dale Wijnand, Miles Sabin, Daniel Barclay, Pap Lőrinc, Iulian Dragos, Rex Kerr, Sakthipriyan Vairamani, Kenji Yoshida, Jakob Odersky, Mohit Agarwal, Paul Kernfeld, Pavel Petlinsky, Boris Korogvich, Sébastien Doeraene, Tim Spence, Viktor Klang, Vladimir Glushak, Chris Okasaki, Lifu Huang, Janek Bogucki, Martijn Hoekstra, Masaru Nomura.

Scala 2.12 Notes

The release notes for Scala 2.12.0 have important information applicable to the whole 2.12 series.

Obtaining Scala

Scala releases are available through a variety of channels, including (but not limited to):

Scala 2.12.0

03 Nov 00:33
v2.12.0
Compare
Choose a tag to compare

Headline features

The Scala 2.12 compiler has been completely overhauled to make use of the new VM features available in Java 8:

  • A trait compiles directly to an interface with default methods. This improves binary compatibility and Java interoperability.
  • Scala and Java 8 interop is also improved for functional code, as methods that take functions can easily be called in both directions using lambda syntax. The FunctionN classes in Scala's standard library are now Single Abstract Method (SAM) types, and all SAM types are treated uniformly -- from type checking through code generation. No class file is generated for a lambda; invokedynamic is used instead.

This release ships with a powerful new optimizer:

  • Inlining: many more (effectively) final methods, including those defined in objects and traits, are now inlined.
  • Closure allocations, dead code, and box/unbox pairs are eliminated more often.

For additional features, read on.

Compatibility

Although Scala 2.11 and 2.12 are mostly source compatible to facilitate cross-building, they are not binary compatible. This allows us to keep improving the Scala compiler and standard library.

All 2.12.x releases will be fully binary compatible with 2.12.0, in according with the policy we have followed since 2.10.

The list of open-source libraries released for Scala 2.12 is growing quickly!

This release is identical to 2.12.0-RC2.

Coming soon

Our roadmap lists the following upcoming releases for 2016:

  • 2.12.1 will be out shortly (by the end of November) to address some known (but rare) issues in 2.12.0.
  • 2.11.9 will be the last planned 2.11.x release (due by mid December)

In the next few weeks, we at Lightbend will share our plans for Scala 2.13.

Known issues

There are some known issues with this release that will be resolved in 2.12.1, due later in November.

The heavy use of default methods for compiling traits caused some performance regressions in the startup time of Scala applications. Note that steady-state performance is not affected according to our measurements.

The regression was mitigated 2.12.0-RC2 (and the final release) by generating forwarder methods in classes that inherit concrete methods from traits, which unfortunately increases bytecode size while improving JVM startup performance.

Please let us know if you notice any performance regressions. We will continue to tweak the bytecode during the 2.12.x cycle to get the best performance out of the JVM.

We hope to address the following in a later 2.12.x release:

  • SI-9824: Parallel collections are prone to deadlock in the REPL and in object initializers.

Obtaining Scala

Java 8 runtime

Install a recent build of the Java 8 Platform, such as OpenJDK or Oracle Java. Any Java 8 compliant runtime will do (but note that Oracle versions before 8u102 have a known issue that affects Scala).

We are planning to add (some) support for Java 9 in the near future. Full Java 9 support will be part of the 2.13 roadmap discussions.

Build tool

We recommend using sbt 0.13.13. Simply bump the scalaVersion setting in your existing project, or start a new project using sbt new scala/scala-seed.g8. We strongly recommend upgrading to sbt 0.13.13 for templating support using the new command, faster compilation, and much more.

Please head over to the scala-seed repo to extend this giter8 template with an example of your favorite 2.12 feature!

Scala also works with Maven, Gradle, and Ant.

You can also download a distribution from scala-lang.org, or obtain the JARs yourself from Maven Central.

Contributors

A big thank you to everyone who's helped improve Scala by reporting bugs, improving our documentation, kindly helping others on forums and at meetups, and submitting and reviewing pull requests! You are all magnificent.

Scala 2.12.0 is the result of merging over 500 pull requests out of about 600 received PRs. The contributions to 2.12.x over the last 2 years were split 64/32/4 between the Scala team at Lightbend (lrytz, retronym, adriaanm, SethTisue, szeiger), the community, and EPFL.

The new encodings of traits, lambdas, and lazy vals were developed in fruitful collaboration with the Dotty team at EPFL.

The new compiler back end and the new optimizer are based on earlier work by Miguel Garcia at EPFL.

Scala 2.12 overview

Scala 2.12 is all about making optimal use of Java 8's new features. Thus, it generates code that requires a Java 8 runtime.

  • Traits (#5003) and functions are compiled to their Java 8 equivalents. The compiler no longer generates trait implementation classes (T$class.class) and anonymous function classes (C$$anonfun$1.class).
  • We treat Single Abstract Method types and Scala's built-in function types uniformly from type checking to the back end (#4971).
  • We use invokedynamic for compiling functions. It also now provides a more natural encoding of other language features (#4896).
  • We've standardized on the GenBCode back end (#4814, #4838) and the flat classpath implementation is now the default (#5057).
  • The optimizer has been completely overhauled for 2.12.

The new encodings for traits and lambdas lead to significantly smaller JAR files. For example, for ScalaTest 3.0.0, the jar size dropped from 9.9M to 6.7M.

Except for the breaking changes listed below, code that compiles on 2.11.x without deprecation warnings should compile on 2.12.x, unless you use experimental APIs such as reflection. If you find incompatibilities that are not listed below, please file an issue.

Thanks to source compatibility, cross-building is a one-line change to most sbt builds. Where needed, sbt provides support for version-specific source folders out of the box.

New language features

The next sections introduce new features and breaking changes in Scala 2.12 in more detail. To understand more technicalities and review past discussions, you can also take a look at the full list of noteworthy pull request that went into this release.

Traits compile to interfaces

Because Java 8 allows concrete methods in interfaces, Scala 2.12 is able to compile a trait to a single interface classfile. Before, a trait was represented as an interface and a class that held the method implementations (T$class.class).

Additional magic is still involved, so care must be taken if a trait is meant to be implemented in Java. Briefly, if a trait does any of the following, its subclasses require synthetic code:

  • defining fields (val or var, but a constant is ok -- final val without result type)
  • calling super
  • initializer statements in the body
  • extending a class
  • relying on linearization to find implementations in the right supertrait

Lambda syntax for SAM types

The Scala 2.12 type checker accepts a function literal as a valid expression for any Single Abstract Method (SAM) type, in addition to the FunctionN types from standard library. This improves the experience of using libraries written for Java 8 from Scala code. Here is a REPL example using java.lang.Runnable:

scala> val r: Runnable = () => println("Run!")
r: Runnable = $$Lambda$1073/754978432@7cf283e1

scala> r.run()
Run!

Note that only lambda expressions are converted to SAM type instances, not arbitrary expressions of FunctionN type:

scala> val f = () => println("Faster!")

scala> val fasterRunnable: Runnable = f
<console>:12: error: type mismatch;
 found   : () => Unit
 required: Runnable

The language specification has the [full list of requirements for SAM conversion](http://www.scala-lang.org/files/archive/spec/2.12/06-expressions.ht...

Read more

Scala 2.12.0-RC2

18 Oct 19:00
v2.12.0-RC2
Compare
Choose a tag to compare
Scala 2.12.0-RC2 Pre-release
Pre-release

We are happy to announce the availability of Scala 2.12.0-RC2!

This RC fixes all reported regressions since 2.11.
It will become the final by October 28th, unless we hear of any issues that block your upgrade to 2.12 before then!

Here are the most noteworthy fixes since RC1:

  • #5429 Default -Xmixin-force-forwarders to true (regression in performance of generated code);
  • #5398 SD-225 Use a lzycompute method for module initialization. Address a performance regression;
  • #5417 SD-233 synchronized blocks are JIT-friendly again;
  • #5433 Don't deprecate Either.left and Either.right yet;
  • #5392 SI-9918 Don't crash on object in trait mixed into package object;
  • #5397 SI-9920 Avoid linkage errors with captured local objects + self types;
  • #5430 Emit object in method like lazy val;
  • #5442 SI-9943 sealed class does not yield SAM type;

The RC1 release notes have a list of important changes since M5.

In total, we merged 29 pull requests.
This milestone resolves 6 JIRA tickets and 9 scala-dev issues.

As usual for Scala pre-releases, 2.12.0-RC2 is not guaranteed to be binary compatible with any other Scala version, including any 2.12 milestones and release candidates.

Known issues

As with previous 2.12 builds, the new trait encoding may make some trait-based code run slower. We've investigated this issue in depth, and have implemented important improvements in RC2. Compile times may still be longer in 2.12 than 2.11. Please let us know if you notice any performance regressions. We will continue to tweak the bytecode we emit during the 2.12.x cycle to get the best performance out of the JVM.

We welcome feedback from the Scala community helping to isolate unusual slowdowns.

We hope to address the following in a future 2.12.x release:

  • SI-9824:
    Parallel collections are prone to deadlock in the REPL and in object initializers.

Scala 2.12

Scala 2.12 requires a Java 8 runtime.

Scala 2.12 is all about making optimal use of Java 8's new features. Traits (#5003) and functions are compiled to their Java 8 equivalents, and we treat Single Abstract Method types and Scala's builtin function types uniformly from type checking to the back end (#4971). We also use invokedynamic for a more natural encoding of other language features (#4896). We've standardized on the GenBCode back end (#4814, #4838) and the flat classpath implementation is now the default (#5057). The optimizer has been completely overhauled for 2.12.

Except for the breaking changes listed below, code that compiles on 2.11.x without deprecation warnings should compile on 2.12.x too, unless you use experimental APIs such as reflection. If you find incompatibilities, please file an issue.

New features

With this release candidate, we consider 2.12.x to be feature complete.

For 2.12.0, we will try to remain binary compatible with RC1, and we won't risk regressions except for the most critical bugs.

Trait compiles to an interface

With Java 8 allowing concrete methods in interfaces, Scala 2.12 is able to compile a trait to a single interface. Before, a trait was represented as a class that held the method implementations and an interface. Note that the compiler still has quite a bit of magic to perform behind the scenes, so that care must be taken if a trait is meant to be implemented in Java. (Briefly, if a trait does any of the following its subclasses require synthetic code: defining fields, calling super, initializer statements in the body, extending a class, relying on linearization to find implementations in the right super trait.)

Java 8-style lambdas

Scala 2.12 emits closures in the same style as Java 8, whether they target a FunctionN class from the standard library or a user-defined Single Abstract Method (SAM) type. The type checker accepts a function literal as a valid expression for either kind of "function-like" type (built-in or SAM). This improves the experience of using libraries written for Java 8 in Scala.

For each lambda the compiler generates a method containing the lambda body, and emits an invokedynamic that will spin up a lightweight class for this closure using the JDK's LambdaMetaFactory.

Compared to Scala 2.11, the new scheme has the advantage that, in most cases, the compiler does not need to generate an anonymous class for each closure. This leads to significantly smaller JAR files.

New back end

Scala 2.12 standardizes on the "GenBCode" back end, which emits code more quickly because it directly generates ASM bytecode from Scala compiler trees, while the previous back end used an intermediate representation called "ICode". The old back ends (GenASM and GenIcode) have been removed (#4814, #4838).

New optimizer

The GenBCode back end includes a new inliner and bytecode optimizer. The optimizer is enabled using -opt compiler option, which defaults to -opt:l:classpath. Check -opt:help to see the full list of available options for the optimizer.

The following optimizations are available:

  • Inlining final methods, including methods defined in objects and final methods defined in traits
  • If a closure is allocated and invoked within the same method, the closure invocation is replaced by an invocations of the corresponding lambda body method
  • Dead code elimination and a small number of cleanup optimizations
  • Box/unbox elimination #4858

Either is now right-biased

Either now supports operations like map, flatMap, contains,
toOption, and so forth, which operate on the right-hand side. (.left and .right may be deprecated in favor of .swap in a later release.)

The changes are source-compatible with old code (except in the presence of conflicting extension methods). Thanks, Simon Ochsenreither, for this contribution.

Futures improved

This blog post series by Viktor Klang explores the diverse improvements made to scala.concurrent.Future for 2.12.

Scaladoc now supports doc comments in Java sources

Thanks, Jakob Odersky, for this fix to SI-4826.

Partial unification of type constructors (SI-2712)

Compiling with -Ypartial-unification adds partial unification of type constructors, fixing the notorious SI-2712, thanks to Miles Sabin.

Breaking changes

SAM types

Implicit conversion of function types to SAM types won't kick in as often now, since the compiler's own SAM conversion takes priority:

trait MySam { def apply(x: Int): String }
implicit def unused(fun: Int => String): MySam =
  new MySam { def apply(x: Int) = fun(x) }
// uses SAM conversion, not the `unused` implicit
val sammy: MySam = (_: Int).toString

To retain the old behavior, you may compile under -Xsource:2.11, or disqualify the type from being a SAM (e.g. by adding a second abstract method).

Inferred types for val (and lazy val)

#5141 and #5294 align type inference for def, val, and lazy val, fixing assorted corner cases and inconsistencies. As a result, the inferred type of a val or lazy val may change.

In particular, implicit vals that didn't need explicitly declared types before may need them now. (This is always good practice anyway.)

You can get the old behavior with -Xsource:2.11. This may be useful for testing whether these changes are responsible if your code fails to compile.

Changed syntax trees (affects macro and compiler plugin authors)

PR #4794 changed the syntax trees for selections of statically accessible symbols. For example, a selection of Predef no longer has the shape q"scala.this.Predef" but simply q"scala.Predef". Macros and compiler plugins matching on the old tree shape need to be adjusted.

Binary compatibility

Since Scala 2.11, minor releases of Scala are binary compatible with each other.
Scala 2.12 will continue this tradition: every 2.12.x release will be binary compatible with 2.12.0.
Milestones and release candidates, however, are not binary compatible with any other release.

Scala 2.12 is not and will not be binary compatible with the ...

Read more

Scala 2.12.0-RC1

13 Sep 23:36
v2.12.0-RC1
Compare
Choose a tag to compare
Scala 2.12.0-RC1 Pre-release
Pre-release

We are happy to announce the availability of Scala 2.12.0-RC1!

Note, however, that Scala 2.12.0-RC2 will follow, due to known regressions detailed below.

The most notable changes since M5 are:

  • #5135: Either is now right-biased
  • SI-4826: Scaladoc now supports doc comments in Java sources
  • SI-7187: Eta-expansion of zero-argument method values is now deprecated
  • #5307: Reduced interference from SAMs when inferring function types in the presence of overload
  • #5141 / #5294: Refactoring of def, val, and lazy val handling, fixing assorted corner cases and inconsistencies
  • #5311: Scala is now built with sbt instead of Ant (affects only contributors, not users)

In total, we merged 82 pull requests, of which 6 are by new contributors -- welcome! This milestone resolves 25 JIRA tickets.

As usual for Scala pre-releases, 2.12.0-RC1 is not binary compatible with any other Scala version, including any 2.12 milestones.

Known issues

As with previous 2.12 builds, the new trait encoding may make some trait-based code run slower. As a result, compile times may also be longer in 2.12 than 2.11. We welcome feedback from the Scala community helping to isolate unusual slowdowns.

The following known regressions will be fixed in 2.12.0-RC2:

  • SD-225 may cause drastically longer compile times for certain kinds of code.
  • SI-9918 may cause scala.reflect.internal.Types$TypeErrors in code involving package objects.
  • SI-9920 may cause java.lang.NoSuchMethodErrors at runtime.
  • A regression may cause java.util.NoSuchElementExceptions in scala.tools.nsc.backend.jvm.BCodeSkelBuilder; see #5395.

Because of the last-mentioned regression, Shapeless will not be
published for 2.12.0-RC1.

We hope to address the following in a future 2.12.x release:

  • SI-9824: Parallel collections are prone to deadlock in the REPL and in object initializers.

Scala 2.12

Scala 2.12 requires a Java 8 runtime.

Scala 2.12 is all about making optimal use of Java 8's new features. Traits (#5003) and functions are compiled to their Java 8 equivalents, and we treat Single Abstract Method types and Scala's builtin function types uniformly from type checking to the back end (#4971). We also use invokedynamic for a more natural encoding of other language features (#4896). We've standardized on the GenBCode back end (#4814, #4838) and the flat classpath implementation is now the default (#5057). The optimizer has been completely overhauled for 2.12.

Except for the breaking changes listed below, code that compiles on 2.11.x without deprecation warnings should compile on 2.12.x too, unless you use experimental APIs such as reflection. If you find incompatibilities, please file an issue.

New features

With this release candidate, we consider 2.12.x to be feature complete.

For 2.12.0, we will try to remain binary compatible with RC1, and we won't risk regressions except for the most critical bugs.

Trait compiles to an interface

With Java 8 allowing concrete methods in interfaces, Scala 2.12 is able to compile a trait to a single interface. Before, a trait was represented as a class that held the method implementations and an interface. Note that the compiler still has quite a bit of magic to perform behind the scenes, so that care must be taken if a trait is meant to be implemented in Java. (Briefly, if a trait does any of the following its subclasses require synthetic code: defining fields, calling super, initializer statements in the body, extending a class, relying on linearization to find implementations in the right super trait.)

Java 8-style lambdas

Scala 2.12 emits closures in the same style as Java 8, whether they target a FunctionN class from the standard library or a user-defined Single Abstract Method type. The type checker accepts a function literal as a valid expression for either kind of "function-like" type (built-in or SAM). This improves the experience of using libraries written for Java 8 in Scala.

For each lambda the compiler generates a method containing the lambda body, and emits an invokedynamic that will spin up a lightweight class for this closure using the JDK's LambdaMetaFactory.

Compared to Scala 2.11, the new scheme has the advantage that, in most cases, the compiler does not need to generate an anonymous class for each closure. This leads to significantly smaller JAR files.

New back end

Scala 2.12 standardizes on the "GenBCode" back end, which emits code more quickly because it directly generates ASM bytecode from Scala compiler trees, while the previous back end used an intermediate representation called "ICode". The old back ends (GenASM and GenIcode) have been removed (#4814, #4838).

New optimizer

The GenBCode back end includes a new inliner and bytecode optimizer. The optimizer is enabled using -opt compiler option, which defaults to -opt:l:classpath. Check -opt:help to see the full list of available options for the optimizer.

The following optimizations are available:

  • Inlining final methods, including methods defined in objects and final methods defined in traits
  • If a closure is allocated and invoked within the same method, the closure invocation is replaced by an invocations of the corresponding lambda body method
  • Dead code elimination and a small number of cleanup optimizations
  • Box/unbox elimination #4858

Either is now right-biased

Either now supports operations like map, flatMap, contains, toOption, and so forth, which operate on the right-hand side.

.left and .right are deprecated in favor of .swap.

The changes are source-compatible with old code (except in the presence of conflicting extension methods).

Thanks, Simon Ochsenreither, for this contribution.

Futures improved

This blog post series by Viktor Klang explores the diverse improvements made to scala.concurrent.Future for 2.12.

Scaladoc now supports doc comments in Java sources

Thanks, Jakob Odersky, for this fix to SI-4826.

Partial unification of type constructors (SI-2712)

Compiling with -Ypartial-unification adds partial unification of type constructors, fixing the notorious SI-2712, thanks to Miles Sabin.

Breaking changes

SAM types

As of #4971, we treat Single Abstract Method types in the same way as our built-in FunctionN classes. This means overloading resolution has more contenders to choose from, making type inference less effective. Here's an example:

class C[V] {
  def sort(cmp: java.util.Comparator[V]): C[V] = ???
  def sort(cmp: (V, V) => Int): C[V] = sort(
    new java.util.Comparator[V] {
      def compare(a: V, b: V): Int = cmp(a, b)
    })
}

(new C[Int]) sort (_ - _) // error
(new C[Int]) sort ((_ - _): java.util.Comparator[Int]) // ok
(new C[Int]) sort ((a: Int, b: Int) => a - b)  // ok

The first attempt fails because the type checker cannot infer the types for _ - _'s arguments anymore.
Type inference in this scenario only works when we can narrow the overloads down to one before type checking the arguments the methods are applied to. When a function is passed as an argument to an overloaded method, we do this by considering the "shape" of the function (essentially, its arity). Now that Comparator[?] and (?, ?) => ? are both considered functions of arity two, our clever scheme breaks down and the programmer must either select an overload (second application) or make the argument types explicit (last application, which resolves to the Function2 overload).

Finally, implicit conversion of SAM types to Function types won't kick in anymore, since the compiler does this conversion itself first:

trait MySam { def apply(x: Int): String }

implicit def unused(fun: Int => String): MySam
  = new MySam { def apply(x: Int) = fun(x) }

// uses sam conversion, not the `unused` implicit
val sammy: MySam = _.toString

Inferred types for val (and lazy val)

#5141 and #5294 align type inference for def, val, and lazy val, fixing assorted corner cases and inconsistencies. As a result, the inferred type of a val or lazy val may change.

In particular, implicit vals that didn't need explicitly ...

Read more