Skip to content

Commit 118f419

Browse files
committed
Rename @Alpha to @TargetNAME
1 parent 24f018d commit 118f419

File tree

27 files changed

+81
-79
lines changed

27 files changed

+81
-79
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class ScalaSettings extends Settings.SettingGroup {
173173
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
174174
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
175175
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ycheck-init", "Check initialization of objects")
176-
val YrequireAlpha: Setting[Boolean] = BooleanSetting("-Yrequire-alpha", "Warn if an operator is defined without an @alpha annotation")
176+
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
177177

178178
/** Area-specific debug output */
179179
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ class Definitions {
937937
@tu lazy val ShowAsInfixAnnot: ClassSymbol = requiredClass("scala.annotation.showAsInfix")
938938
@tu lazy val FunctionalInterfaceAnnot: ClassSymbol = requiredClass("java.lang.FunctionalInterface")
939939
@tu lazy val InfixAnnot: ClassSymbol = requiredClass("scala.annotation.infix")
940-
@tu lazy val AlphaAnnot: ClassSymbol = requiredClass("scala.annotation.alpha")
940+
@tu lazy val TargetNameAnnot: ClassSymbol = requiredClass("scala.annotation.targetName")
941941
@tu lazy val VarargsAnnot: ClassSymbol = requiredClass("scala.annotation.varargs")
942942

943943
// A list of annotations that are commonly used to indicate that a field/method argument or return

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,26 +495,21 @@ object SymDenotations {
495495
/** `fullName` where `.' is the separator character */
496496
def fullName(using Context): Name = fullNameSeparated(QualifiedName)
497497

498-
/** The name given in an `@alpha` annotation if one is present, `name` otherwise */
498+
/** The name given in a `@targetName` annotation if one is present, `name` otherwise */
499499
final def erasedName(using Context): Name =
500-
val alphaAnnot =
501-
if isAllOf(ModuleClass | Synthetic) then companionClass.getAnnotation(defn.AlphaAnnot)
502-
else getAnnotation(defn.AlphaAnnot)
503-
alphaAnnot match {
500+
val targetNameAnnot =
501+
if isAllOf(ModuleClass | Synthetic) then companionClass.getAnnotation(defn.TargetNameAnnot)
502+
else getAnnotation(defn.TargetNameAnnot)
503+
targetNameAnnot match
504504
case Some(ann) =>
505-
ann.arguments match {
505+
ann.arguments match
506506
case Literal(Constant(str: String)) :: Nil =>
507-
if (isType)
508-
if (is(ModuleClass))
509-
str.toTypeName.moduleClassName
510-
else
511-
str.toTypeName
512-
else
513-
str.toTermName
507+
if isType then
508+
if is(ModuleClass) then str.toTypeName.moduleClassName
509+
else str.toTypeName
510+
else str.toTermName
514511
case _ => name
515-
}
516512
case _ => name
517-
}
518513

519514
// ----- Tests -------------------------------------------------
520515

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,20 @@ object Checking {
308308
}
309309
}
310310

311-
/** If `sym` has an operator name, check that it has an @alpha annotation in 3.1 and later
311+
/** Under -Yrequire-targetName, if `sym` has an operator name, check that it has a
312+
* @targetName annotation.
312313
*/
313314
def checkValidOperator(sym: Symbol)(using Context): Unit =
314-
if ctx.settings.YrequireAlpha.value then
315+
if ctx.settings.YrequireTargetName.value then
315316
sym.name.toTermName match
316317
case name: SimpleName
317318
if name.isOperatorName
318319
&& !name.isSetterName
319320
&& !name.isConstructorName
320-
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
321+
&& !sym.getAnnotation(defn.TargetNameAnnot).isDefined
321322
&& !sym.is(Synthetic) =>
322323
report.warning(
323-
i"$sym has an operator name; it should come with an @alpha annotation", sym.srcPos)
324+
i"$sym has an operator name; it should come with an @targetName annotation", sym.srcPos)
324325
case _ =>
325326

326327
/** Check that `info` of symbol `sym` is not cyclic.
@@ -1203,19 +1204,16 @@ trait Checking {
12031204
}
12041205

12051206
/** Check that symbol's external name does not clash with symbols defined in the same scope */
1206-
def checkNoAlphaConflict(stats: List[Tree])(using Context): Unit = {
1207+
def checkNoTargetNameConflict(stats: List[Tree])(using Context): Unit =
12071208
var seen = Set[Name]()
1208-
for (stat <- stats) {
1209+
for stat <- stats do
12091210
val sym = stat.symbol
12101211
val ename = sym.erasedName
1211-
if (ename != sym.name) {
1212+
if ename != sym.name then
12121213
val preExisting = ctx.effectiveScope.lookup(ename)
1213-
if (preExisting.exists || seen.contains(ename))
1214-
report.error(em"@alpha annotation ${'"'}$ename${'"'} clashes with other definition is same scope", stat.srcPos)
1214+
if preExisting.exists || seen.contains(ename) then
1215+
report.error(em"@targetName annotation ${'"'}$ename${'"'} clashes with other definition in same scope", stat.srcPos)
12151216
if stat.isDef then seen += ename
1216-
}
1217-
}
1218-
}
12191217
}
12201218

