diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-23 09:59:44 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-23 12:07:18 -0700 |
commit | b8641a97d669c945a1b9f47b4e8934aa6c98ffd7 (patch) | |
tree | 7d4e4b8d74b32749e2fa01f3d005431a167fe072 | |
parent | 6256e22e705b0b8d61b1012289586650a67fdb9f (diff) | |
download | scala-b8641a97d669c945a1b9f47b4e8934aa6c98ffd7.tar.gz scala-b8641a97d669c945a1b9f47b4e8934aa6c98ffd7.tar.bz2 scala-b8641a97d669c945a1b9f47b4e8934aa6c98ffd7.zip |
Avoid caching different types in TypeSymbol.
Try to prevent TypeSymbols from caching a different typeref
for tpe_* and typeConstructor if the symbol is monomorphic.
I find this undesirable:
scala> AnyRefClass.tpe eq AnyRefClass.typeConstructor
res0: Boolean = true
scala> AnyRefClass.tpe eq AnyRefClass.typeConstructor
res1: Boolean = false
-rw-r--r-- | src/reflect/scala/reflect/internal/Symbols.scala | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index af20b8b756..f8fa5c515b 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2868,18 +2868,19 @@ trait Symbols extends api.Symbols { self: SymbolTable => tpeCache } override def typeConstructor: Type = { - maybeUpdateTyconCache() + if (tyconCacheNeedsUpdate) + setTyconCache(newTypeRef(Nil)) tyconCache } override def tpeHK: Type = typeConstructor - private def maybeUpdateTyconCache() { - if ((tyconCache eq null) || tyconRunId != currentRunId) { - tyconCache = newTypeRef(Nil) - tyconRunId = currentRunId - } - assert(tyconCache ne null) + private def tyconCacheNeedsUpdate = (tyconCache eq null) || tyconRunId != currentRunId + private def setTyconCache(tycon: Type) { + tyconCache = tycon + tyconRunId = currentRunId + assert(tyconCache ne null, this) } + private def maybeUpdateTypeCache() { if (tpePeriod != currentPeriod) { if (isValid(tpePeriod)) @@ -2896,10 +2897,15 @@ trait Symbols extends api.Symbols { self: SymbolTable => tpePeriod = currentPeriod tpeCache = NoType // cycle marker + val noTypeParams = phase.erasedTypes && this != ArrayClass || unsafeTypeParams.isEmpty tpeCache = newTypeRef( - if (phase.erasedTypes && this != ArrayClass || unsafeTypeParams.isEmpty) Nil + if (noTypeParams) Nil else unsafeTypeParams map (_.typeConstructor) ) + // Avoid carrying around different types in tyconCache and tpeCache + // for monomorphic types. + if (noTypeParams && tyconCacheNeedsUpdate) + setTyconCache(tpeCache) } override def info_=(tp: Type) { |