From 7bdb2495ba8108f97735c41b3cb39fc9d6e31da9 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 4 Mar 2021 15:59:29 +0100 Subject: [PATCH 1/2] Fix memory leak through NoDenotation.cachePrefix We may set `NoDenotation.cachePrefix` in `Denotation.asSeenFrom`, thus leak memory. This memory leak is discovered by @mlachkar. Co-authored-by: Meriam Lachkar --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 24aa48213f31..e2127f4d3587 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -130,7 +130,7 @@ object Denotations { /** The denotation with info(s) as seen from prefix type */ final def asSeenFrom(pre: Type)(using Context): AsSeenFromResult = - if (Config.cacheAsSeenFrom) { + if (Config.cacheAsSeenFrom && exists) { if ((cachedPrefix ne pre) || ctx.period != validAsSeenFrom) { cachedAsSeenFrom = computeAsSeenFrom(pre) cachedPrefix = pre From 89d2b26ff4d219c33c699cb40e2ccdd6137502b4 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 4 Mar 2021 17:27:39 +0100 Subject: [PATCH 2/2] Override asSeenFrom for performance --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index e2127f4d3587..9b7893925e29 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -129,8 +129,8 @@ object Denotations { type AsSeenFromResult <: PreDenotation /** The denotation with info(s) as seen from prefix type */ - final def asSeenFrom(pre: Type)(using Context): AsSeenFromResult = - if (Config.cacheAsSeenFrom && exists) { + def asSeenFrom(pre: Type)(using Context): AsSeenFromResult = + if (Config.cacheAsSeenFrom) { if ((cachedPrefix ne pre) || ctx.period != validAsSeenFrom) { cachedAsSeenFrom = computeAsSeenFrom(pre) cachedPrefix = pre diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index fee5f1f0be87..89997fe2f801 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2209,8 +2209,8 @@ object SymDenotations { ensureCompleted() myCompanion - override def registeredCompanion_=(c: Symbol) = - myCompanion = c + override def registeredCompanion_=(c: Symbol) = + myCompanion = c private var myNestingLevel = -1 @@ -2397,6 +2397,7 @@ object SymDenotations { override def owner: Symbol = throw new AssertionError("NoDenotation.owner") override def computeAsSeenFrom(pre: Type)(using Context): SingleDenotation = this override def mapInfo(f: Type => Type)(using Context): SingleDenotation = this + override def asSeenFrom(pre: Type)(using Context): AsSeenFromResult = this override def matches(other: SingleDenotation)(using Context): Boolean = false override def targetName(using Context): Name = EmptyTermName