diff options
author | Martin Odersky <odersky@gmail.com> | 2014-08-27 08:55:21 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-08-27 08:55:21 +0200 |
commit | 292ce6844a212b47defc671c91396d7cec86833b (patch) | |
tree | 43c4576fc6b2e05e4f7552106bbdb57e13fdf06b | |
parent | 08c6eacaf59386ed26aeead472e1df2c5944a3fb (diff) | |
download | dotty-292ce6844a212b47defc671c91396d7cec86833b.tar.gz dotty-292ce6844a212b47defc671c91396d7cec86833b.tar.bz2 dotty-292ce6844a212b47defc671c91396d7cec86833b.zip |
Rebinding ThisTypes
ThisTypes do escape. It seems that Scala 2 pickling produces ThisTypes that refer to base
classes of the class being compiled. If the base class is in a separate compilation unit,
this can lead to a stale class symbol in the ThisType. We solve this here by rebinding the
class symbol in the ThisType. We should also explore the alternative:
class ThisType(tref: TypeRef) ...
That would do the rebinding as part of the generation denotation resolution mechanism.
-rw-r--r-- | src/dotty/tools/dotc/config/ScalaSettings.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Substituters.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 23 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 2 |
5 files changed, 23 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index 967a09543..177813555 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -132,7 +132,7 @@ class ScalaSettings extends Settings.SettingGroup { val Ydumpclasses = StringSetting("-Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", "") val Ynosqueeze = BooleanSetting("-Yno-squeeze", "Disable creation of compact code in matching.") val YstopAfter = PhasesSetting("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat - val YstopBefore = PhasesSetting("-Ystop-before", "Stop before", "erasure") // stop before erasure as long as we have not debugged it fully + val YstopBefore = PhasesSetting("-Ystop-before", "Stop before") // stop before erasure as long as we have not debugged it fully val refinementMethodDispatch = ChoiceSetting("-Ystruct-dispatch", "policy", "structural method dispatch policy", List("no-cache", "mono-cache", "poly-cache", "invoke-dynamic"), "poly-cache") val Yrangepos = BooleanSetting("-Yrangepos", "Use range positions for syntax trees.") val Ybuilderdebug = ChoiceSetting("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none") diff --git a/src/dotty/tools/dotc/core/Substituters.scala b/src/dotty/tools/dotc/core/Substituters.scala index 74388f436..e05f76cd9 100644 --- a/src/dotty/tools/dotc/core/Substituters.scala +++ b/src/dotty/tools/dotc/core/Substituters.scala @@ -145,7 +145,7 @@ trait Substituters { this: Context => var fs = from var ts = to while (fs.nonEmpty) { - if (fs.head eq sym) return ThisType(ts.head.asClass) + if (fs.head eq sym) return ts.head.asClass.thisType fs = fs.tail ts = ts.tail } diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index a3828552d..cb457bd73 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1011,7 +1011,7 @@ object SymDenotations { if ((pre eq NoPrefix) || ctx.erasedTypes) pre select sourceModule else TermRef.withSig(pre, name.sourceModuleName, Signature.NotAMethod) } - else ThisType(classSymbol) + else ThisType.raw(classSymbol) private[this] var myTypeRef: TypeRef = null diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index a6ba7d9a0..787c7c4e9 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1535,16 +1535,31 @@ object Types { // --- Other SingletonTypes: ThisType/SuperType/ConstantType --------------------------- /** The type cls.this */ - abstract case class ThisType(cls: ClassSymbol) extends CachedProxyType with SingletonType { - override def underlying(implicit ctx: Context) = cls.classInfo.selfType - override def computeHash = doHash(cls) + abstract case class ThisType(private var myCls: ClassSymbol) extends CachedProxyType with SingletonType { + def cls(implicit ctx: Context): ClassSymbol = + try myCls.denot.symbol.asClass + catch { + case ex: StaleSymbol => + def prevDenot(implicit ctx: Context) = myCls.denot + val prev = prevDenot(ctx.fresh.setPeriod(Period(myCls.defRunId, ctx.phaseId))) + myCls = prev.owner.info.member(prev.name).symbol.asClass + cls + } + override def underlying(implicit ctx: Context) = + try cls.classInfo.selfType + catch { + case ex: StaleSymbol => + println(i"stale symbol when deref ${cls.id}") + throw ex + } + override def computeHash = doHash(myCls) } final class CachedThisType(cls: ClassSymbol) extends ThisType(cls) // TODO: consider hash before constructing types? object ThisType { - def apply(cls: ClassSymbol)(implicit ctx: Context) = + def raw(cls: ClassSymbol)(implicit ctx: Context) = unique(new CachedThisType(cls)) } diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 2e21358e4..e82002c9f 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -613,7 +613,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: case THIStpe => val cls = readSymbolRef().asClass if (isRefinementClass(cls)) RefinedThis(refinementTypes(cls)) - else ThisType(cls) + else cls.thisType case SINGLEtpe => val pre = readTypeRef() val sym = readDisambiguatedSymbolRef(_.info.isParameterless) |