Skip to content

Commit 0cc6b48

Browse files
committed
Rename annotations
1 parent b4105f2 commit 0cc6b48

File tree

33 files changed

+96
-96
lines changed

33 files changed

+96
-96
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CompilationUnit protected (val source: SourceFile) {
4545
*/
4646
var needsInlining: Boolean = false
4747

48-
var hasMacroAnnotations: Boolean = false
48+
var hasTastyAnnotations: Boolean = false
4949

5050
/** Set to `true` if inliner added anonymous mirrors that need to be completed */
5151
var needsMirrorSupport: Boolean = false
@@ -121,7 +121,7 @@ object CompilationUnit {
121121
force.traverse(unit1.tpdTree)
122122
unit1.needsStaging = force.containsQuote
123123
unit1.needsInlining = force.containsInline
124-
unit1.hasMacroAnnotations = force.containsMacroAnnotation
124+
unit1.hasTastyAnnotations = force.containsTastyAnnotation
125125
}
126126
unit1
127127
}
@@ -150,7 +150,7 @@ object CompilationUnit {
150150
var containsQuote = false
151151
var containsInline = false
152152
var containsCaptureChecking = false
153-
var containsMacroAnnotation = false
153+
var containsTastyAnnotation = false
154154
def traverse(tree: Tree)(using Context): Unit = {
155155
if (tree.symbol.isQuote)
156156
containsQuote = true
@@ -165,8 +165,8 @@ object CompilationUnit {
165165
case _ =>
166166
case _ =>
167167
for annot <- tree.symbol.annotations do
168-
if annot.tree.symbol.denot != NoDenotation && annot.tree.symbol.owner.derivesFrom(defn.MacroAnnotationClass) then
169-
ctx.compilationUnit.hasMacroAnnotations = true
168+
if annot.tree.symbol.denot != NoDenotation && annot.tree.symbol.owner.derivesFrom(defn.TastyAnnotationClass) then
169+
ctx.compilationUnit.hasTastyAnnotations = true
170170
traverseChildren(tree)
171171
}
172172
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ class Definitions {
895895
@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
896896
@tu lazy val QuotedTypeModule_of: Symbol = QuotedTypeModule.requiredMethod("of")
897897

898-
@tu lazy val MacroAnnotationClass: ClassSymbol = requiredClass("scala.annotation.MacroAnnotation")
898+
@tu lazy val TastyAnnotationClass: ClassSymbol = requiredClass("scala.annotation.TastyAnnotation")
899899

900900
@tu lazy val CanEqualClass: ClassSymbol = getClassIfDefined("scala.Eql").orElse(requiredClass("scala.CanEqual")).asClass
901901
def CanEqual_canEqualAny(using Context): TermSymbol =

compiler/src/dotty/tools/dotc/transform/Inlining.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Inlining extends MacroTransform with IdentityDenotTransformer {
2828
override def changesMembers: Boolean = true
2929

3030
override def run(using Context): Unit =
31-
if ctx.compilationUnit.needsInlining || ctx.compilationUnit.hasMacroAnnotations then
31+
if ctx.compilationUnit.needsInlining || ctx.compilationUnit.hasTastyAnnotations then
3232
try super.run
3333
catch case _: CompilationUnit.SuspendException => ()
3434

@@ -69,9 +69,9 @@ class Inlining extends MacroTransform with IdentityDenotTransformer {
6969
else if
7070
!tree.symbol.isPrimaryConstructor
7171
&& StagingContext.level == 0
72-
&& MacroAnnotations.hasMacro(tree.symbol)
72+
&& TastyAnnotations.hasMacro(tree.symbol)
7373
then
74-
val trees = new MacroAnnotations(Inlining.this).transform(tree)
74+
val trees = new TastyAnnotations(Inlining.this).transform(tree)
7575
flatTree(trees.map(super.transform))
7676
else super.transform(tree)
7777
case _: Typed | _: Block =>

compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import scala.quoted.runtime.impl.{QuotesImpl, SpliceScope}
2020

2121
import scala.quoted.Quotes
2222

23-
class MacroAnnotations(thisPhase: DenotTransformer):
23+
class TastyAnnotations(thisPhase: DenotTransformer):
2424
import tpd.*
25-
import MacroAnnotations.*
25+
import TastyAnnotations.*
2626

2727
/** Expands every macro annotation that is on this tree.
2828
* Returns a list with transformed definition and any added definitions.
@@ -50,7 +50,7 @@ class MacroAnnotations(thisPhase: DenotTransformer):
5050

5151
// Apply all macro annotation to `tree` and collect new definitions in order
5252
val transformedTree: DefTree = tree.symbol.annotations.foldLeft(tree) { (tree, annot) =>
53-
if isMacroAnnotation(annot) then
53+
if isTastyAnnotation(annot) then
5454
debug.println(i"Expanding macro annotation: ${annot}")
5555

5656
// Interpret call to `new myAnnot(..).transform(using <Quotes>)(<tree>)`
@@ -81,16 +81,16 @@ class MacroAnnotations(thisPhase: DenotTransformer):
8181

8282
/** Interpret the code `new annot(..).transform(using <Quotes(ctx)>)(<tree>)` */
8383
private def callMacro(interpreter: Interpreter, tree: MemberDef, annot: Annotation)(using Context): List[MemberDef] =
84-
// TODO: Remove when scala.annaotaion.MacroAnnotation is no longer experimental
84+
// TODO: Remove when scala.annaotaion.TastyAnnotation is no longer experimental
8585
import scala.reflect.Selectable.reflectiveSelectable
86-
type MacroAnnotation = {
86+
type TastyAnnotation = {
8787
def transform(using Quotes)(tree: Object/*Erased type of quotes.refelct.Definition*/): List[MemberDef /*quotes.refelct.Definition known to be MemberDef in QuotesImpl*/]
8888
}
8989

9090
// Interpret macro annotation instantiation `new myAnnot(..)`
91-
val annotInstance = interpreter.interpret[MacroAnnotation](annot.tree).get
92-
// TODO: Remove when scala.annaotaion.MacroAnnotation is no longer experimental
93-
assert(annotInstance.getClass.getClassLoader.loadClass("scala.annotation.MacroAnnotation").isInstance(annotInstance))
91+
val annotInstance = interpreter.interpret[TastyAnnotation](annot.tree).get
92+
// TODO: Remove when scala.annaotaion.TastyAnnotation is no longer experimental
93+
assert(annotInstance.getClass.getClassLoader.loadClass("scala.annotation.TastyAnnotation").isInstance(annotInstance))
9494

9595
val quotes = QuotesImpl()(using SpliceScope.contextWithNewSpliceScope(tree.symbol.sourcePos)(using MacroExpansion.context(tree)).withOwner(tree.symbol))
9696
annotInstance.transform(using quotes)(tree.asInstanceOf[quotes.reflect.Definition])
@@ -107,13 +107,13 @@ class MacroAnnotations(thisPhase: DenotTransformer):
107107
else
108108
sym.enteredAfter(thisPhase)
109109

110-
object MacroAnnotations:
110+
object TastyAnnotations:
111111

112-
/** Is this an annotation that implements `scala.annation.MacroAnnotation` */
113-
def isMacroAnnotation(annot: Annotation)(using Context): Boolean =
112+
/** Is this an annotation that implements `scala.annation.TastyAnnotation` */
113+
def isTastyAnnotation(annot: Annotation)(using Context): Boolean =
114114
val sym = annot.tree.symbol
115-
sym.denot != NoDenotation && sym.owner.derivesFrom(defn.MacroAnnotationClass)
115+
sym.denot != NoDenotation && sym.owner.derivesFrom(defn.TastyAnnotationClass)
116116

117-
/** Is this symbol annotated with an annotation that implements `scala.annation.MacroAnnotation` */
117+
/** Is this symbol annotated with an annotation that implements `scala.annation.TastyAnnotation` */
118118
def hasMacro(sym: Symbol)(using Context): Boolean =
119-
sym.getAnnotation(defn.MacroAnnotationClass).isDefined
119+
sym.getAnnotation(defn.TastyAnnotationClass).isDefined

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
393393
if (sym.isClass)
394394
VarianceChecker.check(tree)
395395
annotateExperimental(sym)
396-
checkMacroAnnotation(sym)
396+
checkTastyAnnotation(sym)
397397
tree.rhs match
398398
case impl: Template =>
399399
for parent <- impl.parents do
@@ -488,13 +488,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
488488
if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs
489489

490490
private def checkForMacrosAnnotations(tree: Tree)(using Context) =
491-
if !ctx.compilationUnit.hasMacroAnnotations then
492-
ctx.compilationUnit.hasMacroAnnotations |=
493-
tree.symbol.annotations.exists(MacroAnnotations.isMacroAnnotation)
491+
if !ctx.compilationUnit.hasTastyAnnotations then
492+
ctx.compilationUnit.hasTastyAnnotations |=
493+
tree.symbol.annotations.exists(TastyAnnotations.isTastyAnnotation)
494494

495-
private def checkMacroAnnotation(sym: Symbol)(using Context) =
496-
if sym.derivesFrom(defn.MacroAnnotationClass) && !sym.isStatic then
497-
report.error("Implementation restriction: classes that extend MacroAnnotation must not be inner/local classes", sym.srcPos)
495+
private def checkTastyAnnotation(sym: Symbol)(using Context) =
496+
if sym.derivesFrom(defn.TastyAnnotationClass) && !sym.isStatic then
497+
report.error("Implementation restriction: classes that extend TastyAnnotation must not be inner/local classes", sym.srcPos)
498498

499499
private def checkErasedDef(tree: ValOrDefDef)(using Context): Unit =
500500
if tree.symbol.is(Erased, butNot = Macro) then

compiler/src/dotty/tools/dotc/transform/YCheckPositions.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class YCheckPositions extends Phase {
6161

6262
private def isMacro(call: Tree)(using Context) =
6363
call.symbol.is(Macro) ||
64-
(call.symbol.isClass && call.tpe.derivesFrom(defn.MacroAnnotationClass)) ||
64+
(call.symbol.isClass && call.tpe.derivesFrom(defn.TastyAnnotationClass)) ||
6565
// The call of a macro after typer is encoded as a Select while other inlines are Ident
6666
// TODO remove this distinction once Inline nodes of expanded macros can be trusted (also in Inliner.inlineCallTrace)
6767
(!(ctx.phase <= postTyperPhase) && call.isInstanceOf[Select])

library/src/scala/annotation/MacroAnnotation.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.quoted._
66

77
/** Base trait for macro annotation that will transform a definition */
88
@experimental
9-
trait MacroAnnotation extends StaticAnnotation:
9+
trait TastyAnnotation extends StaticAnnotation:
1010

1111
/** Transform the `tree` definition and add other definitions
1212
*
@@ -27,7 +27,7 @@ trait MacroAnnotation extends StaticAnnotation:
2727
* import scala.quoted.*
2828
* import scala.collection.mutable
2929
*
30-
* class memoize extends MacroAnnotation:
30+
* class memoize extends TastyAnnotation:
3131
* def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
3232
* import quotes.reflect._
3333
* tree match

tests/neg-macros/annot-MacroAnnotation-direct.check

-6
This file was deleted.

tests/neg-macros/annot-MacroAnnotation-direct.scala

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E042] Type Error: tests/neg-macros/annot-TastyAnnotation-direct.scala:3:0 ------------------------------------------
2+
3 |@TastyAnnotation // error
3+
|^^^^^^^^^^^^^^^^
4+
|TastyAnnotation is a trait; it cannot be instantiated
5+
|
6+
| longer explanation available when compiling with `-explain`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.annotation.TastyAnnotation
2+
3+
@TastyAnnotation // error
4+
def test = ()

tests/neg-macros/annot-accessIndirect/Macro_1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class hello extends MacroAnnotation {
5+
class hello extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
import quotes.reflect._
88
val helloSymbol = Symbol.newUniqueVal(tree.symbol.owner, "hello", TypeRepr.of[String], Flags.EmptyFlags, Symbol.noSymbol)

tests/neg-macros/annot-accessIndirect/Macro_2.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class foo extends MacroAnnotation {
5+
class foo extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
import quotes.reflect._
88
val s = '{@hello def foo1(x: Int): Int = x + 1;()}.asTerm
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class nilAnnot extends MacroAnnotation {
5+
class nilAnnot extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
Nil
88
}

tests/neg-macros/annot-error-annot/Macro_1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class error extends MacroAnnotation {
5+
class error extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
quotes.reflect.report.error("MACRO ERROR", tree.pos)
88
List(tree)

tests/neg-macros/annot-nested.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
class Foo:
55
@experimental
6-
class void extends MacroAnnotation: // error
6+
class void extends TastyAnnotation: // error
77
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
88

99
object Bar:
1010
@experimental
11-
class void extends MacroAnnotation: // error
11+
class void extends TastyAnnotation: // error
1212
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
1313

1414
class Foo2:
1515
@experimental
16-
trait void extends MacroAnnotation // error
16+
trait void extends TastyAnnotation // error
1717

1818
object Bar:
1919
@experimental
20-
trait void extends MacroAnnotation // error
20+
trait void extends TastyAnnotation // error
2121

2222
def test: Unit =
2323
@experimental
24-
class void extends MacroAnnotation: // error
24+
class void extends TastyAnnotation: // error
2525
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
2626

27-
trait void2 extends MacroAnnotation // error
27+
trait void2 extends TastyAnnotation // error
2828

29-
new MacroAnnotation {} // error
29+
new TastyAnnotation {} // error
3030

3131
()
3232

3333
val test2: Unit =
3434
@experimental
35-
class void extends MacroAnnotation: // error
35+
class void extends TastyAnnotation: // error
3636
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
3737

38-
trait void2 extends MacroAnnotation // error
38+
trait void2 extends TastyAnnotation // error
3939

40-
new MacroAnnotation {} // error
40+
new TastyAnnotation {} // error
4141

4242
()
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class voidAnnot extends MacroAnnotation {
5+
class voidAnnot extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
List(tree)
88
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class voidAnnot extends MacroAnnotation {
5+
class voidAnnot extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
List(tree)
88
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class voidAnnot extends MacroAnnotation {
5+
class voidAnnot extends TastyAnnotation {
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
List(tree)
88
}

tests/neg-macros/annot-result-owner/Macro_1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class insertVal extends MacroAnnotation:
5+
class insertVal extends TastyAnnotation:
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
import quotes.reflect._
88
// Use of wrong owner
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
object Foo:
55
@experimental
6-
class void extends MacroAnnotation:
6+
class void extends TastyAnnotation:
77
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
88

99
object Bar:
1010
@experimental
11-
class void extends MacroAnnotation:
11+
class void extends TastyAnnotation:
1212
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = List(tree)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class void extends MacroAnnotation:
5+
class void extends TastyAnnotation:
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
List(tree)

tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ val experimentalDefinitionInLibrary = Set(
6363
"scala.deriving.Mirror$.fromProductTyped", // This API is a bit convoluted. We may need some more feedback before we can stabilize it.
6464

6565
//// New feature: Macro annotations
66-
"scala.annotation.MacroAnnotation",
66+
"scala.annotation.TastyAnnotation",
6767

6868
//// New APIs: Quotes
6969
// Can be stabilized in 3.3.0 (unsure) or later

tests/run-macros/annot-annot-order/Macro_1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import scala.annotation.{experimental, MacroAnnotation}
1+
import scala.annotation.{experimental, TastyAnnotation}
22
import scala.quoted._
33

44
@experimental
5-
class print(msg: String) extends MacroAnnotation:
5+
class print(msg: String) extends TastyAnnotation:
66
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] =
77
import quotes.reflect._
88
tree match

0 commit comments

Comments
 (0)