Skip to content

Commit 24b57a4

Browse files
committed
Generalize unpickleExpr interface
This way we could generate somthing that is not a Seq, possibly a closure with a switch on the index.
1 parent 40517fd commit 24b57a4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object PickledQuotes {
5151
}
5252

5353
/** Unpickle the tree contained in the TastyExpr */
54-
def unpickleTerm(pickled: List[String], fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
54+
def unpickleTerm(pickled: List[String], fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
5555
val unpickled = withMode(Mode.ReadPositions)(unpickle(pickled, isType = false))
5656
val Inlined(call, Nil, expnasion) = unpickled
5757
val inlineCtx = inlineContext(call)
@@ -61,13 +61,13 @@ object PickledQuotes {
6161
}
6262

6363
/** Unpickle the tree contained in the TastyType */
64-
def unpickleTypeTree(pickled: List[String], fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
64+
def unpickleTypeTree(pickled: List[String], fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
6565
val unpickled = withMode(Mode.ReadPositions)(unpickle(pickled, isType = true))
6666
spliceTypes(unpickled, fillHole)
6767
}
6868

6969
/** Replace all term holes with the spliced terms */
70-
private def spliceTerms(tree: Tree, fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
70+
private def spliceTerms(tree: Tree, fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
7171
val evaluateHoles = new TreeMap {
7272
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
7373
case Hole(isTerm, idx, args) =>
@@ -121,7 +121,7 @@ object PickledQuotes {
121121
}
122122

123123
/** Replace all type holes generated with the spliced types */
124-
private def spliceTypes(tree: Tree, fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
124+
private def spliceTypes(tree: Tree, fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
125125
tree match
126126
case Block(stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
127127
val typeSpliceMap = (stat :: rest).iterator.map {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,11 +2621,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern
26212621

26222622
end reflect
26232623

2624-
def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T] =
2624+
def unpickleExpr[T](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Expr[T] =
26252625
val tree = PickledQuotes.unpickleTerm(pickled, fillHole)(using reflect.rootContext)
26262626
new scala.quoted.internal.Expr(tree, hash).asInstanceOf[scala.quoted.Expr[T]]
26272627

2628-
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T] =
2628+
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Type[T] =
26292629
val tree = PickledQuotes.unpickleTypeTree(pickled, fillHole)(using reflect.rootContext)
26302630
new scala.quoted.internal.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]]
26312631

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ trait QuoteContextInternal { self: QuoteContext =>
99
/** Unpickle `repr` which represents a pickled `Expr` tree,
1010
* replacing splice nodes with `holes`
1111
*/
12-
def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T]
12+
def unpickleExpr[T](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Expr[T]
1313

1414
/** Unpickle `repr` which represents a pickled `Type` tree,
1515
* replacing splice nodes with `holes`
1616
*/
17-
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T]
17+
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Type[T]
1818

1919
val ExprMatch: ExprMatchModule
2020

0 commit comments

Comments
 (0)