@@ -48,16 +48,33 @@ object Annotations {
48
48
}
49
49
50
50
abstract class LazyAnnotation extends Annotation {
51
- override def symbol (implicit ctx : Context ): Symbol
52
- def complete (implicit ctx : Context ): Tree
53
-
54
- private var myTree : Tree = null
55
- def tree (implicit ctx : Context ): Tree = {
56
- if (myTree == null ) myTree = complete(ctx)
57
- myTree
58
- }
51
+ protected var mySym : Symbol | (Context => Symbol )
52
+ override def symbol (using ctx : Context ): Symbol =
53
+ assert(mySym != null )
54
+ mySym match {
55
+ case symFn : (Context => Symbol ) @ unchecked =>
56
+ val fn = symFn
57
+ mySym = null
58
+ mySym = fn(ctx)
59
+ case sym : Symbol if sym.defRunId != ctx.runId =>
60
+ mySym = sym.denot.current.symbol
61
+ case _ =>
62
+ }
63
+ mySym.asInstanceOf [Symbol ]
64
+
65
+ protected var myTree : Tree | (Context => Tree )
66
+ def tree (using ctx : Context ): Tree =
67
+ assert(myTree != null )
68
+ myTree match {
69
+ case treeFn : (Context => Tree ) @ unchecked =>
70
+ val fn = treeFn
71
+ myTree = null
72
+ myTree = fn(ctx)
73
+ case _ =>
74
+ }
75
+ myTree.asInstanceOf [Tree ]
59
76
60
- override def isEvaluated : Boolean = myTree != null
77
+ override def isEvaluated : Boolean = myTree. isInstanceOf [ Tree ]
61
78
}
62
79
63
80
/** An annotation indicating the body of a right-hand side,
@@ -120,23 +137,15 @@ object Annotations {
120
137
/** Create an annotation where the tree is computed lazily. */
121
138
def deferred (sym : Symbol )(treeFn : Context ?=> Tree )(implicit ctx : Context ): Annotation =
122
139
new LazyAnnotation {
123
- override def symbol ( implicit ctx : Context ) : Symbol = sym
124
- def complete ( implicit ctx : Context ) = treeFn( using ctx)
140
+ protected var myTree : Tree | ( Context => Tree ) = ctx => treeFn( using ctx)
141
+ protected var mySym : Symbol | ( Context => Symbol ) = sym
125
142
}
126
143
127
144
/** Create an annotation where the symbol and the tree are computed lazily. */
128
- def deferredSymAndTree (symf : Context ?=> Symbol )(treeFn : Context ?=> Tree )(implicit ctx : Context ): Annotation =
145
+ def deferredSymAndTree (symFn : Context ?=> Symbol )(treeFn : Context ?=> Tree )(implicit ctx : Context ): Annotation =
129
146
new LazyAnnotation {
130
- private var mySym : Symbol = _
131
-
132
- override def symbol (implicit ctx : Context ): Symbol = {
133
- if (mySym == null || mySym.defRunId != ctx.runId) {
134
- mySym = symf(using ctx)
135
- assert(mySym != null )
136
- }
137
- mySym
138
- }
139
- def complete (implicit ctx : Context ) = treeFn(using ctx)
147
+ protected var mySym : Symbol | (Context => Symbol ) = ctx => symFn(using ctx)
148
+ protected var myTree : Tree | (Context => Tree ) = ctx => treeFn(using ctx)
140
149
}
141
150
142
151
def deferred (atp : Type , args : List [Tree ])(implicit ctx : Context ): Annotation =
0 commit comments