Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @binaryAPI and @binaryAPIAccessor #16992

Closed

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Feb 22, 2023

This PR adds @binaryAPI and @binaryAPIAccessor.

@binaryAPI

A binary API is a definition that is annotated with @binaryAPI or overrides a definition annotated with @binaryAPI. This annotation can be placed on def, val, lazy val, var, object, and given definitions. A binary API will be publicly available in the bytecode. It cannot be used on private/private[this] definitions.

@binaryAPIAccessor

A binary API with accessor is a definition that is annotated with @binaryAPIAccessor.
This annotation can be placed on def, val, lazy val, var, object, and given definitions. The annotated definition will get a public accessor named <fullClassName>$$inline$<definitionName>.

Interaction with inline

This is useful in combination with inline definitions. If an inline definition refers to a private/protected definition marked as @binaryAPI it does not need to use an accessor. We still generate the accessors for binary compatibility but do not use them.

References

SIP: scala/improvement-proposals#58

Part of the fix for #13215
Part of the fix for #15413
Part of the fix for #16983

Alternative to #16985

@nicolasstucki nicolasstucki self-assigned this Feb 22, 2023
@nicolasstucki nicolasstucki force-pushed the add-binary-api-annotation branch 19 times, most recently from 0a55e7f to d1460af Compare February 27, 2023 07:44
@nicolasstucki nicolasstucki force-pushed the add-binary-api-annotation branch 2 times, most recently from 9fd92fd to dd786ce Compare February 27, 2023 09:25
@nicolasstucki nicolasstucki force-pushed the add-binary-api-annotation branch 3 times, most recently from 908df98 to 7025414 Compare February 28, 2023 07:52
@nicolasstucki nicolasstucki force-pushed the add-binary-api-annotation branch 2 times, most recently from 241874f to b19652a Compare February 28, 2023 08:54
@nicolasstucki
Copy link
Contributor Author

I split the old version of binaryAPI into binaryAPI and binaryAPIAccessor. This provides a way to consistently generate accessors for private[this] definitions. With this design, we remove the binary breaking change for a private[this] that becomes more public.

@nicolasstucki nicolasstucki added the needs-minor-release This PR cannot be merged until the next minor release label Feb 28, 2023
@Kordyjan Kordyjan added this to the 3.4.0 milestone Feb 28, 2023
@nicolasstucki nicolasstucki changed the title Add @binaryAPI Add @binaryAPI and @binaryAPIAccessor May 9, 2023
The `@binaryAPI`  annotation will make any package private or protected term definition public in the generated bytecode. Definitions that override an `@binaryAPI` will also become public.

We cannot annotate `private[this]` definitions because we might have different definitions with the same name and signature in a subclass. These would clash if made public. Instead of using private/private[this], the user can write `private[C]` where `C` is the enclosing class.

This is useful in combination with inline definitions. If an inline definition refers to a `private`/`protected` definition marked as `@binaryAPI` it does not need to use an accessor. We still generate the accessors for binary compatibility but do not use them.
In this case the annotation will generate a public accessor (and setter).
This accessor has a consistent name that avoids clashes (`<className>$inline$<definitionName>`).

It will have the same name as a private accessor that would have been generate
in a non final class by the old inline accessor generation.
Users should add the old accessor explicitly to keep binary compatibility.
This accessor should be `@binaryAPI private[C]` where `C` is the enclosing class.
* `@binaryAPI` makes the API public. Cannot be used on `private[this]`.
* `@binaryAPIAccessor` generates the private accessor.
In objects, we can use `inline$<definitionName>` for the name of this
accessor. This is the same name as would have been generated automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants