Skip to content

Commit c8afb18

Browse files
committed
Make Annotations use CFTs for functions with Context domain
1 parent 5c78f6a commit c8afb18

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,27 @@ object Annotations {
5151
def tree(using Context): Tree = t
5252
}
5353

54-
/** The context to use to evaluate an annotation */
55-
private def annotCtx(using Context): Context =
56-
// We should always produce the same annotation tree, no matter when the
57-
// annotation is evaluated. Setting the phase to a pre-transformation phase
58-
// seems to be enough to ensure this (note that after erasure, `ctx.typer`
59-
// will be the Erasure typer, but that doesn't seem to affect the annotation
60-
// trees we create, so we leave it as is)
61-
ctx.withPhaseNoLater(picklerPhase)
62-
6354
abstract class LazyAnnotation extends Annotation {
64-
protected var mySym: Symbol | (Context => Symbol)
55+
protected var mySym: Symbol | (Context ?=> Symbol)
6556
override def symbol(using parentCtx: Context): Symbol =
6657
assert(mySym != null)
6758
mySym match {
68-
case symFn: (Context => Symbol) @unchecked =>
59+
case symFn: (Context ?=> Symbol) @unchecked =>
6960
mySym = null
70-
mySym = symFn(annotCtx)
61+
mySym = atPhaseNoLater(picklerPhase)(symFn)
7162
case sym: Symbol if sym.defRunId != currentRunId(using parentCtx) =>
7263
mySym = sym.denot.current.symbol
7364
case _ =>
7465
}
7566
mySym.asInstanceOf[Symbol]
7667

77-
protected var myTree: Tree | (Context => Tree)
68+
protected var myTree: Tree | (Context ?=> Tree)
7869
def tree(using Context): Tree =
7970
assert(myTree != null)
8071
myTree match {
81-
case treeFn: (Context => Tree) @unchecked =>
72+
case treeFn: (Context ?=> Tree) @unchecked =>
8273
myTree = null
83-
myTree = treeFn(annotCtx)
74+
myTree = atPhaseNoLater(picklerPhase)(treeFn)
8475
case _ =>
8576
}
8677
myTree.asInstanceOf[Tree]
@@ -107,13 +98,13 @@ object Annotations {
10798

10899
abstract class LazyBodyAnnotation extends BodyAnnotation {
109100
// Copy-pasted from LazyAnnotation to avoid having to turn it into a trait
110-
protected var myTree: Tree | (Context => Tree)
101+
protected var myTree: Tree | (Context ?=> Tree)
111102
def tree(using Context): Tree =
112103
assert(myTree != null)
113104
myTree match {
114-
case treeFn: (Context => Tree) @unchecked =>
105+
case treeFn: (Context ?=> Tree) @unchecked =>
115106
myTree = null
116-
myTree = treeFn(annotCtx)
107+
myTree = atPhaseNoLater(picklerPhase)(treeFn)
117108
case _ =>
118109
}
119110
myTree.asInstanceOf[Tree]
@@ -125,7 +116,7 @@ object Annotations {
125116
object LazyBodyAnnotation {
126117
def apply(bodyFn: Context ?=> Tree): LazyBodyAnnotation =
127118
new LazyBodyAnnotation:
128-
protected var myTree: Tree | (Context => Tree) = ctx => bodyFn(using ctx)
119+
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => bodyFn(using ctx)
129120
}
130121

131122
object Annotation {
@@ -156,15 +147,15 @@ object Annotations {
156147
/** Create an annotation where the tree is computed lazily. */
157148
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
158149
new LazyAnnotation {
159-
protected var myTree: Tree | (Context => Tree) = ctx => treeFn(using ctx)
160-
protected var mySym: Symbol | (Context => Symbol) = sym
150+
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => treeFn(using ctx)
151+
protected var mySym: Symbol | (Context ?=> Symbol) = sym
161152
}
162153

163154
/** Create an annotation where the symbol and the tree are computed lazily. */
164155
def deferredSymAndTree(symFn: Context ?=> Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
165156
new LazyAnnotation {
166-
protected var mySym: Symbol | (Context => Symbol) = ctx => symFn(using ctx)
167-
protected var myTree: Tree | (Context => Tree) = ctx => treeFn(using ctx)
157+
protected var mySym: Symbol | (Context ?=> Symbol) = (using ctx) => symFn(using ctx)
158+
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => treeFn(using ctx)
168159
}
169160

170161
def deferred(atp: Type, args: List[Tree])(using Context): Annotation =

0 commit comments

Comments
 (0)