@@ -17,24 +17,24 @@ import dotty.tools.dotc.core.tasty.DottyUnpickler
17
17
import dotty .tools .dotc .core .tasty .TreeUnpickler .UnpickleMode
18
18
import dotty .tools .dotc .report
19
19
20
- import dotty .tools .tasty .TastyString
21
-
22
20
import scala .reflect .ClassTag
23
21
24
- import scala .internal .quoted .Unpickler ._
22
+ import scala .internal .quoted .PickledExpr
23
+ import scala .internal .quoted .PickledSplices
24
+ import scala .internal .quoted .PickledType
25
25
import scala .quoted .QuoteContext
26
26
import scala .collection .mutable
27
27
28
28
object PickledQuotes {
29
29
import tpd ._
30
30
31
31
/** 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 ] =
33
33
if (ctx.reporter.hasErrors) Nil
34
34
else {
35
35
assert(! tree.isInstanceOf [Hole ]) // Should not be pickled as it represents `'{$x}` which should be optimized to `x`
36
36
val pickled = pickle(tree)
37
- TastyString .pickle(pickled)
37
+ scala.internal.quoted. TastyString .pickle(pickled)
38
38
}
39
39
40
40
/** Transform the expression into its fully spliced Tree */
@@ -52,8 +52,7 @@ object PickledQuotes {
52
52
}
53
53
54
54
/** 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 = {
57
56
val unpickled = withMode(Mode .ReadPositions )(
58
57
unpickle(tastyBytes, splices, isType = false ))
59
58
val Inlined (call, Nil , expnasion) = unpickled
@@ -64,15 +63,14 @@ object PickledQuotes {
64
63
}
65
64
66
65
/** 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 = {
69
67
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 )
72
70
}
73
71
74
72
/** 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 = {
76
74
val evaluateHoles = new TreeMap {
77
75
override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
78
76
case Hole (isTerm, idx, args) =>
@@ -81,8 +79,7 @@ object PickledQuotes {
81
79
else new scala.internal.quoted.Type (arg, QuoteContextImpl .scopeId)
82
80
}
83
81
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 ())
86
83
val filled = PickledQuotes .quotedExprToTree(quotedExpr)
87
84
88
85
// 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 {
92
89
else
93
90
// Replaces type holes generated by ReifyQuotes (non-spliced types).
94
91
// 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)
96
93
PickledQuotes .quotedTypeToTree(quotedType)
97
94
case tree : Select =>
98
95
// Retain selected members
@@ -127,15 +124,15 @@ object PickledQuotes {
127
124
}
128
125
129
126
/** 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 = {
131
128
tree match
132
129
case Block (stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ) =>
133
130
val typeSpliceMap = (stat :: rest).iterator.map {
134
131
case tdef : TypeDef =>
135
132
assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ))
136
133
val tree = tdef.rhs match
137
134
case TypeBoundsTree (_, Hole (_, idx, args), _) =>
138
- val quotedType = splices(idx). asInstanceOf [ Seq [ Any ] => quoted. Type [ ? ]] (args)
135
+ val quotedType = splices.typeSplice (idx)(args)
139
136
PickledQuotes .quotedTypeToTree(quotedType)
140
137
case TypeBoundsTree (_, tpt, _) =>
141
138
tpt
@@ -181,7 +178,7 @@ object PickledQuotes {
181
178
}
182
179
183
180
/** 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 = {
185
182
quotePickling.println(s " **** unpickling quote from TASTY \n ${new TastyPrinter (bytes).printContents()}" )
186
183
187
184
val mode = if (isType) UnpickleMode .TypeTree else UnpickleMode .Term
0 commit comments