Skip to content

Commit 273239d

Browse files
committed
cache inherited inline body caches
1 parent 7bde05f commit 273239d

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
149149
* the rhs of the key. If a symbol is present in the value set, then do not hash its signature or inline body.
150150
*/
151151
private val seenInlineCache = mutable.HashMap.empty[Symbol, mutable.HashSet[Symbol]]
152+
private val inlineBodyCache = mutable.HashMap.empty[Symbol, Int]
152153

153154
private val allNonLocalClassesInSrc = new mutable.HashSet[xsbti.api.ClassLike]
154155
private val _mainClasses = new mutable.HashSet[String]
@@ -652,17 +653,27 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
652653
// an inline def in every class that extends its owner. To avoid this we
653654
// could store the hash as an annotation when pickling an inline def
654655
// and retrieve it here instead of computing it on the fly.
655-
val root =
656-
if inlineOrigin.exists then
657-
inlineOrigin
658-
else
659-
assert(!seenInlineCache.contains(s))
660-
seenInlineCache.put(s, mutable.HashSet.empty)
661-
s
662-
if !seenInlineCache(root).contains(s) then
663-
seenInlineCache(root) += s
664-
val inlineBodyHash = treeHash(inlineBody, inlineOrigin = root)
656+
657+
def registerInlineHash(inlineBodyHash: Int): Unit =
665658
annots += marker(inlineBodyHash.toString)
659+
660+
def nestedHash(root: Symbol): Unit =
661+
if !seenInlineCache(root).contains(s) then
662+
seenInlineCache(root) += s
663+
registerInlineHash(treeHash(inlineBody, inlineOrigin = root))
664+
665+
def originHash(root: Symbol): Unit =
666+
def computeHash(): Int =
667+
assert(!seenInlineCache.contains(root))
668+
seenInlineCache.put(root, mutable.HashSet(root))
669+
val res = treeHash(inlineBody, inlineOrigin = root)
670+
seenInlineCache.remove(root)
671+
res
672+
registerInlineHash(inlineBodyCache.getOrElseUpdate(root, computeHash()))
673+
674+
if inlineOrigin.exists then nestedHash(root = inlineOrigin)
675+
else originHash(root = s)
676+
666677
end if
667678

668679
// In the Scala2 ExtractAPI phase we only extract annotations that extend

0 commit comments

Comments
 (0)