@@ -17,24 +17,22 @@ 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 .PickledQuote
2523import scala .quoted .QuoteContext
2624import scala .collection .mutable
2725
2826object PickledQuotes {
2927 import tpd ._
3028
3129 /** Pickle the tree of the quote into strings */
32- def pickleQuote (tree : Tree )(using Context ): PickledQuote =
30+ def pickleQuote (tree : Tree )(using Context ): List [ String ] =
3331 if (ctx.reporter.hasErrors) Nil
3432 else {
3533 assert(! tree.isInstanceOf [Hole ]) // Should not be pickled as it represents `'{$x}` which should be optimized to `x`
3634 val pickled = pickle(tree)
37- TastyString .pickle(pickled)
35+ scala.internal.quoted. TastyString .pickle(pickled)
3836 }
3937
4038 /** Transform the expression into its fully spliced Tree */
@@ -52,27 +50,25 @@ object PickledQuotes {
5250 }
5351
5452 /** Unpickle the tree contained in the TastyExpr */
55- def unpickleExpr (tasty : PickledQuote , splices : PickledArgs )(using Context ): Tree = {
56- val tastyBytes = TastyString .unpickle(tasty)
53+ def unpickleTerm (pickledQuote : PickledQuote )(using Context ): Tree = {
5754 val unpickled = withMode(Mode .ReadPositions )(
58- unpickle(tastyBytes, splices , isType = false ))
55+ unpickle(pickledQuote , isType = false ))
5956 val Inlined (call, Nil , expnasion) = unpickled
6057 val inlineCtx = inlineContext(call)
61- val expansion1 = spliceTypes(expnasion, splices )(using inlineCtx)
62- val expansion2 = spliceTerms(expansion1, splices )(using inlineCtx)
58+ val expansion1 = spliceTypes(expnasion, pickledQuote )(using inlineCtx)
59+ val expansion2 = spliceTerms(expansion1, pickledQuote )(using inlineCtx)
6360 cpy.Inlined (unpickled)(call, Nil , expansion2)
6461 }
6562
6663 /** Unpickle the tree contained in the TastyType */
67- def unpickleType (tasty : PickledQuote , args : PickledArgs )(using Context ): Tree = {
68- val tastyBytes = TastyString .unpickle(tasty)
64+ def unpickleTypeTree (pickledQuote : PickledQuote )(using Context ): Tree = {
6965 val unpickled = withMode(Mode .ReadPositions )(
70- unpickle(tastyBytes, args , isType = true ))
71- spliceTypes(unpickled, args )
66+ unpickle(pickledQuote , isType = true ))
67+ spliceTypes(unpickled, pickledQuote )
7268 }
7369
7470 /** Replace all term holes with the spliced terms */
75- private def spliceTerms (tree : Tree , splices : PickledArgs )(using Context ): Tree = {
71+ private def spliceTerms (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
7672 val evaluateHoles = new TreeMap {
7773 override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
7874 case Hole (isTerm, idx, args) =>
@@ -81,8 +77,7 @@ object PickledQuotes {
8177 else new scala.internal.quoted.Type (arg, QuoteContextImpl .scopeId)
8278 }
8379 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 ())
80+ val quotedExpr = pickledQuote.exprSplice(idx)(reifiedArgs)(dotty.tools.dotc.quoted.QuoteContextImpl ())
8681 val filled = PickledQuotes .quotedExprToTree(quotedExpr)
8782
8883 // We need to make sure a hole is created with the source file of the surrounding context, even if
@@ -92,7 +87,7 @@ object PickledQuotes {
9287 else
9388 // Replaces type holes generated by ReifyQuotes (non-spliced types).
9489 // 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)
90+ val quotedType = pickledQuote.typeSplice (idx)(reifiedArgs)
9691 PickledQuotes .quotedTypeToTree(quotedType)
9792 case tree : Select =>
9893 // Retain selected members
@@ -127,15 +122,15 @@ object PickledQuotes {
127122 }
128123
129124 /** Replace all type holes generated with the spliced types */
130- private def spliceTypes (tree : Tree , splices : PickledArgs )(using Context ): Tree = {
125+ private def spliceTypes (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
131126 tree match
132127 case Block (stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ) =>
133128 val typeSpliceMap = (stat :: rest).iterator.map {
134129 case tdef : TypeDef =>
135130 assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ))
136131 val tree = tdef.rhs match
137132 case TypeBoundsTree (_, Hole (_, idx, args), _) =>
138- val quotedType = splices (idx). asInstanceOf [ Seq [ Any ] => quoted. Type [ ? ]] (args)
133+ val quotedType = pickledQuote.typeSplice (idx)(args)
139134 PickledQuotes .quotedTypeToTree(quotedType)
140135 case TypeBoundsTree (_, tpt, _) =>
141136 tpt
@@ -181,7 +176,8 @@ object PickledQuotes {
181176 }
182177
183178 /** Unpickle TASTY bytes into it's tree */
184- private def unpickle (bytes : Array [Byte ], splices : Seq [Any ], isType : Boolean )(using Context ): Tree = {
179+ private def unpickle (pickledQuote : PickledQuote , isType : Boolean )(using Context ): Tree = {
180+ val bytes = pickledQuote.bytes()
185181 quotePickling.println(s " **** unpickling quote from TASTY \n ${new TastyPrinter (bytes).printContents()}" )
186182
187183 val mode = if (isType) UnpickleMode .TypeTree else UnpickleMode .Term
0 commit comments