Skip to content

Commit 5cc810e

Browse files
committed
Use Expr and Type to unpickle in CompilerInterface
1 parent 7cd3070 commit 5cc810e

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,17 +2617,19 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern
26172617

26182618
end reflect
26192619

2620-
def unpickleTerm(pickledQuote: PickledQuote): reflect.Term =
2621-
PickledQuotes.unpickleTerm(pickledQuote)(using reflect.rootContext)
2620+
def unpickleExpr(pickledQuote: PickledQuote): scala.quoted.Expr[Any] =
2621+
val tree = PickledQuotes.unpickleTerm(pickledQuote)(using reflect.rootContext)
2622+
new scala.internal.quoted.Expr(tree, hash)
26222623

2623-
def unpickleTypeTree(pickledQuote: PickledQuote): reflect.TypeTree =
2624-
PickledQuotes.unpickleTypeTree(pickledQuote)(using reflect.rootContext)
2624+
def unpickleType(pickledQuote: PickledQuote): scala.quoted.Type[?] =
2625+
val tree = PickledQuotes.unpickleTypeTree(pickledQuote)(using reflect.rootContext)
2626+
new scala.internal.quoted.Type(tree, hash)
26252627

2626-
def termMatch(scrutinee: reflect.Term, pattern: reflect.Term): Option[Tuple] =
2627-
treeMatch(scrutinee, pattern)
2628+
def exprMatch(scrutinee: scala.quoted.Expr[Any], pattern: scala.quoted.Expr[Any]): Option[Tuple] =
2629+
treeMatch(scrutinee.unseal(using this), pattern.unseal(using this))
26282630

2629-
def typeTreeMatch(scrutinee: reflect.TypeTree, pattern: reflect.TypeTree): Option[Tuple] =
2630-
treeMatch(scrutinee, pattern)
2631+
def typeMatch(scrutinee: scala.quoted.Type[?], pattern: scala.quoted.Type[?]): Option[Tuple] =
2632+
treeMatch(scrutinee.unseal(using this), pattern.unseal(using this))
26312633

26322634
private def treeMatch(scrutinee: reflect.Tree, pattern: reflect.Tree): Option[Tuple] = {
26332635
import reflect._

library/src-bootstrapped/scala/internal/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Expr {
5454
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: scala.quoted.Expr[Any])
5555
(using patternExpr: scala.quoted.Expr[Any], qctx: QuoteContext): Option[Tup] = {
5656
val qctx1 = quoteContextWithCompilerInterface(qctx)
57-
qctx1.termMatch(scrutineeExpr.unseal, patternExpr.unseal).asInstanceOf[Option[Tup]]
57+
qctx1.exprMatch(scrutineeExpr, patternExpr).asInstanceOf[Option[Tup]]
5858
}
5959

6060
/** Returns a null expresssion equivalent to `'{null}` */

library/src-bootstrapped/scala/internal/quoted/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Type {
3737
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeType: scala.quoted.Type[_])
3838
(using patternType: scala.quoted.Type[_], qctx: QuoteContext): Option[Tup] = {
3939
val qctx1 = quoteContextWithCompilerInterface(qctx)
40-
qctx1.typeTreeMatch(scrutineeType.unseal, patternType.unseal).asInstanceOf[Option[Tup]]
40+
qctx1.typeMatch(scrutineeType, patternType).asInstanceOf[Option[Tup]]
4141
}
4242

4343

library/src/scala/internal/quoted/CompilerInterface.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ trait CompilerInterface { self: scala.quoted.QuoteContext =>
1212
/** Unpickle `repr` which represents a pickled `Expr` tree,
1313
* replacing splice nodes with `holes`
1414
*/
15-
def unpickleTerm(pickledQuote: PickledQuote): Term
15+
def unpickleExpr(pickledQuote: PickledQuote): scala.quoted.Expr[Any]
1616

1717
/** Unpickle `repr` which represents a pickled `Type` tree,
1818
* replacing splice nodes with `holes`
1919
*/
20-
def unpickleTypeTree(pickledQuote: PickledQuote): TypeTree
20+
def unpickleType(pickledQuote: PickledQuote): scala.quoted.Type[?]
2121

2222
/** Pattern matches the scrutinee against the pattern and returns a tuple
2323
* with the matched holes if successful.
@@ -34,20 +34,20 @@ trait CompilerInterface { self: scala.quoted.QuoteContext =>
3434
* - scala.internal.Quoted.patternHole[T]: hole that matches an expression `x` of type `Expr[U]`
3535
* if `U <:< T` and returns `x` as part of the match.
3636
*
37-
* @param scrutinee `Term` on which we are pattern matching
38-
* @param pattern `Term` containing the pattern tree
37+
* @param scrutinee `Expr` on which we are pattern matching
38+
* @param pattern `Expr` containing the pattern tree
3939
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Term``
4040
*/
41-
def termMatch(scrutinee: Term, pattern: Term): Option[Tuple]
41+
def exprMatch(scrutinee: scala.quoted.Expr[Any], pattern: scala.quoted.Expr[Any]): Option[Tuple]
4242

4343
/** Pattern matches the scrutineeType against the patternType and returns a tuple
4444
* with the matched holes if successful.
4545
*
46-
* @param scrutinee `TypeTree` on which we are pattern matching
47-
* @param pattern `TypeTree` containing the pattern tree
48-
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `quoted.Type[Ti]``
46+
* @param scrutinee `Type` on which we are pattern matching
47+
* @param pattern `Type` containing the pattern tree
48+
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `scala.quoted.Type[Ti]``
4949
*/
50-
def typeTreeMatch(scrutinee: TypeTree, pattern: TypeTree): Option[Tuple]
50+
def typeMatch(scrutinee: scala.quoted.Type[?], pattern: scala.quoted.Type[?]): Option[Tuple]
5151

5252
}
5353

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ object PickledQuote:
1818

1919
def unpickleExpr[T](pickledQuote: PickledQuote): QuoteContext ?=> Expr[T] =
2020
val qctx = CompilerInterface.quoteContextWithCompilerInterface(summon[QuoteContext])
21-
val tree = qctx.unpickleTerm(pickledQuote)
22-
new scala.internal.quoted.Expr(tree, qctx.hashCode).asInstanceOf[Expr[T]]
21+
qctx.unpickleExpr(pickledQuote).asInstanceOf[Expr[T]]
2322

2423
def unpickleType[T](pickledQuote: PickledQuote): QuoteContext ?=> Type[T] =
2524
val qctx = CompilerInterface.quoteContextWithCompilerInterface(summon[QuoteContext])
26-
val tree = qctx.unpickleTypeTree(pickledQuote)
27-
new scala.internal.quoted.Type(tree, qctx.hashCode).asInstanceOf[Type[T]]
25+
qctx.unpickleType(pickledQuote).asInstanceOf[Type[T]]
2826

2927
/** Create an instance of PickledExpr from encoded tasty and sequence of labmdas to fill holes
3028
*

0 commit comments

Comments
 (0)