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
For library maintainers, Scala 3.7.0 stabilizes the `@publicInBinary` annotation, introduced experimentally in Scala 3.4. This annotation ensures binary compatibility when inline methods access non-public members and prevent generation of redundant accessors required by inlining mechanism.
21
-
22
-
Inline methods are always inlined at their call sites. If they refer to members not visible outside their defining scope, the compiler generates accessor methods. The accessors are not subject to binary compatibility; they might be emitted differently by newer versions of compiler or eventually removed.
23
-
The `@publicInBinary` annotation addresses this by emitting those members as public in bytecode, while maintaining restricted source-level visibility.
24
-
This allows the compiler to refer to the original non-private member without the need to create additional accessors.
25
-
26
-
```scala
27
-
objectapi:
28
-
classService:
29
-
private[api] defimplementation():Unit= println("Executing old API")
30
-
inlinedefuse() = implementation()
31
-
// generated by compiler, accessed in `use()`
32
-
// def api$Service$$inline$implementation(): Unit = implementation()
The new annotation also resolves a long-standing issue with the inability to invoke a private constructor of a class from inlined methods. Now by annotating the constructor with `@publicInBinary` you are allowed to access it directly from inlined methods.
45
-
46
-
```scala
47
-
importscala.annotation.publicInBinary
48
-
49
-
classPrinter@publicInBinary private(id: Int)
50
-
objectPrinter:
51
-
inlinedefcreate():Printer=newPrinter(42) // Not allowed previously
52
-
```
53
-
54
-
SIP-52 has also introduced the linting flag `-WunstableInlineAccessors` which detects and emits warnings for all unstable accessors generated for inline methods. This flag has been available since Scala 3.4.0. We highly recommend its usage of users' codebases, especially in the case of public libraries.
55
18
56
19
### [SIP-58: Named Tuples](https://docs.scala-lang.org/sips/named-tuples.html)
57
20
58
-
Named Tuples introduced as experimental in Scala 3.5 are now a stable feature.
21
+
Named Tuples, introduced as experimental in Scala 3.5, are now a stable feature.
59
22
Named tuples are a convenient lightweight way to return multiple results from a function or to model the data using tuples while allowing you to use meaningful names for its fields.
60
23
61
24
```scala
@@ -115,6 +78,44 @@ case class Release(version: String, issues: List[String])
For library maintainers, Scala 3.7.0 stabilizes the `@publicInBinary` annotation, introduced experimentally in Scala 3.4. This annotation ensures binary compatibility when inline methods access non-public members and prevent generation of redundant accessors required by inlining mechanism.
84
+
85
+
Inline methods are always inlined at their call sites. If they refer to members not visible outside their defining scope, the compiler generates accessor methods. The accessors are not subject to binary compatibility; they might be emitted differently by newer versions of compiler or eventually removed.
86
+
The `@publicInBinary` annotation addresses this by emitting those members as public in bytecode, while maintaining restricted source-level visibility.
87
+
This allows the compiler to refer to the original non-private member without the need to create additional accessors.
88
+
89
+
```scala
90
+
objectapi:
91
+
classService:
92
+
private[api] defimplementation():Unit= println("Executing old API")
93
+
inlinedefuse() = implementation()
94
+
// generated by compiler, accessed in `use()`
95
+
// def api$Service$$inline$implementation(): Unit = implementation()
The new annotation also resolves a long-standing issue with the inability to invoke a private constructor of a class from inlined methods. Now by annotating the constructor with `@publicInBinary` you are allowed to access it directly from inlined methods.
108
+
109
+
```scala
110
+
importscala.annotation.publicInBinary
111
+
112
+
classPrinter@publicInBinary private(id: Int)
113
+
objectPrinter:
114
+
inlinedefcreate():Printer=newPrinter(42) // Not allowed previously
115
+
```
116
+
117
+
SIP-52 has also introduced the linting flag `-WunstableInlineAccessors` which detects and emits warnings for all unstable accessors generated for inline methods. This flag has been available since Scala 3.4.0. We highly recommend its usage of users' codebases, especially in the case of public libraries.
118
+
118
119
## Preview features
119
120
120
121
Scala 3.7 introduces the concept of `preview` features — fully implemented and SIP-approved, but potentially subject to small refinements before becoming stable.
0 commit comments