Skip to content

Commit 97d747a

Browse files
committed
Cache quotes containing definitions
1 parent 94f069e commit 97d747a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,14 @@ object PickledQuotes {
184184
QuotesCache.getTree(pickled) match
185185
case Some(tree) =>
186186
quotePickling.println(s"**** Using cached quote for TASTY\n$tree")
187-
tree
187+
treeOwner(tree) match
188+
case Some(owner) if owner == ctx.owner =>
189+
// Copy the cached tree to make sure the all definitions are unique.
190+
// If the owner is different, then changeOwnerOfTree will change the owner later.
191+
TreeTypeMap(oldOwners = List(owner), newOwners = List(owner)).apply(tree)
192+
case _ =>
193+
tree
194+
188195
case _ =>
189196
val bytes = pickled match
190197
case pickled: String => TastyString.unpickle(pickled)
@@ -197,25 +204,14 @@ object PickledQuotes {
197204
unpickler.enter(Set.empty)
198205

199206
val tree = unpickler.tree
200-
201-
var cacheable = true // TODO: can we remove this?
207+
QuotesCache(pickled) = tree
202208

203209
// Make sure trees and positions are fully loaded
204210
new TreeTraverser {
205-
def traverse(tree: Tree)(using Context): Unit =
206-
tree match
207-
case _: DefTree =>
208-
if !tree.symbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot)
209-
&& !tree.symbol.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot)
210-
then
211-
cacheable = false
212-
case _ =>
213-
traverseChildren(tree)
211+
def traverse(tree: Tree)(using Context): Unit = traverseChildren(tree)
214212
}.traverse(tree)
215213

216214
quotePickling.println(i"**** unpickled quote\n$tree")
217-
if cacheable then
218-
QuotesCache(pickled) = tree
219215

220216
tree
221217
}

0 commit comments

Comments
 (0)