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

Get rid of suppressions for "invisible_reference" and "invisible_member" #618

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

psteiger
Copy link
Contributor

@psteiger psteiger commented Sep 21, 2023

For accessing internal declarations from "friend" modules (e.g. access rib-base internals from rib-test), we are currently suppressing compiler errors with @file:Suppress("invisible_reference", "invisible_member")

A better approach is to:

  1. Create an internal opt-in annotation.
  2. Make the "accessible to friend modules" component public
  3. Mark the (now public) component with the opt-in annotation.
  4. Opt-in to the annotation from build.gradle.

Because the new annotation is internal, it cannot be normally accessed from external modules. But Gradle can see it if it's part of the source set.

Benefits:

  1. We get rid of the hacky suppressions in our codebase.
  2. By suppressing invisible_reference and invisible_member we gain access to all internal components from the other modules, and that's not ideal: we'd rather be explicit about what are the APIs that are visible for module friends, and what are truly internal for the module and should never be used even from module friends.
  3. We make the internal visibility of those friend-modules APIs even stricter, since consumers from the general public now cannot just suppress "invisible_reference" and "invisible_member" to directly access the friend-module API -- they require explicit Opt-In. They would need to suppress invisible members AND opt-in.

@psteiger
Copy link
Contributor Author

Note: this is the same approach now being used in KotlinX libraries: Kotlin/kotlinx.serialization#2444

For accessing internal declarations from other modules (e.g. access `rib-base` internals from `rib-test`), we are currently suppressing compiler errors with `@file:Suppress("invisible_reference", "invisible_member")`

A better approach is to:
1. Create an `internal` opt-in annotation.
2. Make the "accessible to friend modules" component `public`
3. Mark the (now public) component with the opt-in annotation.
4. Opt-in to the annotation from `build.gradle`.

Because the new annotation is `internal`, it cannot be normally accessed from external modules. But Gradle can see it if it's part of the source set.

This makes the internal visibility of those friend-modules APIs even stricter, since consumers now cannot just suppress `"invisible_reference"` and `"invisible_member"` to directly access the friend-module API. Plus, we get rid of the hacky suppressions in our codebase.
@psteiger psteiger merged commit adc3b0d into uber:main Sep 22, 2023
2 checks passed
@psteiger psteiger deleted the friend branch September 22, 2023 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants