Version 2.12.0, released Wednesday, features a complete overhaul of its compiler to take advantage of VM features in the Java upgrade, according to scala-lang.org. With Scala 2.12.0, a trait compiles directly to an interface with default methods, to improve binary compatibility and Java interoperability. And with Java 8 allowing concrete methods in interfaces, Scala 2.12.0 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,” scala-lang.org said. “Scala 2.12 is all about making optimal use of Java 8’s new features—and thus generates code that requires a Java 8 runtime.”
Additionally, Scala and Java 8 interop has been improved for functional code, with methods that take functions easily called in each direction via lambda syntax. “The FunctionN classes in Scala’s standard library are now SAM (Single Abstract Method) types and all SAM types are treated uniformly—from type-checking until code generation—no class file is generated for lambdas, and
invokedynamic is used instead.”
The new version also features a new bytecode optimizer. “The optimizer is configured using the
-opt compiler option. By default it only removes unreachable code within a method.” Dead code elimination and a number of cleanup optimizations are included as well.
Scala 2.12.1, which will rectify some issues with release 2.12.0, is coming later this month; scala-lang.org says it will clean up code and offer front-end fixes. A future release of Scala 2.12.x will address an issue in which parallel collections are prone to deadlock in the REPL and object initializers. From here on out, Scala 2.12.x releases will be fully binary compatible.