Skip to content

Commit 4124a4f

Browse files
committed
Do not force symbols of annotations when unpickling
This lead to stale symbol errors in `tasty_tools` because the symbol forcing was bringing forward symbols from the previous run before the corresponding symbols for the current run were created. We fix this by adding Annotations#deferredSymAndTree which behaves similarly to Annotations#deferred but take a by-name symbol. We also remove TreeUnpickler#LazyAnnotationReader which was apparently never used.
1 parent bded3aa commit 4124a4f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ object Annotations {
3434
def tree(implicit ctx: Context): Tree = t
3535
}
3636

37-
abstract case class LazyAnnotation(sym: Symbol) extends Annotation {
37+
abstract class LazyAnnotation extends Annotation {
38+
override def symbol(implicit ctx: Context): Symbol
39+
def complete(implicit ctx: Context): Tree
40+
3841
private var myTree: Tree = null
3942
def tree(implicit ctx: Context) = {
4043
if (myTree == null) myTree = complete(ctx)
4144
myTree
4245
}
43-
def complete(implicit ctx: Context): Tree
44-
override def symbol(implicit ctx: Context): Symbol = sym
4546
}
4647

4748
/** An annotation indicating the body of a right-hand side,
@@ -108,8 +109,19 @@ object Annotations {
108109
apply(resolveConstructor(atp, args))
109110
}
110111

112+
/** Create an annotation where the tree is computed lazily. */
111113
def deferred(sym: Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
112-
new LazyAnnotation(sym) {
114+
new LazyAnnotation {
115+
override def symbol(implicit ctx: Context): Symbol = sym
116+
def complete(implicit ctx: Context) = treeFn(ctx)
117+
}
118+
119+
/** Create an annotation where the symbol and the tree are computed lazily. */
120+
def deferredSymAndTree(sym: => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
121+
new LazyAnnotation {
122+
lazy val symf = sym
123+
124+
override def symbol(implicit ctx: Context): Symbol = symf
113125
def complete(implicit ctx: Context) = treeFn(ctx)
114126
}
115127

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
541541
case ANNOTATION =>
542542
readByte()
543543
val end = readEnd()
544-
val sym = readType().typeSymbol
544+
val tp = readType()
545545
val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
546-
annots += Annotation.deferred(sym, _ => lazyAnnotTree.complete)
546+
annots += Annotation.deferredSymAndTree(tp.typeSymbol, _ => lazyAnnotTree.complete)
547547
case _ =>
548548
assert(false, s"illegal modifier tag at $currentAddr")
549549
}
@@ -1043,12 +1043,6 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
10431043
}
10441044
}
10451045

1046-
class LazyAnnotationReader(sym: Symbol, reader: TreeReader) extends LazyAnnotation(sym) {
1047-
def complete(implicit ctx: Context) = {
1048-
reader.readTerm()(ctx.withPhaseNoLater(ctx.picklerPhase))
1049-
}
1050-
}
1051-
10521046
/** A lazy datastructure that records how definitions are nested in TASTY data.
10531047
* The structure is lazy because it needs to be computed only for forward references
10541048
* to symbols that happen before the referenced symbol is created (see `symbolAt`).

0 commit comments

Comments
 (0)