aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-03-08 11:03:29 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:15:47 +0100
commit5a43cb120f33328fdc755488684240dbd517283f (patch)
tree4247fb76e5b85e75e33d925949fc6d3deb35b2a7
parentf1ffa4c0a0a32057795c4395aecd990c6ae057e2 (diff)
downloaddotty-5a43cb120f33328fdc755488684240dbd517283f.tar.gz
dotty-5a43cb120f33328fdc755488684240dbd517283f.tar.bz2
dotty-5a43cb120f33328fdc755488684240dbd517283f.zip
Pickle shadowed names
Shadowed names in types need to be pickled and treated on unpickling. We choose to make Shadowed a separate TastyName class, to avoid the ad-hoc name-mangling in current dotc. When names are redone Shadowed will also become a special class in the compiler proper.
-rw-r--r--src/dotty/tools/dotc/core/pickling/NameBuffer.scala13
-rw-r--r--src/dotty/tools/dotc/core/pickling/PickleFormat.scala2
-rw-r--r--src/dotty/tools/dotc/core/pickling/TastyName.scala1
-rw-r--r--src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala2
-rw-r--r--src/dotty/tools/dotc/core/pickling/TreePickler.scala10
-rw-r--r--src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala12
-rw-r--r--tests/pos/pickleOK/templateParents.scala3
7 files changed, 35 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/NameBuffer.scala b/src/dotty/tools/dotc/core/pickling/NameBuffer.scala
index 70d6b9ee1..c72df5563 100644
--- a/src/dotty/tools/dotc/core/pickling/NameBuffer.scala
+++ b/src/dotty/tools/dotc/core/pickling/NameBuffer.scala
@@ -5,7 +5,7 @@ package pickling
import collection.mutable
import Names.{Name, chrs}
-import Decorators._
+import Decorators._, NameOps._
import TastyBuffer._
import scala.io.Codec
import TastyName._
@@ -23,7 +23,13 @@ class NameBuffer extends TastyBuffer(100000) {
nameRefs(name) = ref
ref
}
- def nameIndex(name: Name): NameRef = nameIndex(Simple(name.toTermName))
+ def nameIndex(name: Name): NameRef = {
+ val tname =
+ if (name.isShadowedName) Shadowed(nameIndex(name.revertShadowed))
+ else Simple(name.toTermName)
+ nameIndex(tname)
+ }
+
def nameIndex(str: String): NameRef = nameIndex(str.toTermName)
private def withLength(op: => Unit): Unit = {
@@ -63,6 +69,9 @@ class NameBuffer extends TastyBuffer(100000) {
case DefaultGetter(method, paramNumber) =>
writeByte(DEFAULTGETTER)
withLength { writeNameRef(method); writeNat(paramNumber) }
+ case Shadowed(original) =>
+ writeByte(SHADOWED)
+ withLength { writeNameRef(original) }
}
override def assemble(): Unit = {
diff --git a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala
index 3338c355e..68751f75f 100644
--- a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala
+++ b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala
@@ -36,6 +36,7 @@ Macro-format:
MODULECLASS Length module_NameRef
SUPERACCESSOR Length accessed_NameRef
DEFAULTGETTER Length method_NameRef paramNumber_Nat
+ SHADOWED Length original_NameRef
MANGLED Length mangle_NameRef name_NameRef
...
@@ -220,6 +221,7 @@ object PickleFormat {
final val MODULECLASS = 5
final val SUPERACCESSOR = 6
final val DEFAULTGETTER = 7
+ final val SHADOWED = 8
// AST tags
diff --git a/src/dotty/tools/dotc/core/pickling/TastyName.scala b/src/dotty/tools/dotc/core/pickling/TastyName.scala
index 581a87901..8508d7ffa 100644
--- a/src/dotty/tools/dotc/core/pickling/TastyName.scala
+++ b/src/dotty/tools/dotc/core/pickling/TastyName.scala
@@ -19,6 +19,7 @@ object TastyName {
case class ModuleClass(module: NameRef) extends TastyName
case class SuperAccessor(accessed: NameRef) extends TastyName
case class DefaultGetter(method: NameRef, num: Int) extends TastyName
+ case class Shadowed(original: NameRef) extends TastyName
class Table extends (NameRef => TastyName) {
private val names = new mutable.ArrayBuffer[TastyName]
diff --git a/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala b/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala
index b67244e3b..d90dd2e32 100644
--- a/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala
@@ -58,6 +58,8 @@ class TastyUnpickler(reader: TastyReader) {
SuperAccessor(readNameRef())
case DEFAULTGETTER =>
DefaultGetter(readNameRef(), readNat())
+ case SHADOWED =>
+ Shadowed(readNameRef())
}
assert(currentAddr == end, s"bad name $result $start $currentAddr $end")
result
diff --git a/src/dotty/tools/dotc/core/pickling/TreePickler.scala b/src/dotty/tools/dotc/core/pickling/TreePickler.scala
index 3004043d5..7ffcaec6e 100644
--- a/src/dotty/tools/dotc/core/pickling/TreePickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/TreePickler.scala
@@ -6,7 +6,7 @@ package pickling
import ast.Trees._
import PickleFormat._
import core._
-import Contexts._, Symbols._, Types._, Names._, Constants._, Decorators._, Annotations._, StdNames.tpnme
+import Contexts._, Symbols._, Types._, Names._, Constants._, Decorators._, Annotations._, StdNames.tpnme, NameOps._
import collection.mutable
import TastyBuffer._
@@ -296,9 +296,13 @@ class TreePickler(pickler: TastyPickler) {
pickleType(tree.tpe)
case Select(qual, name) =>
writeByte(SELECT)
+ val realName = tree.tpe match {
+ case tp: NamedType if tp.name.isShadowedName => tp.name
+ case _ => name
+ }
val sig = tree.tpe.signature
- if (sig == Signature.NotAMethod) pickleName(name)
- else pickleNameAndSig(name, sig)
+ if (sig == Signature.NotAMethod) pickleName(realName)
+ else pickleNameAndSig(realName, sig)
pickleTree(qual)
case Apply(fun, args) =>
writeByte(APPLY)
diff --git a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala
index 9e18a9a6c..d7d53c3a9 100644
--- a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala
@@ -69,6 +69,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
case Simple(name) => name
case Qualified(qual, name) => toTermName(qual) ++ "." ++ toTermName(name)
case Signed(original, params, result) => toTermName(original)
+ case Shadowed(original) => toTermName(original).shadowedName
case Expanded(original) => ???
case ModuleClass(original) => toTermName(original).moduleClassName.toTermName
case SuperAccessor(accessed) => ???
@@ -686,10 +687,17 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
if (name == nme.CONSTRUCTOR) ctx.fresh.addMode(Mode.InSuperCall) else ctx
readTerm()(localCtx)
}
+ def readRest(name: Name, sig: Signature) = {
+ val unshadowed = if (name.isShadowedName) name.revertShadowed else name
+ val sel = readQual(unshadowed).selectWithSig(unshadowed, sig)
+ if (unshadowed != name) sel.withType(sel.tpe.asInstanceOf[NamedType].shadowed)
+ else sel
+ }
readNameSplitSig match {
- case name: Name => readQual(name).selectWithSig(name, Signature.NotAMethod)
- case (name: Name, sig: Signature) => readQual(name).selectWithSig(name, sig)
+ case name: Name => readRest(name, Signature.NotAMethod)
+ case (name: Name, sig: Signature) => readRest(name, sig)
}
+
case NEW =>
New(readTpt())
case EMPTYTREE =>
diff --git a/tests/pos/pickleOK/templateParents.scala b/tests/pos/pickleOK/templateParents.scala
index 316d8c81c..153c4b4da 100644
--- a/tests/pos/pickleOK/templateParents.scala
+++ b/tests/pos/pickleOK/templateParents.scala
@@ -7,7 +7,8 @@ object templateParents {
class F extends C[Boolean](true) {
def foo = x
}
- new C("abc") with D
+ val cd = new C("abc") with D
+ cd.x
}