12211219
trait ReChecking extends Checking {
@@ -1238,7 +1236,7 @@ trait NoChecking extends ReChecking {
12381236
override def checkImplicitConversionUseOK(tree: Tree)(using Context): Unit = ()
12391237
override def checkFeasibleParent(tp: Type, pos: SrcPos, where: => String = "")(using Context): Type = tp
12401238
override def checkInlineConformant(tpt: Tree, tree: Tree, sym: Symbol)(using Context): Unit = ()
1241-
override def checkNoAlphaConflict(stats: List[Tree])(using Context): Unit = ()
1239+
override def checkNoTargetNameConflict(stats: List[Tree])(using Context): Unit = ()
12421240
override def checkParentCall(call: Tree, caller: ClassSymbol)(using Context): Unit = ()
12431241
override def checkSimpleKinded(tpt: Tree)(using Context): Tree = tpt
12441242
override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(using Context): Unit = ()

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ object RefChecks {
433433
overrideError("has incompatible type" + err.whyNoMatchStr(memberTp(self), otherTp(self)))
434434
else if (member.erasedName != other.erasedName)
435435
if (other.erasedName != other.name)
436-
overrideError(i"needs to be declared with @alpha(${"\""}${other.erasedName}${"\""}) so that external names match")
436+
overrideError(i"needs to be declared with @targetName(${"\""}${other.erasedName}${"\""}) so that external names match")
437437
else
438-
overrideError("cannot have an @alpha annotation since external names would be different")
438+
overrideError("cannot have a @targetName annotation since external names would be different")
439439
else
440440
checkOverrideDeprecated()
441441
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ class Typer extends Namer
19821982
if (sym.isConstructor && !sym.isPrimaryConstructor) {
19831983
val ename = sym.erasedName
19841984
if (ename != sym.name)
1985-
report.error(em"@alpha annotation ${'"'}$ename${'"'} may not be used on a constructor", ddef.srcPos)
1985+
report.error(em"@targetName annotation may not be used on a constructor", ddef.srcPos)
19861986

19871987
for (param <- tparams1 ::: vparamss1.flatten)
19881988
checkRefsLegal(param, sym.owner, (name, sym) => sym.is(TypeParam), "secondary constructor")
@@ -2665,7 +2665,7 @@ class Typer extends Namer
26652665
}
26662666
val (stats0, finalCtx) = traverse(stats)(using localCtx)
26672667
val stats1 = stats0.mapConserve(finalize)
2668-
if (ctx.owner == exprOwner) checkNoAlphaConflict(stats1)
2668+
if ctx.owner == exprOwner then checkNoTargetNameConflict(stats1)
26692669
(stats1, finalCtx)
26702670
}
26712671

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class CompilationTests {
153153
defaultOptions),
154154
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes),
155155
compileFile("tests/neg-custom-args/infix.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
156-
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-alpha", "-Xfatal-warnings")),
156+
compileFile("tests/neg-custom-args/missing-alpha.scala", defaultOptions.and("-Yrequire-targetName", "-Xfatal-warnings")),
157157
compileFile("tests/neg-custom-args/wildcards.scala", defaultOptions.and("-source", "3.1", "-deprecation", "-Xfatal-warnings")),
158158
compileFile("tests/neg-custom-args/indentRight.scala", defaultOptions.and("-noindent", "-Xfatal-warnings")),
159159
compileFile("tests/neg-custom-args/extmethods-tparams.scala", defaultOptions.and("-deprecation", "-Xfatal-warnings")),

library/src/scala/annotation/alpha.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ package scala.annotation
66
* the regular name. An `alpha` annotation is mandatory for definitions
77
* with symbolic names.
88
*/
9+
@deprecated("use @targetName instead")
910
final class alpha(externalName: String) extends StaticAnnotation
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.annotation
2+
3+
/** An annotation that defines an external name for a definition.
4+
* If an `targetName(extname)` annotation is given for a method or some other
5+
* definition, its implementation will use the name `extname` instead of
6+
* the regular name.
7+
*/
8+
final class targetName(name: String) extends StaticAnnotation

tests/neg-custom-args/missing-alpha.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Compile with -strict -Xfatal-warnings -deprecation
2-
import scala.annotation.alpha
2+
import scala.annotation.targetName
33
class & { // error
44

5-
@alpha("op") def *(x: Int): Int = ??? // OK
5+
@targetName("op") def *(x: Int): Int = ??? // OK
66
def / (x: Int): Int // error
77
val frozen_& : Int = ??? // error
88
object some_??? // error

0 commit comments

Comments
 (0)