diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-27 15:35:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-27 16:02:21 +0100 |
commit | c476171d838c55bbfe36856e73a470e826748acc (patch) | |
tree | b2f93b5f14c23f779391c68860cb45e47f33d74d /src | |
parent | fe85a5aa18e071922d11f1dd1694fe478b9d4fad (diff) | |
download | dotty-c476171d838c55bbfe36856e73a470e826748acc.tar.gz dotty-c476171d838c55bbfe36856e73a470e826748acc.tar.bz2 dotty-c476171d838c55bbfe36856e73a470e826748acc.zip |
Cache result of narrow on Methods.
narrow is exercised a lot after the improvement to normalize. So it's important to cache it in order not to bust `uniques` with NoprefixTermRefs.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Uniques.scala | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 38ed09ebd..4f740d2e5 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -965,6 +965,15 @@ object Types { def map(tm: TypeMap): ProtoType } + /** Implementations of this trait cache the resukts of `narrow`. */ + trait NarrowCached extends Type { + private var myNarrow: TermRef = null + override def narrow(implicit ctx: Context): TermRef = { + if (myNarrow eq null) myNarrow = super.narrow + myNarrow + } + } + // --- NamedTypes ------------------------------------------------------------------ /** A NamedType of the form Prefix # name */ @@ -1408,7 +1417,7 @@ object Types { abstract case class MethodType(paramNames: List[TermName], paramTypes: List[Type]) (resultTypeExp: MethodType => Type) - extends CachedGroundType with BindingType with TermType with MethodOrPoly { thisMethodType => + extends CachedGroundType with BindingType with TermType with MethodOrPoly with NarrowCached { thisMethodType => override val resultType = resultTypeExp(this) assert(resultType != NoType) diff --git a/src/dotty/tools/dotc/core/Uniques.scala b/src/dotty/tools/dotc/core/Uniques.scala index 765b5d73f..9ad736c9c 100644 --- a/src/dotty/tools/dotc/core/Uniques.scala +++ b/src/dotty/tools/dotc/core/Uniques.scala @@ -24,7 +24,12 @@ object Uniques { def unique[T <: Type](tp: T)(implicit ctx: Context): T = { if (monitored) recordCaching(tp) if (tp.hash == NotCached) tp - else ctx.uniques.findEntryOrUpdate(tp).asInstanceOf[T] + else if (monitored) { + val size = ctx.uniques.size + val result = ctx.uniques.findEntryOrUpdate(tp).asInstanceOf[T] + if (ctx.uniques.size > size) record(s"fresh unique ${tp.getClass}") + result + } else ctx.uniques.findEntryOrUpdate(tp).asInstanceOf[T] } /* !!! DEBUG ensuring ( result => tp.toString == result.toString || { |