Skip to content

Commit 9cde3dd

Browse files
committed
New annotation on inline accessors
scala.annottation.internal.Accessed indicates which symbol is accessed by an inline accessor.
1 parent 2a5abb3 commit 9cde3dd

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,26 @@ object Annotations {
146146
def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
147147
deferred(atp.classSymbol, implicit ctx => resolveConstructor(atp, args))
148148

149-
def makeAlias(sym: TermSymbol)(implicit ctx: Context) =
150-
apply(defn.AliasAnnot, List(
151-
ref(TermRef(sym.owner.thisType, sym.name, sym))))
149+
class TermRefAnnotExtractor(annotFn: Context => Symbol) {
152150

153-
/** Extractor for child annotations */
151+
def apply(sym: TermSymbol)(implicit ctx: Context): Annotation =
152+
Annotation(annotFn(ctx).typeRef, List(ref(TermRef(sym.owner.thisType, sym.name, sym))))
153+
154+
def unapply(ann: Annotation)(implicit ctx: Context): Option[Symbol] =
155+
if (ann.symbol == annotFn(ctx)) {
156+
val ast.Trees.Apply(fn, arg :: Nil) = ann.tree
157+
Some(arg.symbol)
158+
}
159+
else None
160+
}
161+
162+
/** Extractor for "accessed" annotations */
163+
object Accessed extends TermRefAnnotExtractor(implicit ctx => defn.AccessedAnnot)
164+
165+
/** Extractor for "aliased" annotations */
166+
object Alias extends TermRefAnnotExtractor(implicit ctx => defn.AliasAnnot)
167+
168+
/** Extractor for "child" annotations */
154169
object Child {
155170

156171
/** A deferred annotation to the result of a given child computation */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ class Definitions {
692692
// Annotation classes
693693
lazy val AliasAnnotType = ctx.requiredClassRef("scala.annotation.internal.Alias")
694694
def AliasAnnot(implicit ctx: Context) = AliasAnnotType.symbol.asClass
695+
lazy val AccessedAnnotType = ctx.requiredClassRef("scala.annotation.internal.Accessed")
696+
def AccessedAnnot(implicit ctx: Context) = AccessedAnnotType.symbol.asClass
695697
lazy val AnnotationDefaultAnnotType = ctx.requiredClassRef("scala.annotation.internal.AnnotationDefault")
696698
def AnnotationDefaultAnnot(implicit ctx: Context) = AnnotationDefaultAnnotType.symbol.asClass
697699
lazy val BodyAnnotType = ctx.requiredClassRef("scala.annotation.internal.Body")

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
578578
}
579579
}
580580
val alias = readDisambiguatedSymbolRef(disambiguate).asTerm
581-
denot.addAnnotation(Annotation.makeAlias(alias))
581+
denot.addAnnotation(Annotation.Alias(alias))
582582
}
583583
}
584584
// println(s"unpickled ${denot.debugString}, info = ${denot.info}") !!! DEBUG
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.annotation.internal
2+
3+
import scala.annotation.Annotation
4+
5+
/** An annotation to record the method accessed by an inline accessor.
6+
* @param aliased A TermRef pointing to the accessed method
7+
*/
8+
class Accessed(aliased: Any) extends Annotation

0 commit comments

Comments
 (0)