-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. 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. If the linting option `-WunstableInlineAccessors` is enabled, then a warning will be emitted if an inline accessor is generated. The warning will guide the user to the use of `@binaryAPI`. For SIP: scala/improvement-proposals#58
- Loading branch information
1 parent
ca6a80e
commit a696e00
Showing
27 changed files
with
1,178 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
compiler/src/dotty/tools/dotc/transform/BinaryAPIAnnotations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dotty.tools.dotc.transform | ||
|
||
import dotty.tools.dotc.core.Contexts.* | ||
import dotty.tools.dotc.core.DenotTransformers.SymTransformer | ||
import dotty.tools.dotc.core.Flags.* | ||
import dotty.tools.dotc.core.Symbols.NoSymbol | ||
import dotty.tools.dotc.core.SymDenotations.SymDenotation | ||
import dotty.tools.dotc.transform.MegaPhase.MiniPhase | ||
import dotty.tools.dotc.typer.RefChecks | ||
|
||
/** Makes @binaryAPI definitions public. | ||
* | ||
* This makes it possible to elide the generations of some unnecessary accessors. | ||
*/ | ||
class BinaryAPIAnnotations extends MiniPhase with SymTransformer: | ||
|
||
override def runsAfterGroupsOf: Set[String] = Set(RefChecks.name) | ||
|
||
override def phaseName: String = BinaryAPIAnnotations.name | ||
override def description: String = BinaryAPIAnnotations.description | ||
|
||
def transformSym(d: SymDenotation)(using Context): SymDenotation = { | ||
if d.isBinaryAPI then | ||
d.resetFlag(Protected) | ||
d.setPrivateWithin(NoSymbol) | ||
if d.is(Module) then | ||
val moduleClass = d.moduleClass | ||
moduleClass.resetFlag(Protected) | ||
moduleClass.setPrivateWithin(NoSymbol) | ||
d | ||
} | ||
|
||
object BinaryAPIAnnotations: | ||
val name: String = "binaryAPIAnnotations" | ||
val description: String = "makes @binaryAPI definitions public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.