Skip to content

Commit 46bd277

Browse files
committed
Change name of annotation to @publicInBinary
1 parent dd862f8 commit 46bd277

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

content/binary-api.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ title: SIP-52 - Binary APIs
1010

1111
## History
1212

13-
| Date | Version |
14-
|---------------|--------------------|
15-
| Feb 27 2022 | Initial Draft |
16-
| Aug 16 2022 | Single Annotation |
13+
| Date | Version |
14+
|---------------|------------------------|
15+
| Feb 27 2022 | Initial Draft |
16+
| Aug 16 2022 | Single Annotation |
17+
| Aug 24 2022 | Change Annotation Name |
1718

1819
## Summary
1920

2021
The purpose of binary APIs is to have publicly accessible definitions in generated bytecode for definitions that are package private or protected.
21-
This proposal introduces the `@binaryAPI` annotation on term definitions and the `-WunstableInlineAccessors` linting flag.
22+
This proposal introduces the `@publicInBinary` annotation on term definitions and the `-WunstableInlineAccessors` linting flag.
2223

2324

2425
## Motivation
@@ -68,11 +69,11 @@ object C:
6869

6970
### High-level overview
7071

71-
This proposal introduces the `@binaryAPI` annotation, and adds a migration path to inline methods in libraries (requiring binary compatibility).
72+
This proposal introduces the `@publicInBinary` annotation, and adds a migration path to inline methods in libraries (requiring binary compatibility).
7273

73-
#### `@binaryAPI` annotation
74+
#### `@publicInBinary` annotation
7475

75-
A binary API is a definition that is annotated with `@binaryAPI` or overrides a definition annotated with `@binaryAPI`.
76+
A binary API is a definition that is annotated with `@publicInBinary` or overrides a definition annotated with `@publicInBinary`.
7677
This annotation can be placed on `def`, `val`, `lazy val`, `var`, `object`, and `given` definitions.
7778
A binary API will be publicly available in the bytecode.
7879

@@ -84,9 +85,9 @@ Example:
8485

8586
~~~ scala
8687
class C {
87-
@binaryAPI private[C] def packagePrivateAPI: Int = ...
88-
@binaryAPI protected def protectedAPI: Int = ...
89-
@binaryAPI def publicAPI: Int = ... // warn: `@binaryAPI` has no effect on public definitions
88+
@publicInBinary private[C] def packagePrivateAPI: Int = ...
89+
@publicInBinary protected def protectedAPI: Int = ...
90+
@publicInBinary def publicAPI: Int = ... // warn: `@publicInBinary` has no effect on public definitions
9091
}
9192
~~~
9293
will generate the following bytecode signatures
@@ -99,32 +100,32 @@ public class C {
99100
}
100101
~~~
101102

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.
103104
<!-- 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. -->
104105

105106
#### Binary API and inlining
106107

107108
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;
109110
- otherwise, an accessor is automatically generated and used.
110111

111112
Example:
112113
~~~ scala
113-
import scala.annotation.binaryAPI
114+
import scala.annotation.publicInBinary
114115
class C {
115-
@binaryAPI private[C] def a: Int = ...
116+
@publicInBinary private[C] def a: Int = ...
116117
private[C] def b: Int = ...
117-
@binaryAPI protected def c: Int = ...
118+
@publicInBinary protected def c: Int = ...
118119
protected def d: Int = ...
119120
inline def foo: Int = a + b + c + d
120121
}
121122
~~~
122123
before inlining the compiler will generate the accessors for inlined definitions
123124
~~~ scala
124125
class C {
125-
@binaryAPI private[C] def a: Int = ...
126+
@publicInBinary private[C] def a: Int = ...
126127
private[C] def b: Int = ...
127-
@binaryAPI protected def c: Int = ...
128+
@publicInBinary protected def c: Int = ...
128129
protected def d: Int = ...
129130
final def C$$inline$b: Int = ...
130131
final def C$$inline$d: Int = ...
@@ -171,15 +172,15 @@ When an accessor is detected we can tell the user how to fix the issue. For exam
171172
|
172173
| To make sure that the inlined code is binary compatible you must make sure that
173174
| method b is public in the binary API.
174-
| * Option 1: Annotate method b with @binaryAPI
175+
| * Option 1: Annotate method b with @publicInBinary
175176
| * Option 2: Make method b public
176177
|
177178
| This change may break binary compatibility if a previous version of this
178179
| library was compiled with generated accessors. Binary compatibility should
179180
| be checked using MiMa. If binary compatibility is broken, you should add the
180181
| old accessor explicitly in the source code. The following code should be
181182
| 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
183184
-----------------------------------------------------------------------------
184185
-- [E...] Compatibility Warning: C.scala -----------------------------
185186
| inline def foo: Int = a + b + c + d
@@ -194,55 +195,55 @@ When an accessor is detected we can tell the user how to fix the issue. For exam
194195
|
195196
| To make sure that the inlined code is binary compatible you must make sure that
196197
| method d is public in the binary API.
197-
| * Option 1: Annotate method d with @binaryAPI
198+
| * Option 1: Annotate method d with @publicInBinary
198199
| * Option 2: Make method d public
199200
|
200201
| This change may break binary compatibility if a previous version of this
201202
| library was compiled with generated accessors. Binary compatibility should
202203
| be checked using MiMa. If binary compatibility is broken, you should add the
203204
| old accessor explicitly in the source code. The following code should be
204205
| added to class C:
205-
| @binaryAPI private[C] def C$$inline$d: Int = this.d
206+
| @publicInBinary private[C] def C$$inline$d: Int = this.d
206207
-----------------------------------------------------------------------------
207208
~~~
208209

209210
</details>
210211

211212
### Specification
212213

213-
We must add `binaryAPI` to the standard library.
214+
We must add `publicInBinary` to the standard library.
214215

215216
```scala
216217
package scala.annotation
217218

218-
final class binaryAPI extends scala.annotation.StaticAnnotation
219+
final class publicInBinary extends scala.annotation.StaticAnnotation
219220
```
220221

221-
#### `@binaryAPI` annotation
222+
#### `@publicInBinary` annotation
222223

223224
* 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.
225226
* 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.
226227

227228
#### Inline
228229

229230
* Inlining will not require the generation of an inline accessor for binary APIs.
230231
* 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.
232233

233234
### Compatibility
234235

235-
The introduction of the `@binaryAPI` do not introduce any binary incompatibility.
236+
The introduction of the `@publicInBinary` do not introduce any binary incompatibility.
236237

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.
238239

239240
### Other concerns
240241

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).
242243

243244
## Alternatives
244245

245-
### Add a `@binaryAPIAccessor`
246+
### Add a `@binaryAccessor`
246247
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.
247248

248249
* Implementation https://github.com/lampepfl/dotty/pull/16992

0 commit comments

Comments
 (0)