You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are happy to announce the availability of Scala 2.12.0!
2
2
3
3
The Scala 2.12 compiler has been completely overhauled to make use of the new VM features available in Java 8!
4
-
5
-
- A trait is compiled to an interface with default methods for improved binary compatibility.
4
+
- A trait is compiled directly to an interface with default methods for improved binary compatibility.
6
5
- Lambda syntax can now be used to create instances of types with a single abstract method (SAM types). Scala code can seamlessly use libraries with higher-order functions written in Java 8, and vice versa.
7
6
- Code generation for function literals uses `invokedynamic` to avoid emitting a classfile at compile time, just like Java 8.
8
7
9
-
This release ships with a powerful new optimizer. Many more (effectively) final methods, including those defined in objects and traits, are now inlined. As well, closure allocations, dead code and [box/unbox pairs](https://github.com/scala/scala/pull/4858) are eliminated more effectively.
8
+
This release ships with a powerful new optimizer. Many more (effectively) final methods, including those defined in objects and traits, are now inlined. As well, closure allocations, dead code and [box/unbox pairs](https://github.com/scala/scala/pull/4858) are eliminated more effectively.
10
9
11
-
From now on, 2.12.x releases will be fully binary compatible. This release is identical to 2.12.0-RC2. To run Scala 2.12 code, you need a Java 8 runtime.
10
+
From now on, 2.12.x releases will be fully binary compatible. This release is identical to 2.12.0-RC2.
12
11
13
12
Our [roadmap](https://github.com/scala/scala/milestones) 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, and 2.11.9 is 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.
14
13
15
14
16
-
###Known issues
15
+
## Known issues
17
16
There are some [known issues](https://issues.scala-lang.org/browse/SI-10009?jql=project%20%3D%20SI%20AND%20affectedVersion%20%3D%20%22Scala%202.12.0%22) with this release that [will be resolved](https://github.com/scala/scala/pulls?q=is%3Apr+milestone%3A2.12.1+label%3Arelease-notes) in 2.12.1, due by the end of November.
18
17
19
18
The heavy use of default methods for compiling traits caused some performance regressions in the
@@ -31,7 +30,38 @@ We hope to address the following in a future 2.12.x release:
31
30
32
31
-[SI-9824](https://issues.scala-lang.org/browse/SI-9824): Parallel collections are prone to deadlock in the REPL and in object initializers.
33
32
34
-
## Scala 2.12
33
+
## Obtaining Scala
34
+
### Java 8 runtime
35
+
Install a recent build of the Java 8 Platform, from [OpenJDK](http://openjdk.java.net/install/) or [Oracle](http://www.oracle.com/technetwork/java/javase/downloads/index.html). Any Java 8 compliant run-time will do.
36
+
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.
37
+
38
+
### Build tool
39
+
We recommend using [sbt 0.13.13](http://www.scala-sbt.org/download.html). 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](https://github.com/sbt/sbt/pull/2705), [faster compilation](https://github.com/sbt/sbt/pull/2754), and [much more](http://www.scala-sbt.org/0.13/docs/sbt-0.13-Tech-Previews.html#sbt+0.13.13)!
40
+
41
+
Please head over to the [scala-seed repo](https://github.com/scala/scala-seed.g8) to extend this [giter8 template](https://github.com/foundweekends/giter8) with an example of your favorite 2.12 feature!
42
+
43
+
Scala also works with ant, [maven](http://docs.scala-lang.org/tutorials/scala-with-maven.html) and [gradle](https://docs.gradle.org/current/userguide/scala_plugin.html). You can also download a distribution from [scala-lang.org](http://scala-lang.org/download/2.12.0.html), or obtain the JARs yourself via [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.scala-lang%22%20AND%20v%3A%222.12.0%22).
44
+
45
+
46
+
## Contributors
47
+
48
+
A big thank you to everyone who's helped improve Scala by reporting bugs, improving our documentation, spreading kindness in mailing lists and other public fora, and submitting and reviewing pull requests! You are all magnificent.
49
+
50
+
Scala 2.12.0 is the result of merging over [500 pull requests](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=is%3Amerged%20label%3A2.12%20) out of about [600 received PRs](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=is%3Apr%20label%3A2.12%20). The [contributions to 2.12.x over the last 2 years](https://github.com/scala/scala/graphs/contributors?from=2014-11-01&to=2016-10-29&type=c)[break down](https://docs.google.com/spreadsheets/d/16zVViCpJEZn_x2RlYFh-xAOiHJG3SrYYpfetRr5cu_Y/edit#gid=912693440) as 64/32/4 between the Scala team at Lightbend (lrytz, retronym, adriaanm, SethTisue, szeiger), the community and EPFL.
51
+
52
+
The new encodings of traits, lambdas and lazy vals were developed in fruitful collaboration with the Dotty team.
53
+
54
+
Thank you very much to all contributors that helped realize this Scala release!
55
+
56
+
57
+
## Binary compatibility
58
+
59
+
Since Scala 2.10, minor releases of Scala are binary compatible with each other. We maintain [this policy](/documentation/compatibility.html) for 2.12.x.
60
+
61
+
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.
62
+
63
+
64
+
## Scala 2.12 Overview
35
65
36
66
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).
37
67
- Traits ([#5003](https://github.com/scala/scala/pull/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`).
@@ -42,41 +72,75 @@ Scala 2.12 is all about making optimal use of Java 8's new features (and thus ge
42
72
43
73
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](https://issues.scala-lang.org). Cross-building is a one-line change to most sbt builds, and even provides support for [version-specific source folders](http://www.scala-sbt.org/0.13/docs/sbt-0.13-Tech-Previews.html#Cross-version+support+for+Scala+sources) out of the box, when necessary to work around incompatibilities (e.g. macros).
44
74
45
-
### New features
46
-
47
-
The upcoming sections introduce new features and breaking changes in Scala 2.12 in more detail.
75
+
### New Language Features
76
+
The next sections introduce new features and breaking changes in Scala 2.12 in more detail.
48
77
To understand more technicalities and review past discussions, you can also take a look at the full list of
With Java 8 allowing concrete methods in interfaces, Scala 2.12 is able to compile a trait to a single interface classfile.
55
84
Before, a trait was represented as an interface and a class that held the method implementations.
56
85
57
86
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.
58
87
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.
59
88
60
-
####Java 8-style lambdas
89
+
### Java 8-style lambdas
61
90
62
91
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.
63
92
64
93
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`. Note that in the following situations, the an anonymous function class is still synthesized at compile-time:
65
94
66
-
- If the SAM type is not a simple interface, for example an abstract class or a triat with a field definition (see [#4971](https://github.com/scala/scala/pull/4971))
95
+
- If the SAM type is not a simple interface, for example an abstract class or a trait with a field definition (see [#4971](https://github.com/scala/scala/pull/4971))
67
96
- If the abstract method is specialized - except for `scala.FunctionN`, whose specialized variants can be instantiated using `LambdaMetaFactory` (see [#4971](https://github.com/scala/scala/pull/4971))
68
97
- If the function literal is defined in a constructor or a super call ([#3616](https://github.com/scala/scala/pull/3616))
69
98
70
99
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.
71
100
72
-
#### New back end
101
+
For example, in the REPL:
102
+
103
+
```
104
+
scala> val runRunnableRun: Runnable = () => println("Run!")
Our support for `invokedynamic` is also exposed to macro authors, as shown in [this test case](https://github.com/scala/scala/blob/v2.12.0/test/files/run/indy-via-macro-with-dynamic-args/macro_1.scala).
112
+
113
+
114
+
#### Partial unification for type constructor inference
115
+
116
+
Compiling with `-Ypartial-unification` improves type constructor inference with support for partial unification, fixing the notorious [SI-2712](https://issues.scala-lang.org/browse/SI-2712). Thank you, [Miles Sabin](https://github.com/milessabin) for contributing [your implementation](https://github.com/scala/scala/pull/5102) (and [backporting to 2.11.9](https://github.com/scala/scala/pull/5343))!
117
+
118
+
Also, hat tip to Daniel Spiewak for [a great explanation of this feature](https://gist.github.com/djspiewak/7a81a395c461fd3a09a6941d4cd040f2).
119
+
120
+
For now, we recommend using `-Ypartial-unification` over `-Xexperimental`, as the latter enables some surprising features that will not ship with a future release of Scala.
121
+
122
+
### Parameter names available at runtime
123
+
124
+
With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored in class files and be queried at runtime using reflection.
125
+
A quick REPL session shows this in action:
126
+
127
+
```
128
+
scala> case class Person(name: String, age: Int)
129
+
defined class Person
130
+
131
+
scala> val paramNames = classOf[Person].getConstructors.head.getParameters.toList
132
+
paramNames: List[java.lang.reflect.Parameter] = List(final java.lang.String name, final int age)
133
+
```
134
+
135
+
### Tooling Improvements
136
+
137
+
### New back end
73
138
74
139
Scala 2.12 standardizes on the "GenBCode" back end, which emits code more quickly because it directly generates bytecode from Scala compiler trees, while the previous back end used an intermediate representation called "ICode".
75
140
The old back ends (GenASM and GenIcode) have been removed ([#4814](https://github.com/scala/scala/pull/4814), [#4838](https://github.com/scala/scala/pull/4838)).
76
141
77
142
78
-
79
-
#### New optimizer
143
+
### New optimizer
80
144
81
145
The GenBCode back end includes a new inliner and bytecode optimizer. The optimizer is configured
82
146
using `-opt` compiler option, by default it removes unreachable code within a method. Check
@@ -118,6 +182,31 @@ The Scala distribution is built using `-opt:l:classpath`, which improves the per
118
182
119
183
The GenBCode backend and the implementation of the new optimizer are built on earlier work by Miguel Garcia.
120
184
185
+
186
+
#### Scaladoc look-and-feel overhauled
187
+
188
+
Scaladoc's output is now more attractive, more modern, and easier
189
+
to use.
190
+
191
+
Thanks, [Felix Mulder](https://github.com/felixmulder), for leading
192
+
this effort.
193
+
194
+
#### Scaladoc can be used to document Java sources
195
+
This fix for [SI-4826](https://issues.scala-lang.org/browse/SI-4826) simplifies generating comprehensive documentation for projects with both Scala and Java sources. Thank you for your contribution, [Jakob Odersky](https://github.com/jodersky)!
196
+
197
+
This feature is enabled by default, but can be disabled with:
198
+
199
+
scalacOptions in (Compile, doc) += "-no-java-comments"
200
+
201
+
Some projects with very large Javadoc comments may run into a stack overflow in the Javadoc scanner, which [will be fixed in 2.12.1](https://github.com/scala/scala/pull/5469).
Scala's interactive shell ships with several spiffy improvements. To try it out, launch it from the command line with the `scala` script or in sbt using the `console` task. If you like color (who doesn't!), use `scala -Dscala.color` instead until [it's turned on by default](https://github.com/scala/scala-dev/issues/256).
206
+
207
+
Since 2.11.8, the REPL uses the [same tab completion logic](https://github.com/scala/scala/pull/4725) as Scala IDE and ENSIME, which greatly improves the experience! Check out the PR description for some tips and tricks.
208
+
209
+
### Library Improvements
121
210
#### Either is now right-biased
122
211
123
212
`Either` now supports operations like `map`, `flatMap`, `contains`,
@@ -128,38 +217,28 @@ The GenBCode backend and the implementation of the new optimizer are built on ea
128
217
The changes are source-compatible with old code (except in the
129
218
presence of conflicting extension methods).
130
219
131
-
Thanks, [Simon Ochsenreither](https://github.com/soc), for this
132
-
contribution.
220
+
This change has allowed other libraries, such as [cats](http://typelevel.org/cats/) to standardize on `Either`.
221
+
222
+
Thanks, [Simon Ochsenreither](https://github.com/soc), for this contribution.
133
223
134
-
#### Futures improved
224
+
225
+
### Futures improved
135
226
136
227
This [blog post series](https://github.com/viktorklang/blog)
137
228
by Viktor Klang explores the diverse improvements made to
138
229
`scala.concurrent.Future` for 2.12.
139
230
140
-
#### Scaladoc look-and-feel overhauled
141
-
142
-
Scaladoc's output is now more attractive, more modern, and easier
143
-
to use.
144
-
145
-
Thanks, [Felix Mulder](https://github.com/felixmulder), for leading
146
-
this effort.
147
-
148
-
#### Scaladoc now supports doc comments in Java sources
231
+
#### Use Standard Java 8 APIs
232
+
The Scala library is [free](https://github.com/scala/scala/pull/4443) of [references](https://github.com/scala/scala/pull/4712) to `sun.misc.Unsafe`, and [no longer ships](https://github.com/scala/scala/pull/4629) with a fork of the forkjoin library.
149
233
150
-
Thanks, [Jakob Odersky](https://github.com/jodersky), for this fix to [SI-4826](https://issues.scala-lang.org/browse/SI-4826).
151
234
152
-
This feature is enabled by default, but can be disabled with:
153
235
154
-
scalacOptions in (Compile, doc) += "-no-java-comments"
236
+
## Breaking changes
155
237
156
-
#### Partial unification of type constructors (SI-2712)
238
+
###Lambdas and locks
157
239
158
-
Compiling with `-Ypartial-unification` adds partial unification of type constructors, fixing the notorious [SI-2712](https://issues.scala-lang.org/browse/SI-2712), thanks to [Miles Sabin](https://github.com/milessabin).
159
240
160
-
### Breaking changes
161
-
162
-
#### SAM types
241
+
### SAM types
163
242
164
243
Implicit conversion of function types to SAM types won't kick in as often now, since the compiler's own SAM conversion takes priority:
165
244
@@ -171,7 +250,7 @@ Implicit conversion of function types to SAM types won't kick in as often now, s
171
250
172
251
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).
173
252
174
-
####Inferred types for `val` (and `lazy val`)
253
+
### Inferred types for `val` (and `lazy val`)
175
254
176
255
[#5141](https://github.com/scala/scala/pull/5141) and
177
256
[#5294](https://github.com/scala/scala/pull/5294) align type
@@ -191,35 +270,13 @@ code fails to compile.
191
270
and those defined in methods now use a [more efficient representation](https://github.com/scala/scala/pull/5374)
192
271
that allows synchronization on the holder of the `lazy val`, instead of the surrounding class (as in Dotty).
193
272
194
-
####Changed syntax trees (affects macro and compiler plugin authors)
273
+
### Changed syntax trees (affects macro and compiler plugin authors)
195
274
196
275
PR [#4794](https://github.com/scala/scala/pull/4749) 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.
197
276
198
277
199
278
200
-
## Binary compatibility
201
-
202
-
Since Scala 2.11, minor releases of Scala are binary compatible with each other. The [Scala 2.11.1 release notes](http://scala-lang.org/news/2.11.1) explain in more detail on how binary compatibility works in Scala.
203
-
Scala 2.12 will continue this tradition: every 2.12.x release will be binary compatible with 2.12.0.
204
-
205
-
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. We are working with the community to ensure that core projects in the Scala eco-system become available for 2.12. Please refer to this growing [list of libraries and frameworks](https://github.com/scala/make-release-notes/blob/2.12.x/projects-2.12.md).
206
-
207
-
208
-
## Contributors
209
-
210
-
A big thank you to everyone who's helped improve Scala by reporting bugs, improving our documentation, spreading kindness in mailing lists and other public fora, and submitting and reviewing pull requests! You are all magnificent.
211
-
212
-
Scala 2.12.0 is the result of merging over [500 pull requests](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=is%3Amerged%20label%3A2.12%20) out of about [600 received PRs](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=is%3Apr%20label%3A2.12%20). The [contributions to 2.12.x over the last 2 years](https://github.com/scala/scala/graphs/contributors?from=2014-11-01&to=2016-10-29&type=c)[break down](https://docs.google.com/spreadsheets/d/16zVViCpJEZn_x2RlYFh-xAOiHJG3SrYYpfetRr5cu_Y/edit#gid=912693440) as 64/32/4 between the Scala team at Lightbend (lrytz, retronym, adriaanm, SethTisue, szeiger), the community and EPFL.
213
-
214
-
Thank you very much to all contributors that helped realize this Scala release!
215
-
216
-
217
-
## Release notes
279
+
## Improving these notes
218
280
219
281
Improvements to these release notes [are welcome!](https://github.com/scala/make-release-notes/blob/2.12.x/hand-written.md)
220
282
221
-
## Obtaining Scala
222
-
* Install a Java 8 runtime (Java 9 is not yet supported).
223
-
* Download a distribution from [scala-lang.org](http://scala-lang.org/download/2.12.0.html)
224
-
* Bump the `scalaVersion` setting in your sbt-based project. We recommend upgrading to 0.13.13 for [faster compilation](https://github.com/sbt/sbt/pull/2754) and much more!
225
-
* Obtain JARs via [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.scala-lang%22%20AND%20v%3A%222.12.0%22)
0 commit comments