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
@publicInBinarydefpublicAPI:Int= ... // warn: `@publicInBinary` has no effect on public definitions
90
91
}
91
92
~~~
92
93
will generate the following bytecode signatures
@@ -99,32 +100,32 @@ public class C {
99
100
}
100
101
~~~
101
102
102
-
In the bytecode, `@binaryAPI` definitions will have the [ACC_PUBLIC](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1-200-E.1) flag.
103
+
In the bytecode, `@publicInBinary` definitions will have the [ACC_PUBLIC](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1-200-E.1) flag.
103
104
<!-- We can also set the [ACC_SYNTHETIC](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1-200-E.1) to hide these definitions from javac and java IDEs. -->
104
105
105
106
#### Binary API and inlining
106
107
107
108
A non-public reference in an inline method is handled as follows:
108
-
- if the reference is a `@binaryAPI` the reference is used;
109
+
- if the reference is a `@publicInBinary` the reference is used;
109
110
- otherwise, an accessor is automatically generated and used.
110
111
111
112
Example:
112
113
~~~scala
113
-
importscala.annotation.binaryAPI
114
+
importscala.annotation.publicInBinary
114
115
classC {
115
-
@binaryAPIprivate[C] defa:Int= ...
116
+
@publicInBinaryprivate[C] defa:Int= ...
116
117
private[C] defb:Int= ...
117
-
@binaryAPIprotecteddefc:Int= ...
118
+
@publicInBinaryprotecteddefc:Int= ...
118
119
protecteddefd:Int= ...
119
120
inlinedeffoo:Int= a + b + c + d
120
121
}
121
122
~~~
122
123
before inlining the compiler will generate the accessors for inlined definitions
123
124
~~~scala
124
125
classC {
125
-
@binaryAPIprivate[C] defa:Int= ...
126
+
@publicInBinaryprivate[C] defa:Int= ...
126
127
private[C] defb:Int= ...
127
-
@binaryAPIprotecteddefc:Int= ...
128
+
@publicInBinaryprotecteddefc:Int= ...
128
129
protecteddefd:Int= ...
129
130
finaldefC$$inline$b:Int= ...
130
131
finaldefC$$inline$d:Int= ...
@@ -171,15 +172,15 @@ When an accessor is detected we can tell the user how to fix the issue. For exam
171
172
|
172
173
| To make sure that the inlined code is binary compatible you must make sure that
173
174
| method b is public in the binary API.
174
-
| * Option 1: Annotate method b with @binaryAPI
175
+
| * Option 1: Annotate method b with @publicInBinary
175
176
| * Option 2: Make method b public
176
177
|
177
178
| This change may break binary compatibility if a previous version of this
178
179
| library was compiled with generated accessors. Binary compatibility should
179
180
| be checked using MiMa. If binary compatibility is broken, you should add the
180
181
| old accessor explicitly in the source code. The following code should be
181
182
| added to class C:
182
-
| @binaryAPI private[C] def C$$inline$b: Int = this.b
183
+
| @publicInBinary private[C] def C$$inline$b: Int = this.b
* Only valid on `def`, `val`, `lazy val`, `var`, `object`, and `given`.
224
-
* TASTy will contain references to non-public definitions that are out of scope but `@binaryAPI`. TASTy already allows those references.
225
+
* TASTy will contain references to non-public definitions that are out of scope but `@publicInBinary`. TASTy already allows those references.
225
226
* The annotated definitions will be public in the generated bytecode. Definitions should be made public as early as possible in the compiler phases, as this can remove the need to create other accessors. It should be done after we check the accessibility of references.
226
227
227
228
#### Inline
228
229
229
230
* Inlining will not require the generation of an inline accessor for binary APIs.
230
231
* The user will be warned if a new inline accessor is automatically generated under `-WunstableInlineAccessors`.
231
-
The message will suggest `@binaryAPI` and how to fix potential incompatibilities.
232
+
The message will suggest `@publicInBinary` and how to fix potential incompatibilities.
232
233
233
234
### Compatibility
234
235
235
-
The introduction of the `@binaryAPI` do not introduce any binary incompatibility.
236
+
The introduction of the `@publicInBinary` do not introduce any binary incompatibility.
236
237
237
-
Using references to `@binaryAPI` in inline code can cause binary incompatibilities. These incompatibilities are equivalent to the ones that can occur due to the unsoundness we want to fix. When migrating to binary APIs, the compiler will show the implementation of accessors that the users need to add to keep binary compatibility with pre-binaryAPI code.
238
+
Using references to `@publicInBinary` in inline code can cause binary incompatibilities. These incompatibilities are equivalent to the ones that can occur due to the unsoundness we want to fix. When migrating to binary APIs, the compiler will show the implementation of accessors that the users need to add to keep binary compatibility with pre-publicInBinary code.
238
239
239
240
### Other concerns
240
241
241
-
* Tools that analyze inlined TASTy code might need to know about `@binaryAPI`. For example [MiMa](https://github.com/lightbend/mima/) and [TASTy MiMa](https://github.com/scalacenter/tasty-mima).
242
+
* Tools that analyze inlined TASTy code might need to know about `@publicInBinary`. For example [MiMa](https://github.com/lightbend/mima/) and [TASTy MiMa](https://github.com/scalacenter/tasty-mima).
242
243
243
244
## Alternatives
244
245
245
-
### Add a `@binaryAPIAccessor`
246
+
### Add a `@binaryAccessor`
246
247
This annotation would generate an stable accessor. This annotation could be used on `private` definition. It would also mitigate [migration costs](https://gist.github.com/nicolasstucki/003f7293941836b08a0d53dbcb913e3c) for library authors that have published unstable accessors.
0 commit comments