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: experimental-backend.md
+43-2Lines changed: 43 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Experimental Backend in Scala 2.11
2
2
3
-
Scala 2.11 ships with an experimental backend named "GenBCode", originally implemented by [Miguel Garcia](https://github.com/magarciaEPFL).
3
+
Scala 2.11 ships with an experimental backend named "GenBCode", originally implemented by [@magarciaEPFL](https://github.com/magarciaEPFL).
4
4
This backend will become the new default in Scala 2.12.
5
5
Given that the new backend is experimental in Scala 2.11, it can be modified and extended without compatibility concerns.
6
6
Most of the work towards the Scala 2.12 backend happens in the 2.11 branch and flows into 2.11.x minor releases.
@@ -15,8 +15,49 @@ GenBCode without any further compiler flags is a drop-in replacement for the cur
15
15
The generated bytecode is binary compatible, altough not exactly the same; some instruction sequences may differ.
16
16
If you find a binary incompatibility, please [report an issue](https://issues.scala-lang.org/secure/Dashboard.jspa).
17
17
18
+
## Delambdafy-Method
18
19
20
+
`-Ydelambdafy:method` is an experimental option in Scala 2.11 to alter the translation of lambdas, implemented by [@JamesIry](https://github.com/JamesIry).
19
21
20
-
## Delambdafy-Method
22
+
Traditionally, the anonymous class generated for a lambda contains the lambda body in the `apply` method of the class.
23
+
When using delambdafy-method, a method containing the lambda body is generated for each lambda, and the anonymous class delegates to this method.
24
+
25
+
Delambdafy-method is a requiement for emitting lambdas in Java 8 style, as explained in detail in [this Gist by @retronym](https://gist.github.com/retronym/0178c212e4bacffed568).
26
+
27
+
## Target jvm-1.8
28
+
29
+
`-target:jvm-1.8` instructs the Scala compiler to generate classfiles of version 52 (the default is `jvm-1.6`, generating classfiles of version 50).
30
+
31
+
This option is one of the requirements to enable emitting lambdas in Java 8 style.
32
+
33
+
## Scala-Java8-Compat
34
+
35
+
The [`scala-java8-compat` library](https://github.com/scala/scala-java8-compat) defines subtypes of Scala's `FunctionN` that have a single abstract method.
36
+
37
+
The `FunctionN` traits in Scala are compiled to interface classfiles with multiple abstract methods (`compose`, `apply`, `andThen`, specialized variants of `apply`).
38
+
The compat library compiles to Java 8 bytecode and makes use of [default methods](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html) for all methods but `apply`.
39
+
40
+
## Emitting Java 8 Style Lambdas
41
+
42
+
The Scala 2.11.7 compiler emits lambdas in Java 8 style (using `invokedynamic` and LambdaMetaFactory) if the following conditions are met:
43
+
- the compiler is running on Java 8
44
+
-`-Ybackend:GenBCode` is enabled
45
+
-`-Ydelambdafy:method` is enabled
46
+
-`-target:jvm-1.8` is enabled
47
+
- the scala-java8-compat library is on the compiler's classpath
48
+
49
+
In an SBT project, this can be achieved using the following settins:
0 commit comments