Skip to content

Commit 41bf75b

Browse files
committed
Split into @binaryAPI and @binaryAPIAccessor
* `@binaryAPI` makes the API public. Cannot be used on `private[this]`. * `@binaryAPIAccessor` generates the private accessor.
1 parent e080ad1 commit 41bf75b

File tree

27 files changed

+182
-103
lines changed

27 files changed

+182
-103
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import NameKinds.AvoidNameKind
1515
import util.SimpleIdentitySet
1616
import NullOpsDecorator.stripNull
1717

18-
import scala.annotation.binaryAPI
18+
import scala.annotation.{binaryAPI, binaryAPIAccessor}
1919

2020
/** Methods for adding constraints and solving them.
2121
*
@@ -112,7 +112,8 @@ trait ConstraintHandling {
112112
* of `1`. So the lower bound is `1 | x.M` and when we level-avoid that we
113113
* get `1 | Int & String`, which simplifies to `Int`.
114114
*/
115-
@binaryAPI private var myTrustBounds = true
115+
@binaryAPIAccessor
116+
private var myTrustBounds = true
116117

117118
inline def withUntrustedBounds(op: => Type): Type =
118119
val saved = myTrustBounds

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import classfile.ReusableDataReader
3030
import StdNames.nme
3131
import compiletime.uninitialized
3232

33-
import scala.annotation.binaryAPI
33+
import scala.annotation.{binaryAPI, binaryAPIAccessor}
3434
import scala.annotation.internal.sharable
3535

