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