From b8641a97d669c945a1b9f47b4e8934aa6c98ffd7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 23 May 2013 09:59:44 -0700 Subject: 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 --- src/reflect/scala/reflect/internal/Symbols.scala | 22 ++++++++++++++-------- 1 file 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) { -- cgit v1.2.3