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
Copy file name to clipboardExpand all lines: hand-written.md
+32-56Lines changed: 32 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
We are happy to announce the availability of Scala 2.12.0!
1
+
We are very happy to announce the availability of Scala 2.12.0!
2
2
3
-
The Scala 2.12 compiler has been completely overhauled to make use of the new VM features available in Java 8!
4
-
- A trait [compiles directly to an interface](#trait-compiles-to-an-interface) with default methods for improved binary compatibility.
5
-
-A function literal (lambda) can now target any [Single Abstract Method (SAM) type](#java-8-style-lambdas), including Scala's built-in `FunctionN` classes. Scala code can seamlessly use libraries with higher-order functions written in Java 8, and vice versa. Code generation for function literals uses `invokedynamic` to avoid emitting a classfile at compile time, just like Java 8.
3
+
The Scala 2.12 compiler has been completely overhauled to make use of the new VM features available in Java 8:
4
+
- A trait [compiles directly to an interface](#trait-compiles-to-an-interface) with default methods. This improves binary compatibility and Java interoperability.
5
+
-Scala and Java 8 interop is also improved for functional code, as methods that take functions can easily be called in each direction using lambda syntax. The `FunctionN` classes in Scala's standard library are now Single Abstract Method (SAM) types, and all [SAM types](#java-8-style-lambdas) are treated uniformly -- from type checking until code generation (no class file is generated for lambdas, and `invokedynamic` is used instead).
6
6
7
7
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
8
@@ -14,25 +14,19 @@ Our [roadmap](https://github.com/scala/scala/milestones) lists the following upc
14
14
## Known issues
15
15
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.
16
16
17
-
The heavy use of default methods for compiling traits caused some performance regressions in the
18
-
startup time of Scala applications. Note that steady-state performance is not affected according to
19
-
our measurements.
17
+
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.
20
18
21
-
The regression was mitigated 2.12.0-RC2 (and the final release) by generating forwarder methods in
22
-
classes that inherit concrete methods form trait. A summary and links to detailed information is
23
-
available in the description of pull request [#5429](https://github.com/scala/scala/pull/5429).
19
+
The regression was mitigated 2.12.0-RC2 (and the final release) by generating forwarder methods in classes that inherit concrete methods form trait, which unfortunately [increases bytecode size while improving JVM startup performance](https://github.com/scala/scala/pull/5429).
24
20
25
-
Please let us know if you notice any performance regressions. We will continue to tweak the bytecode
26
-
during the 2.12.x cycle to get the best performance out of the JVM.
21
+
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.
27
22
28
23
We hope to address the following in a future 2.12.x release:
29
24
30
25
-[SI-9824](https://issues.scala-lang.org/browse/SI-9824): Parallel collections are prone to deadlock in the REPL and in object initializers.
31
26
32
27
## Obtaining Scala
33
28
### Java 8 runtime
34
-
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.
35
-
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.
29
+
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. 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.
36
30
37
31
### Build tool
38
32
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)!
@@ -69,7 +63,9 @@ Scala 2.12 is all about making optimal use of Java 8's new features (and thus ge
69
63
- We've standardized on the GenBCode back end ([#4814](https://github.com/scala/scala/pull/4814), [#4838](https://github.com/scala/scala/pull/4838)) and the flat classpath implementation is now the default ([#5057](https://github.com/scala/scala/pull/5057)).
70
64
- The optimizer has been completely overhauled for 2.12.
71
65
72
-
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).
66
+
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](#breaking-changes), please [file an issue](https://issues.scala-lang.org).
67
+
68
+
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](http://www.scala-sbt.org/0.13/docs/sbt-0.13-Tech-Previews.html#Cross-version+support+for+Scala+sources) out of the box.
73
69
74
70
### New Language Features
75
71
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](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=%20is%3Amerged%20label%3A2.12%20label%3Arelease-notes%20) that went into this release.
@@ -78,8 +74,7 @@ The next sections introduce new features and breaking changes in Scala 2.12 in m
78
74
79
75
With Java 8 allowing 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.
80
76
81
-
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.
82
-
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 super trait.
77
+
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 ( `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 super trait.
83
78
84
79
#### Java 8-style lambdas
85
80
@@ -91,19 +86,21 @@ For each lambda the compiler generates a method containing the lambda body, and
91
86
- 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))
92
87
- If the function literal is defined in a constructor or a super call ([#3616](https://github.com/scala/scala/pull/3616))
93
88
89
+
The language specification has the [full list of requirements for SAM conversion](http://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#sam-conversion).
90
+
94
91
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.
95
92
96
93
For example, in the REPL:
97
94
98
95
```
99
-
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).
103
+
Our backend support for `invokedynamic` is also available 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).
107
104
108
105
109
106
#### Partial unification for type constructor inference
@@ -116,8 +113,7 @@ For now, we recommend using `-Ypartial-unification` over `-Xexperimental`, as th
116
113
117
114
#### Parameter names available at runtime
118
115
119
-
With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored in class files and be queried at runtime using reflection.
120
-
A quick REPL session shows this in action:
116
+
With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored in class files and be queried at runtime using reflection. A quick REPL session shows this in action:
121
117
122
118
```
123
119
scala> case class Person(name: String, age: Int)
@@ -131,15 +127,12 @@ paramNames: List[java.lang.reflect.Parameter] = List(final java.lang.String name
131
127
132
128
#### New back end
133
129
134
-
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".
135
-
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)).
130
+
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". 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)).
136
131
137
132
138
133
#### New optimizer
139
134
140
-
The GenBCode back end includes a new inliner and bytecode optimizer. The optimizer is configured
141
-
using `-opt` compiler option, by default it removes unreachable code within a method. Check
142
-
`-opt:help` to see the list of available options for the optimizer.
135
+
The GenBCode back end includes a new inliner and bytecode optimizer. The optimizer is configured using the `-opt` compiler option. By default it only removes unreachable code within a method. Check `-opt:help` to see the list of available options for the optimizer.
143
136
144
137
The following optimizations are available:
145
138
@@ -158,7 +151,7 @@ def f(a: Int, b: Boolean) = (a, b) match {
158
151
}
159
152
```
160
153
161
-
produces, when compiled with `-opt:l:method`, the following bytecode (decompiled using cfr-decompiler):
154
+
produces, when compiled with `-opt:l:method`, the following bytecode (decompiled using [cfr](http://www.benf.org/other/cfr/)):
162
155
163
156
```java
164
157
publicint f(int a, boolean b) {
@@ -180,11 +173,9 @@ The GenBCode backend and the implementation of the new optimizer are built on ea
180
173
181
174
#### Scaladoc look-and-feel overhauled
182
175
183
-
Scaladoc's output is now more attractive, more modern, and easier
184
-
to use.
176
+
Scaladoc's output is now more attractive, more modern, and easier to use.
185
177
186
-
Thanks, [Felix Mulder](https://github.com/felixmulder), for leading
187
-
this effort.
178
+
Thanks, [Felix Mulder](https://github.com/felixmulder), for leading this effort.
188
179
189
180
#### Scaladoc can be used to document Java sources
190
181
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)!
@@ -204,24 +195,19 @@ Since 2.11.8, the REPL uses the [same tab completion logic](https://github.com/s
204
195
### Library Improvements
205
196
#### Either is now right-biased
206
197
207
-
`Either` now supports operations like `map`, `flatMap`, `contains`,
208
-
`toOption`, and so forth, which operate on the right-hand side.
198
+
`Either` now supports operations like `map`, `flatMap`, `contains`, `toOption`, and so forth, which operate on the right-hand side.
209
199
210
200
(`.left` and `.right` may be deprecated in favor of `.swap` in a later release.)
211
201
212
-
The changes are source-compatible with old code (except in the
213
-
presence of conflicting extension methods).
202
+
The changes are source-compatible with old code (except in the presence of conflicting extension methods).
214
203
215
204
This change has allowed other libraries, such as [cats](http://typelevel.org/cats/) to standardize on `Either`.
216
205
217
206
Thanks, [Simon Ochsenreither](https://github.com/soc), for this contribution.
218
207
219
208
220
209
#### Futures improved
221
-
222
-
This [blog post series](https://github.com/viktorklang/blog)
223
-
by Viktor Klang explores the diverse improvements made to
224
-
`scala.concurrent.Future` for 2.12.
210
+
This [blog post series](https://github.com/viktorklang/blog) by Viktor Klang explores the diverse improvements made to `scala.concurrent.Future` for 2.12.
225
211
226
212
#### Use Standard Java 8 APIs
227
213
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.
@@ -231,7 +217,7 @@ The Scala library is [free](https://github.com/scala/scala/pull/4443) of [refere
231
217
## Breaking changes
232
218
233
219
### Lambdas and locks
234
-
TODO
220
+
Our new lambda encoding lifts the lambda body to a method in the enclosing class. If your code relies on the old behavior, which spins up a new class for each lambda, you may notice this difference because a lambda invocation will now indirect through the instance of the enclosing class (or in case of an object, its module field). When a lock is held on this instance (e.g., during object initialization), deadlocks may occur that did not happen before. One example of this [surprised users of ScalaCheck](https://github.com/rickynils/scalacheck/issues/290) -- now [fixed](https://github.com/rickynils/scalacheck/pull/294).
235
221
236
222
### SAM types
237
223
@@ -247,23 +233,13 @@ To retain the old behavior, you may compile under `-Xsource:2.11`, or disqualify
247
233
248
234
### Inferred types for `val` (and `lazy val`)
249
235
250
-
[#5141](https://github.com/scala/scala/pull/5141) and
251
-
[#5294](https://github.com/scala/scala/pull/5294) align type
252
-
inference for `def`, `val`, and `lazy val`, fixing assorted
253
-
corner cases and inconsistencies. As a result, the inferred type
254
-
of a `val` or `lazy val` may change.
236
+
[#5141](https://github.com/scala/scala/pull/5141) and [#5294](https://github.com/scala/scala/pull/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.
255
237
256
-
In particular, `implicit val`s that didn't need explicitly declared
257
-
types before may need them now. (This is always good practice
258
-
anyway.)
238
+
In particular, `implicit val`s that didn't need explicitly declared types before may need them now. (This is always good practice anyway.)
259
239
260
-
You can get the old behavior with `-Xsource:2.11`. This may be
261
-
useful for testing whether these changes are responsible if your
262
-
code fails to compile.
240
+
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.
263
241
264
-
[Lazy vals and objects](https://github.com/scala/scala/pull/5294) have been reworked,
265
-
and those defined in methods now use a [more efficient representation](https://github.com/scala/scala/pull/5374)
266
-
that allows synchronization on the holder of the `lazy val`, instead of the surrounding class (as in Dotty).
242
+
[Lazy vals and objects](https://github.com/scala/scala/pull/5294) have been reworked, and those defined in methods now use a [more efficient representation](https://github.com/scala/scala/pull/5374) that allows synchronization on the holder of the `lazy val`, instead of the surrounding class (as in Dotty).
267
243
268
244
### Changed syntax trees (affects macro and compiler plugin authors)
0 commit comments