@@ -17,24 +17,24 @@ import dotty.tools.dotc.core.tasty.DottyUnpickler
1717import dotty .tools .dotc .core .tasty .TreeUnpickler .UnpickleMode
1818import dotty .tools .dotc .report
1919
20- import dotty .tools .tasty .TastyString
21-
2220import scala .reflect .ClassTag
2321
24- import scala .internal .quoted .Unpickler ._
22+ import scala .internal .quoted .PickledExpr
23+ import scala .internal .quoted .PickledSplices
24+ import scala .internal .quoted .PickledType
2525import scala .quoted .QuoteContext
2626import scala .collection .mutable
2727
2828object PickledQuotes {
2929 import tpd ._
3030
3131 /** Pickle the tree of the quote into strings */
32- def pickleQuote (tree : Tree )(using Context ): PickledQuote =
32+ def pickleQuote (tree : Tree )(using Context ): List [ String ] =
3333 if (ctx.reporter.hasErrors) Nil
3434 else {
3535 assert(! tree.isInstanceOf [Hole ]) // Should not be pickled as it represents `'{$x}` which should be optimized to `x`
3636 val pickled = pickle(tree)
37- TastyString .pickle(pickled)
37+ scala.internal.quoted. TastyString .pickle(pickled)
3838 }
3939
4040 /** Transform the expression into its fully spliced Tree */
@@ -52,8 +52,7 @@ object PickledQuotes {
5252 }
5353
5454 /** Unpickle the tree contained in the TastyExpr */
55- def unpickleExpr (tasty : PickledQuote , splices : PickledArgs )(using Context ): Tree = {
56- val tastyBytes = TastyString .unpickle(tasty)
55+ def unpickleTerm (tastyBytes : Array [Byte ], splices : PickledSplices )(using Context ): Tree = {
5756 val unpickled = withMode(Mode .ReadPositions )(
5857 unpickle(tastyBytes, splices, isType = false ))
5958 val Inlined (call, Nil , expnasion) = unpickled
@@ -64,15 +63,14 @@ object PickledQuotes {
6463 }
6564
6665 /** Unpickle the tree contained in the TastyType */
67- def unpickleType (tasty : PickledQuote , args : PickledArgs )(using Context ): Tree = {
68- val tastyBytes = TastyString .unpickle(tasty)
66+ def unpickleTypeTree (tastyBytes : Array [Byte ], splices : PickledSplices )(using Context ): Tree = {
6967 val unpickled = withMode(Mode .ReadPositions )(
70- unpickle(tastyBytes, args , isType = true ))
71- spliceTypes(unpickled, args )
68+ unpickle(tastyBytes, splices , isType = true ))
69+ spliceTypes(unpickled, splices )
7270 }
7371
7472 /** Replace all term holes with the spliced terms */
75- private def spliceTerms (tree : Tree , splices : PickledArgs )(using Context ): Tree = {
73+ private def spliceTerms (tree : Tree , splices : PickledSplices )(using Context ): Tree = {
7674 val evaluateHoles = new TreeMap {
7775 override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
7876 case Hole (isTerm, idx, args) =>
@@ -81,8 +79,7 @@ object PickledQuotes {
8179 else new scala.internal.quoted.Type (arg, QuoteContextImpl .scopeId)
8280 }
8381 if isTerm then
84- val splice1 = splices(idx).asInstanceOf [Seq [Any ] => QuoteContext ?=> quoted.Expr [? ]]
85- val quotedExpr = splice1(reifiedArgs)(using dotty.tools.dotc.quoted.QuoteContextImpl ())
82+ val quotedExpr = splices.exprSplice(idx)(reifiedArgs)(dotty.tools.dotc.quoted.QuoteContextImpl ())
8683 val filled = PickledQuotes .quotedExprToTree(quotedExpr)
8784
8885 // We need to make sure a hole is created with the source file of the surrounding context, even if
@@ -92,7 +89,7 @@ object PickledQuotes {
9289 else
9390 // Replaces type holes generated by ReifyQuotes (non-spliced types).
9491 // These are types defined in a quote and used at the same level in a nested quote.
95- val quotedType = splices(idx). asInstanceOf [ Seq [ Any ] => quoted. Type [ ? ]] (reifiedArgs)
92+ val quotedType = splices.typeSplice (idx)(reifiedArgs)
9693 PickledQuotes .quotedTypeToTree(quotedType)
9794 case tree : Select =>
9895 // Retain selected members
@@ -127,15 +124,15 @@ object PickledQuotes {
127124 }
128125
129126 /** Replace all type holes generated with the spliced types */
130- private def spliceTypes (tree : Tree , splices : PickledArgs )(using Context ): Tree = {
127+ private def spliceTypes (tree : Tree , splices : PickledSplices )(using Context ): Tree = {
131128 tree match
132129 case Block (stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ) =>
133130 val typeSpliceMap = (stat :: rest).iterator.map {
134131 case tdef : TypeDef =>
135132 assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ))
136133 val tree = tdef.rhs match
137134 case TypeBoundsTree (_, Hole (_, idx, args), _) =>
138- val quotedType = splices(idx). asInstanceOf [ Seq [ Any ] => quoted. Type [ ? ]] (args)
135+ val quotedType = splices.typeSplice (idx)(args)
139136 PickledQuotes .quotedTypeToTree(quotedType)
140137 case TypeBoundsTree (_, tpt, _) =>
141138 tpt
@@ -181,7 +178,7 @@ object PickledQuotes {
181178 }
182179
183180 /** Unpickle TASTY bytes into it's tree */
184- private def unpickle (bytes : Array [Byte ], splices : Seq [ Any ] , isType : Boolean )(using Context ): Tree = {
181+ private def unpickle (bytes : Array [Byte ], splices : PickledSplices , isType : Boolean )(using Context ): Tree = {
185182 quotePickling.println(s " **** unpickling quote from TASTY \n ${new TastyPrinter (bytes).printContents()}" )
186183
187184 val mode = if (isType) UnpickleMode .TypeTree else UnpickleMode .Term
0 commit comments