3636
import DenotTransformers.DenotTransformer
@@ -800,7 +800,7 @@ object Contexts {
800800
* Note: plain TypeComparers always take on the kind of the outer comparer if they are in the same context.
801801
* In other words: tracking or explaining is a sticky property in the same context.
802802
*/
803-
@binaryAPI
803+
@binaryAPIAccessor
804804
private def comparer(using Context): TypeComparer =
805805
util.Stats.record("comparing")
806806
val base = ctx.base

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ class Definitions {
10531053
@tu lazy val RetainsAnnot: ClassSymbol = requiredClass("scala.annotation.retains")
10541054
@tu lazy val RetainsByNameAnnot: ClassSymbol = requiredClass("scala.annotation.retainsByName")
10551055
@tu lazy val BinaryAPIAnnot: ClassSymbol = requiredClass("scala.annotation.binaryAPI")
1056+
@tu lazy val BinaryAPIAccessorAnnot: ClassSymbol = requiredClass("scala.annotation.binaryAPIAccessor")
10561057

10571058
@tu lazy val JavaRepeatableAnnot: ClassSymbol = requiredClass("java.lang.annotation.Repeatable")
10581059

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,13 @@ object SymDenotations {
10391039
def isBinaryAPI(using Context): Boolean =
10401040
isTerm && (
10411041
hasAnnotation(defn.BinaryAPIAnnot) ||
1042-
allOverriddenSymbols.exists(_.hasAnnotation(defn.BinaryAPIAnnot))
1042+
allOverriddenSymbols.exists(sym => sym.hasAnnotation(defn.BinaryAPIAnnot))
10431043
)
10441044

1045+
/** Is this a member that will have an accessor in the generated binary */
1046+
def isBinaryAPIAccessor(using Context): Boolean =
1047+
isTerm && hasAnnotation(defn.BinaryAPIAccessorAnnot)
1048+
10451049
/** ()T and => T types should be treated as equivalent for this symbol.
10461050
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,
10471051
* because the Scala library does not always follow the right conventions.

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import reporting.trace
2525
import annotation.constructorOnly
2626
import cc.{CapturingType, derivedCapturingType, CaptureSet, stripCapturing, isBoxedCapturing, boxed, boxedUnlessFun, boxedIfTypeParam, isAlwaysPure}
2727

28-
import scala.annotation.binaryAPI
28+
import scala.annotation.{binaryAPI, binaryAPIAccessor}
2929

3030
/** Provides methods to compare types.
3131
*/
@@ -158,7 +158,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
158158
private [this] var leftRoot: Type | Null = null
159159

160160
/** Are we forbidden from recording GADT constraints? */
161-
@binaryAPI private var frozenGadt = false
161+
@binaryAPIAccessor
162+
private var frozenGadt = false
162163
private inline def inFrozenGadt[T](inline op: T): T =
163164
inFrozenGadtIf(true)(op)
164165

@@ -189,7 +190,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
189190
inFrozenGadtIf(true)(inFrozenConstraint(op))
190191

191192
extension (sym: Symbol)
192-
@binaryAPI private inline def onGadtBounds(inline op: TypeBounds => Boolean): Boolean =
193+
@binaryAPIAccessor private inline def onGadtBounds(inline op: TypeBounds => Boolean): Boolean =
193194
val bounds = gadtBounds(sym)
194195
bounds != null && op(bounds)
195196

compiler/src/dotty/tools/dotc/inlines/PrepareInlineable.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object PrepareInlineable {
5858

5959
def accessorNameOf(accessed: Symbol, site: Symbol)(using Context): TermName =
6060
val accName = InlineAccessorName(accessed.name.asTermName)
61-
if site.isExtensibleClass || accessed.isBinaryAPI then accName.expandedName(site)
61+
if site.isExtensibleClass || accessed.isBinaryAPIAccessor then accName.expandedName(site)
6262
else accName
6363

6464
/** A definition needs an accessor if it is private, protected, or qualified private
@@ -74,7 +74,7 @@ object PrepareInlineable {
7474
def needsAccessor(sym: Symbol)(using Context): Boolean =
7575
sym.isTerm &&
7676
(sym.isOneOf(AccessFlags) || sym.privateWithin.exists) &&
77-
(!sym.isBinaryAPI || sym.is(Private)) &&
77+
!sym.isBinaryAPI &&
7878
!(sym.isStableMember && sym.info.widenTermRefExpr.isInstanceOf[ConstantType]) &&
7979
!sym.isInlineMethod &&
8080
(Inlines.inInlineMethod || StagingContext.level > 0)
@@ -110,13 +110,14 @@ object PrepareInlineable {
110110

111111
protected def unstableAccessorWarning(accessor: Symbol, accessed: Symbol, srcPos: SrcPos)(using Context): Unit =
112112
val accessorDefTree = accessorDef(accessor, accessed)
113+
val annot = if accessed.is(Private) then "@binaryAPIAccessor" else "@binaryAPI"
113114
val solution =
114115
if accessed.is(Private) then
115-
s"Annotate ${accessed.name} with `@binaryAPI` to generate a stable accessor."
116+
s"Annotate ${accessed.name} with `$annot` to generate a stable accessor."
116117
else
117-
s"Annotate ${accessed.name} with `@binaryAPI` to make it accessible."
118+
s"Annotate ${accessed.name} with `$annot` to make it accessible."
118119
val binaryCompat =
119-
s"""Adding @binaryAPI may break binary compatibility if a previous version of this
120+
s"""Adding $annot may break binary compatibility if a previous version of this
120121
|library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
121122
|using MiMa. To keep binary you can add the following accessor to ${accessor.owner.showKind} ${accessor.owner.name.stripModuleClassSuffix}:
122123
| @binaryAPI private[${accessor.owner.name.stripModuleClassSuffix}] ${accessorDefTree.show}
@@ -139,7 +140,7 @@ object PrepareInlineable {
139140
}
140141
else
141142
val accessorTree = useAccessor(tree)
142-
if !tree.symbol.isBinaryAPI && tree.symbol != accessorTree.symbol then
143+
if !tree.symbol.isBinaryAPI && !tree.symbol.isBinaryAPIAccessor && tree.symbol != accessorTree.symbol then
143144
unstableAccessorWarning(accessorTree.symbol, tree.symbol, tree.srcPos)
144145
accessorTree
145146
case _ =>
@@ -251,7 +252,6 @@ object PrepareInlineable {
251252

252253
/** Create an inline accessor for this definition. */
253254
def makePrivateBinaryAPIAccessor(sym: Symbol)(using Context): Unit =
254-
assert(sym.is(Private))
255255
if !sym.is(Accessor) then
256256
val ref = tpd.ref(sym).asInstanceOf[RefTree]
257257
val accessor = InsertPrivateBinaryAPIAccessors.useAccessor(ref)

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import config.Feature.{migrateTo3, fewerBracesEnabled}
2121
import config.SourceVersion.`3.0`
2222
import reporting.{NoProfile, Profile, Message}
2323

24-
import scala.annotation.binaryAPI
24+
import scala.annotation.binaryAPIAccessor
2525

2626
import java.util.Objects
2727

@@ -1598,7 +1598,8 @@ object Scanners {
15981598
protected def coversIndent(w: IndentWidth): Boolean =
15991599
knownWidth != null && w == indentWidth
16001600

1601-
@binaryAPI private var myCommasExpected: Boolean = false
1601+
@binaryAPIAccessor
1602+
private var myCommasExpected: Boolean = false
16021603

16031604
inline def withCommasExpected[T](inline op: => T): T =
16041605
val saved = myCommasExpected

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Decorators.{em, toMessage}
1818
import util.SourceFile
1919
import Utility._
2020

21-
import scala.annotation.binaryAPI
21+
import scala.annotation.binaryAPIAccessor
2222

2323
// XXX/Note: many/most of the functions in here are almost direct cut and pastes
2424
// from another file - scala.xml.parsing.MarkupParser, it looks like.
@@ -52,7 +52,7 @@ object MarkupParsers {
5252
override def getMessage: String = "input ended while parsing XML"
5353
}
5454

55-
class MarkupParser(@binaryAPI parser: Parser, final val preserveWS: Boolean)(using @binaryAPI c: Context) extends MarkupParserCommon {
55+
class MarkupParser(@binaryAPIAccessor parser: Parser, final val preserveWS: Boolean)(using @binaryAPIAccessor c: Context) extends MarkupParserCommon {
5656

5757
import Tokens.{ LBRACE, RBRACE }
5858

@@ -93,8 +93,8 @@ object MarkupParsers {
9393
var xEmbeddedBlock: Boolean = false
9494

9595
private var debugLastStartElement = List.empty[(Int, String)]
96-
@binaryAPI private def debugLastPos = debugLastStartElement.head._1
97-
@binaryAPI private def debugLastElem = debugLastStartElement.head._2
96+
@binaryAPIAccessor private def debugLastPos = debugLastStartElement.head._1
97+
@binaryAPIAccessor private def debugLastElem = debugLastStartElement.head._2
9898

9999
private def errorBraces() = {
100100
reportSyntaxError("in XML content, please use '}}' to express '}'")

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import dotty.tools.dotc.util.SourcePosition
3131
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}
3232
import cc.{CaptureSet, toCaptureSet, IllegalCaptureRef}
3333

34-
import scala.annotation.binaryAPI
34+
import scala.annotation.binaryAPIAccessor
3535

3636
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
3737

3838
/** A stack of enclosing DefDef, TypeDef, or ClassDef, or ModuleDefs nodes */
3939
private var enclosingDef: untpd.Tree = untpd.EmptyTree
40-
@binaryAPI private var myCtx: Context = super.printerContext
40+
@binaryAPIAccessor private var myCtx: Context = super.printerContext
4141
private var printPos = ctx.settings.YprintPos.value
4242
private val printLines = ctx.settings.printLines.value
4343

0 commit comments

Comments
 (0)