@@ -19,7 +19,6 @@ import dotty.tools.dotc.report
1919
2020import scala .reflect .ClassTag
2121
22- import scala .internal .quoted .PickledQuote
2322import scala .quoted .QuoteContext
2423import scala .collection .mutable
2524
@@ -34,7 +33,7 @@ object PickledQuotes {
3433 else {
3534 assert(! tree.isInstanceOf [Hole ]) // Should not be pickled as it represents `'{$x}` which should be optimized to `x`
3635 val pickled = pickle(tree)
37- scala.internal.quoted. TastyString .pickle(pickled)
36+ TastyString .pickle(pickled)
3837 }
3938
4039 /** Transform the expression into its fully spliced Tree */
@@ -52,25 +51,23 @@ object PickledQuotes {
5251 }
5352
5453 /** Unpickle the tree contained in the TastyExpr */
55- def unpickleTerm (pickledQuote : PickledQuote )(using Context ): Tree = {
56- val unpickled = withMode(Mode .ReadPositions )(
57- unpickle(pickledQuote, isType = false ))
54+ def unpickleTerm (pickled : List [String ], fillHole : Seq [Seq [Any ] => Any ])(using Context ): Tree = {
55+ val unpickled = withMode(Mode .ReadPositions )(unpickle(pickled, isType = false ))
5856 val Inlined (call, Nil , expnasion) = unpickled
5957 val inlineCtx = inlineContext(call)
60- val expansion1 = spliceTypes(expnasion, pickledQuote )(using inlineCtx)
61- val expansion2 = spliceTerms(expansion1, pickledQuote )(using inlineCtx)
58+ val expansion1 = spliceTypes(expnasion, fillHole )(using inlineCtx)
59+ val expansion2 = spliceTerms(expansion1, fillHole )(using inlineCtx)
6260 cpy.Inlined (unpickled)(call, Nil , expansion2)
6361 }
6462
6563 /** Unpickle the tree contained in the TastyType */
66- def unpickleTypeTree (pickledQuote : PickledQuote )(using Context ): Tree = {
67- val unpickled = withMode(Mode .ReadPositions )(
68- unpickle(pickledQuote, isType = true ))
69- spliceTypes(unpickled, pickledQuote)
64+ def unpickleTypeTree (pickled : List [String ], fillHole : Seq [Seq [Any ] => Any ])(using Context ): Tree = {
65+ val unpickled = withMode(Mode .ReadPositions )(unpickle(pickled, isType = true ))
66+ spliceTypes(unpickled, fillHole)
7067 }
7168
7269 /** Replace all term holes with the spliced terms */
73- private def spliceTerms (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
70+ private def spliceTerms (tree : Tree , fillHole : Seq [ Seq [ Any ] => Any ] )(using Context ): Tree = {
7471 val evaluateHoles = new TreeMap {
7572 override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
7673 case Hole (isTerm, idx, args) =>
@@ -79,7 +76,7 @@ object PickledQuotes {
7976 else new scala.quoted.internal.Type (arg, QuoteContextImpl .scopeId)
8077 }
8178 if isTerm then
82- val quotedExpr = pickledQuote.exprSplice (idx)(reifiedArgs)(dotty.tools.dotc.quoted.QuoteContextImpl ())
79+ val quotedExpr = fillHole (idx)(reifiedArgs). asInstanceOf [ QuoteContext => scala.quoted. Expr [ Any ]] (dotty.tools.dotc.quoted.QuoteContextImpl ())
8380 val filled = PickledQuotes .quotedExprToTree(quotedExpr)
8481
8582 // We need to make sure a hole is created with the source file of the surrounding context, even if
@@ -89,7 +86,7 @@ object PickledQuotes {
8986 else
9087 // Replaces type holes generated by PickleQuotes (non-spliced types).
9188 // These are types defined in a quote and used at the same level in a nested quote.
92- val quotedType = pickledQuote.typeSplice (idx)(reifiedArgs)
89+ val quotedType = fillHole (idx)(reifiedArgs). asInstanceOf [scala.quoted. Type [ ? ]]
9390 PickledQuotes .quotedTypeToTree(quotedType)
9491 case tree : Select =>
9592 // Retain selected members
@@ -124,15 +121,15 @@ object PickledQuotes {
124121 }
125122
126123 /** Replace all type holes generated with the spliced types */
127- private def spliceTypes (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
124+ private def spliceTypes (tree : Tree , fillHole : Seq [ Seq [ Any ] => Any ] )(using Context ): Tree = {
128125 tree match
129126 case Block (stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ) =>
130127 val typeSpliceMap = (stat :: rest).iterator.map {
131128 case tdef : TypeDef =>
132129 assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ))
133130 val tree = tdef.rhs match
134131 case TypeBoundsTree (_, Hole (_, idx, args), _) =>
135- val quotedType = pickledQuote.typeSplice (idx)(args)
132+ val quotedType = fillHole (idx)(args). asInstanceOf [scala.quoted. Type [ ? ]]
136133 PickledQuotes .quotedTypeToTree(quotedType)
137134 case TypeBoundsTree (_, tpt, _) =>
138135 tpt
@@ -178,8 +175,8 @@ object PickledQuotes {
178175 }
179176
180177 /** Unpickle TASTY bytes into it's tree */
181- private def unpickle (pickledQuote : PickledQuote , isType : Boolean )(using Context ): Tree = {
182- val bytes = pickledQuote.bytes( )
178+ private def unpickle (pickled : List [ String ] , isType : Boolean )(using Context ): Tree = {
179+ val bytes = TastyString .unpickle(pickled )
183180 quotePickling.println(s " **** unpickling quote from TASTY \n ${TastyPrinter .show(bytes)}" )
184181
185182 val mode = if (isType) UnpickleMode .TypeTree else UnpickleMode .Term
0 commit comments