diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2016-11-14 23:50:57 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2016-11-22 01:35:08 +0100 |
commit | 3693211aafb3253c0f4608c84c285f5572d5ad6a (patch) | |
tree | f7858bf5e17a73132d4993dc6c00a3a4aef0143a /compiler/src/dotty/tools/dotc/core | |
parent | 830d4699e4ad8d866fa0c109697f0eebd99b3ecd (diff) | |
download | dotty-3693211aafb3253c0f4608c84c285f5572d5ad6a.tar.gz dotty-3693211aafb3253c0f4608c84c285f5572d5ad6a.tar.bz2 dotty-3693211aafb3253c0f4608c84c285f5572d5ad6a.zip |
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.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Annotations.scala | 20 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 10 |
2 files changed, 18 insertions, 12 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 0e8e5a1f0..985b1ea3d 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -34,14 +34,15 @@ object Annotations { def tree(implicit ctx: Context): Tree = t } - abstract case class LazyAnnotation(sym: Symbol) extends Annotation { + abstract class LazyAnnotation extends Annotation { + override def symbol(implicit ctx: Context): Symbol + def complete(implicit ctx: Context): Tree + private var myTree: Tree = null def tree(implicit ctx: Context) = { if (myTree == null) myTree = complete(ctx) myTree } - def complete(implicit ctx: Context): Tree - override def symbol(implicit ctx: Context): Symbol = sym } /** An annotation indicating the body of a right-hand side, @@ -108,8 +109,19 @@ object Annotations { apply(resolveConstructor(atp, args)) } + /** Create an annotation where the tree is computed lazily. */ def deferred(sym: Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation = - new LazyAnnotation(sym) { + new LazyAnnotation { + override def symbol(implicit ctx: Context): Symbol = sym + def complete(implicit ctx: Context) = treeFn(ctx) + } + + /** Create an annotation where the symbol and the tree are computed lazily. */ + def deferredSymAndTree(sym: => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation = + new LazyAnnotation { + lazy val symf = sym + + override def symbol(implicit ctx: Context): Symbol = symf def complete(implicit ctx: Context) = treeFn(ctx) } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 1d23a902a..6fcc2fcaa 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -552,9 +552,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle case ANNOTATION => readByte() val end = readEnd() - val sym = readType().typeSymbol + val tp = readType() val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx)) - annots += Annotation.deferred(sym, _ => lazyAnnotTree.complete) + annots += Annotation.deferredSymAndTree(tp.typeSymbol, _ => lazyAnnotTree.complete) case _ => assert(false, s"illegal modifier tag at $currentAddr") } @@ -1103,12 +1103,6 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle } } - class LazyAnnotationReader(sym: Symbol, reader: TreeReader) extends LazyAnnotation(sym) { - def complete(implicit ctx: Context) = { - reader.readTerm()(ctx.withPhaseNoLater(ctx.picklerPhase)) - } - } - /** A lazy datastructure that records how definitions are nested in TASTY data. * The structure is lazy because it needs to be computed only for forward references * to symbols that happen before the referenced symbol is created (see `symbolAt`). |