From be29c982e43261873a57149371a2d75966d14802 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 18 Oct 2016 00:27:56 +0200 Subject: Don't generate positions that can be reconstructed Don't generate positions that can be reconstructed from the initial position of a tree. --- src/dotty/tools/dotc/core/tasty/PositionPickler.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/tasty/PositionPickler.scala b/src/dotty/tools/dotc/core/tasty/PositionPickler.scala index 64552ef27..78c15eae2 100644 --- a/src/dotty/tools/dotc/core/tasty/PositionPickler.scala +++ b/src/dotty/tools/dotc/core/tasty/PositionPickler.scala @@ -54,9 +54,16 @@ class PositionPickler(pickler: TastyPickler, addrsOfTree: tpd.Tree => List[Addr] lastIndex = index lastPos = pos } + + /** True if x's position cannot be reconstructed automatically from its initialPos + */ + def needsPosition(x: Positioned) = + x.pos.toSynthetic != x.initialPos.toSynthetic || + x.isInstanceOf[WithLazyField[_]] || // initialPos is inaccurate for trees with lazy fields + x.isInstanceOf[Trees.PackageDef[_]] // package defs might be split into several Tasty files def traverse(x: Any): Unit = x match { case x: Tree @unchecked => - if (x.pos.exists /*&& x.pos.toSynthetic != x.initialPos.toSynthetic*/) { + if (x.pos.exists && needsPosition(x)) { nextTreeAddr(x) match { case Some(addr) => //println(i"pickling $x at $addr") @@ -65,7 +72,7 @@ class PositionPickler(pickler: TastyPickler, addrsOfTree: tpd.Tree => List[Addr] //println(i"no address for $x") } } - //else println(i"skipping $x") + //else if (x.pos.exists) println(i"skipping $x") x match { case x: MemberDef @unchecked => traverse(x.symbol.annotations.map(_.tree)) case _ => -- cgit v1.2.3