Skip to content

Commit 7a3973a

Browse files
committed
Remove PickledQuote and TastyString from library
1 parent 24f018d commit 7a3973a

File tree

8 files changed

+29
-70
lines changed

8 files changed

+29
-70
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,10 @@ class Definitions {
796796

797797
@tu lazy val QuoteContextClass: ClassSymbol = requiredClass("scala.quoted.QuoteContext")
798798
@tu lazy val QuoteContextInternalClass: ClassSymbol = requiredClass("scala.internal.quoted.QuoteContextInternal")
799-
@tu lazy val QuoteContextInternalClass_ExprMatch: Symbol = QuoteContextInternalClass.requiredMethod("ExprMatch")
800-
@tu lazy val QuoteContextInternalClass_TypeMatch: Symbol = QuoteContextInternalClass.requiredMethod("TypeMatch")
799+
@tu lazy val QuoteContextInternal_unpickleExpr: Symbol = QuoteContextInternalClass.requiredMethod("unpickleExpr")
800+
@tu lazy val QuoteContextInternal_unpickleType: Symbol = QuoteContextInternalClass.requiredMethod("unpickleType")
801+
@tu lazy val QuoteContextInternal_ExprMatch: Symbol = QuoteContextInternalClass.requiredMethod("ExprMatch")
802+
@tu lazy val QuoteContextInternal_TypeMatch: Symbol = QuoteContextInternalClass.requiredMethod("TypeMatch")
801803

802804
@tu lazy val LiftableModule: Symbol = requiredModule("scala.quoted.Liftable")
803805
@tu lazy val LiftableModule_BooleanLiftable: Symbol = LiftableModule.requiredMethod("BooleanLiftable")
@@ -831,8 +833,6 @@ class Definitions {
831833

832834
@tu lazy val TastyReflectionClass: ClassSymbol = requiredClass("scala.tasty.Reflection")
833835

834-
@tu lazy val PickledQuote_make: Symbol = requiredMethod("scala.internal.quoted.PickledQuote.make")
835-
836836
@tu lazy val EqlClass: ClassSymbol = requiredClass("scala.Eql")
837837
def Eql_eqlAny(using Context): TermSymbol = EqlClass.companionModule.requiredMethod(nme.eqlAny)
838838

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import dotty.tools.dotc.report
1919

2020
import scala.reflect.ClassTag
2121

22-
import scala.internal.quoted.PickledQuote
2322
import scala.quoted.QuoteContext
2423
import scala.collection.mutable
2524

@@ -34,7 +33,7 @@ object PickledQuotes {
3433
else {
3534
assert(!tree.isInstanceOf[Hole]) // Should not be pickled as it represents `'{$x}` which should be optimized to `x`
3635
val pickled = pickle(tree)
37-
scala.internal.quoted.TastyString.pickle(pickled)
36+
TastyString.pickle(pickled)
3837
}
3938

4039
/** Transform the expression into its fully spliced Tree */
@@ -52,25 +51,23 @@ object PickledQuotes {
5251
}
5352

5453
/** 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))
5856
val Inlined(call, Nil, expnasion) = unpickled
5957
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)
6260
cpy.Inlined(unpickled)(call, Nil, expansion2)
6361
}
6462

6563
/** 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)
7067
}
7168

7269
/** 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 = {
7471
val evaluateHoles = new TreeMap {
7572
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
7673
case Hole(isTerm, idx, args) =>
@@ -79,7 +76,7 @@ object PickledQuotes {
7976
else new scala.internal.quoted.Type(arg, QuoteContextImpl.scopeId)
8077
}
8178
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())
8380
val filled = PickledQuotes.quotedExprToTree(quotedExpr)
8481

8582
// 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 {
8986
else
9087
// Replaces type holes generated by ReifyQuotes (non-spliced types).
9188
// 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[?]]
9390
PickledQuotes.quotedTypeToTree(quotedType)
9491
case tree: Select =>
9592
// Retain selected members
@@ -124,15 +121,15 @@ object PickledQuotes {
124121
}
125122

126123
/** 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 = {
128125
tree match
129126
case Block(stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
130127
val typeSpliceMap = (stat :: rest).iterator.map {
131128
case tdef: TypeDef =>
132129
assert(tdef.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot))
133130
val tree = tdef.rhs match
134131
case TypeBoundsTree(_, Hole(_, idx, args), _) =>
135-
val quotedType = pickledQuote.typeSplice(idx)(args)
132+
val quotedType = fillHole(idx)(args).asInstanceOf[scala.quoted.Type[?]]
136133
PickledQuotes.quotedTypeToTree(quotedType)
137134
case TypeBoundsTree(_, tpt, _) =>
138135
tpt
@@ -178,8 +175,8 @@ object PickledQuotes {
178175
}
179176

180177
/** 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)
183180
quotePickling.println(s"**** unpickling quote from TASTY\n${TastyPrinter.show(bytes)}")
184181

185182
val mode = if (isType) UnpickleMode.TypeTree else UnpickleMode.Term

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import dotty.tools.dotc.core.Decorators._
1616
import scala.quoted.QuoteContext
1717
import dotty.tools.dotc.quoted.printers.{Extractors, SourceCode, SyntaxHighlight}
1818

19-
import scala.internal.quoted.PickledQuote
2019
import scala.tasty.reflect._
2120

2221
object QuoteContextImpl {
@@ -2631,12 +2630,12 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern
26312630

26322631
end reflect
26332632

2634-
def unpickleExpr[T](pickledQuote: PickledQuote): scala.quoted.Expr[T] =
2635-
val tree = PickledQuotes.unpickleTerm(pickledQuote)(using reflect.rootContext)
2633+
def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T] =
2634+
val tree = PickledQuotes.unpickleTerm(pickled, fillHole)(using reflect.rootContext)
26362635
new scala.internal.quoted.Expr(tree, hash).asInstanceOf[scala.quoted.Expr[T]]
26372636

2638-
def unpickleType[T <: AnyKind](pickledQuote: PickledQuote): scala.quoted.Type[T] =
2639-
val tree = PickledQuotes.unpickleTypeTree(pickledQuote)(using reflect.rootContext)
2637+
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T] =
2638+
val tree = PickledQuotes.unpickleTypeTree(pickled, fillHole)(using reflect.rootContext)
26402639
new scala.internal.quoted.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]]
26412640

26422641
object ExprMatch extends ExprMatchModule:

library/src/scala/internal/quoted/TastyString.scala renamed to compiler/src/dotty/tools/dotc/quoted/TastyString.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scala.internal.quoted
1+
package dotty.tools.dotc.quoted
22

33
import java.io._
44
import java.util.Base64

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,14 @@ class ReifyQuotes extends MacroTransform {
201201
*/
202202
def pickleAsTasty() = {
203203
val pickledQuoteStrings = liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType)
204-
// TODO: generate an instance of PickledSplices directly instead of passing through a List
205204
val splicesList = liftList(splices, defn.FunctionType(1).appliedTo(defn.SeqType.appliedTo(defn.AnyType), defn.AnyType))
206-
val pickledQuote = ref(defn.PickledQuote_make).appliedTo(pickledQuoteStrings, splicesList)
207205
val quoteClass = if isType then defn.QuotedTypeClass else defn.QuotedExprClass
208206
val quotedType = quoteClass.typeRef.appliedTo(originalTp)
209207
val lambdaTpe = MethodType(defn.QuoteContextClass.typeRef :: Nil, quotedType)
210208
def callUnpickle(ts: List[Tree]) = {
211209
val qctx = ts.head.asInstance(defn.QuoteContextInternalClass.typeRef)
212-
val unpickleMethName = if isType then "unpickleType" else "unpickleExpr"
213-
qctx.select(unpickleMethName.toTermName).appliedToType(originalTp).appliedTo(pickledQuote)
210+
val unpickleMeth = if isType then defn.QuoteContextInternal_unpickleType else defn.QuoteContextInternal_unpickleExpr
211+
qctx.select(unpickleMeth).appliedToType(originalTp).appliedTo(pickledQuoteStrings, splicesList)
214212
}
215213
Lambda(lambdaTpe, callUnpickle).withSpan(body.span)
216214
}

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ trait QuotesAndSplices {
463463
if (tree.quoted.isTerm) ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx)
464464
else ref(defn.QuotedTypeModule_apply.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)
465465

466-
val matchModule = if tree.quoted.isTerm then defn.QuoteContextInternalClass_ExprMatch else defn.QuoteContextInternalClass_TypeMatch
466+
val matchModule = if tree.quoted.isTerm then defn.QuoteContextInternal_ExprMatch else defn.QuoteContextInternal_TypeMatch
467467
val unapplyFun = qctx.asInstance(defn.QuoteContextInternalClass.typeRef).select(matchModule).select(nme.unapply)
468468

469469
UnApply(

library/src/scala/internal/quoted/PickledQuote.scala

Lines changed: 0 additions & 34 deletions
This file was deleted.

library/src/scala/internal/quoted/QuoteContextInternal.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ package scala.internal.quoted
22

33
import scala.quoted.{QuoteContext, Expr, Type}
44
import scala.tasty.reflect._
5-
import scala.internal.quoted.PickledQuote
65

76
/** Part of the QuoteContext interface that needs to be implemented by the compiler but is not visible to users */
87
trait QuoteContextInternal { self: QuoteContext =>
98

109
/** Unpickle `repr` which represents a pickled `Expr` tree,
1110
* replacing splice nodes with `holes`
1211
*/
13-
def unpickleExpr[T](pickledQuote: PickledQuote): scala.quoted.Expr[T]
12+
def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T]
1413

1514
/** Unpickle `repr` which represents a pickled `Type` tree,
1615
* replacing splice nodes with `holes`
1716
*/
18-
def unpickleType[T <: AnyKind](pickledQuote: PickledQuote): scala.quoted.Type[T]
17+
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T]
1918

2019
val ExprMatch: ExprMatchModule
2120

0 commit comments

Comments
 (0)