@@ -19,9 +19,7 @@ import dotty.tools.dotc.report
19
19
20
20
import scala .reflect .ClassTag
21
21
22
- import scala .internal .quoted .PickledExpr
23
- import scala .internal .quoted .PickledSplices
24
- import scala .internal .quoted .PickledType
22
+ import scala .internal .quoted .PickledQuote
25
23
import scala .quoted .QuoteContext
26
24
import scala .collection .mutable
27
25
@@ -52,25 +50,25 @@ object PickledQuotes {
52
50
}
53
51
54
52
/** Unpickle the tree contained in the TastyExpr */
55
- def unpickleTerm (tastyBytes : Array [ Byte ], splices : PickledSplices )(using Context ): Tree = {
53
+ def unpickleTerm (pickledQuote : PickledQuote )(using Context ): Tree = {
56
54
val unpickled = withMode(Mode .ReadPositions )(
57
- unpickle(tastyBytes, splices , isType = false ))
55
+ unpickle(pickledQuote , isType = false ))
58
56
val Inlined (call, Nil , expnasion) = unpickled
59
57
val inlineCtx = inlineContext(call)
60
- val expansion1 = spliceTypes(expnasion, splices )(using inlineCtx)
61
- val expansion2 = spliceTerms(expansion1, splices )(using inlineCtx)
58
+ val expansion1 = spliceTypes(expnasion, pickledQuote )(using inlineCtx)
59
+ val expansion2 = spliceTerms(expansion1, pickledQuote )(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 (tastyBytes : Array [ Byte ], splices : PickledSplices )(using Context ): Tree = {
64
+ def unpickleTypeTree (pickledQuote : PickledQuote )(using Context ): Tree = {
67
65
val unpickled = withMode(Mode .ReadPositions )(
68
- unpickle(tastyBytes, splices , isType = true ))
69
- spliceTypes(unpickled, splices )
66
+ unpickle(pickledQuote , isType = true ))
67
+ spliceTypes(unpickled, pickledQuote )
70
68
}
71
69
72
70
/** Replace all term holes with the spliced terms */
73
- private def spliceTerms (tree : Tree , splices : PickledSplices )(using Context ): Tree = {
71
+ private def spliceTerms (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
74
72
val evaluateHoles = new TreeMap {
75
73
override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
76
74
case Hole (isTerm, idx, args) =>
@@ -79,7 +77,7 @@ object PickledQuotes {
79
77
else new scala.internal.quoted.Type (arg, QuoteContextImpl .scopeId)
80
78
}
81
79
if isTerm then
82
- val quotedExpr = splices .exprSplice(idx)(reifiedArgs)(dotty.tools.dotc.quoted.QuoteContextImpl ())
80
+ val quotedExpr = pickledQuote .exprSplice(idx)(reifiedArgs)(dotty.tools.dotc.quoted.QuoteContextImpl ())
83
81
val filled = PickledQuotes .quotedExprToTree(quotedExpr)
84
82
85
83
// We need to make sure a hole is created with the source file of the surrounding context, even if
@@ -89,7 +87,7 @@ object PickledQuotes {
89
87
else
90
88
// Replaces type holes generated by ReifyQuotes (non-spliced types).
91
89
// These are types defined in a quote and used at the same level in a nested quote.
92
- val quotedType = splices .typeSplice(idx)(reifiedArgs)
90
+ val quotedType = pickledQuote .typeSplice(idx)(reifiedArgs)
93
91
PickledQuotes .quotedTypeToTree(quotedType)
94
92
case tree : Select =>
95
93
// Retain selected members
@@ -124,15 +122,15 @@ object PickledQuotes {
124
122
}
125
123
126
124
/** Replace all type holes generated with the spliced types */
127
- private def spliceTypes (tree : Tree , splices : PickledSplices )(using Context ): Tree = {
125
+ private def spliceTypes (tree : Tree , pickledQuote : PickledQuote )(using Context ): Tree = {
128
126
tree match
129
127
case Block (stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ) =>
130
128
val typeSpliceMap = (stat :: rest).iterator.map {
131
129
case tdef : TypeDef =>
132
130
assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot ))
133
131
val tree = tdef.rhs match
134
132
case TypeBoundsTree (_, Hole (_, idx, args), _) =>
135
- val quotedType = splices .typeSplice(idx)(args)
133
+ val quotedType = pickledQuote .typeSplice(idx)(args)
136
134
PickledQuotes .quotedTypeToTree(quotedType)
137
135
case TypeBoundsTree (_, tpt, _) =>
138
136
tpt
@@ -178,7 +176,8 @@ object PickledQuotes {
178
176
}
179
177
180
178
/** Unpickle TASTY bytes into it's tree */
181
- private def unpickle (bytes : Array [Byte ], splices : PickledSplices , isType : Boolean )(using Context ): Tree = {
179
+ private def unpickle (pickledQuote : PickledQuote , isType : Boolean )(using Context ): Tree = {
180
+ val bytes = pickledQuote.bytes()
182
181
quotePickling.println(s " **** unpickling quote from TASTY \n ${new TastyPrinter (bytes).printContents()}" )
183
182
184
183
val mode = if (isType) UnpickleMode .TypeTree else UnpickleMode .Term
0 commit comments