Skip to content

Commit 1cd140c

Browse files
committed
Port to QuoteScope
1 parent d68daf4 commit 1cd140c

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ object Expr {
198198
* @param tpe quoted type of the implicit parameter
199199
* @param qctx current context
200200
*/
201-
def summon[T](using tpe: Type[T])(using qctx: QuoteContext): Option[Expr[T]] = {
202-
import qctx.tasty._
201+
def summon[T](using s: QuoteScope)(using tpe: s.Type[T]): Option[s.Expr[T]] = {
202+
import s.tasty._
203203
searchImplicit(tpe.unseal.tpe) match {
204-
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
204+
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[s.Expr[T]])
205205
case isf: ImplicitSearchFailure => None
206206
}
207207
}

library/src-bootstrapped/scala/quoted/QuoteScope.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ trait QuoteScope { self =>
6464
/** Quoted type (or kind) `T` */
6565
type Type[T <: AnyKind] <: scala.quoted.Type[T] // TODO replace `<: scala.quoted.Type[T]` with `<: tasty.Type`
6666

67+
object Type {
68+
// /** Show a source code like representation of this type without syntax highlight */
69+
// def show(using qctx: QuoteContext): String =
70+
// this.unseal.showWith(SyntaxHighlight.plain)
71+
72+
// /** Show a source code like representation of this type */
73+
// def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
74+
// this.unseal.showWith(syntaxHighlight)
75+
76+
/** View this expression `Type[T]` as a `tasty.TypeTree` */
77+
def [T <: AnyKind](tpe: Type[T]).unseal: self.tasty.TypeTree =
78+
self.tasty.internal.QuotedType_unseal(tpe.asInstanceOf[scala.quoted.Type[T]])(using self.tasty.rootContext)
79+
}
80+
6781
/** Low-level Typed AST API `tasty` meta-programming API.
6882
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
6983
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class Type[T <: AnyKind] private[scala] {
77
type `$splice` = T
88

99
/** Show a source code like representation of this type without syntax highlight */
10-
def show(using qctx: QuoteContext): String =
10+
def show(using s: QuoteScope): String =
1111
this.unseal.showWith(SyntaxHighlight.plain)
1212

1313
/** Show a source code like representation of this type */
14-
def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
14+
def show(syntaxHighlight: SyntaxHighlight)(using s: QuoteScope): String =
1515
this.unseal.showWith(syntaxHighlight)
1616

1717
/** View this expression `quoted.Type[T]` as a `TypeTree` */
18-
def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree =
19-
qctx.tasty.internal.QuotedType_unseal(this)(using qctx.tasty.rootContext)
18+
def unseal(using s: QuoteScope): s.tasty.TypeTree =
19+
s.tasty.internal.QuotedType_unseal(this)(using s.tasty.rootContext)
2020

2121
}
2222

library/src-bootstrapped/scala/quoted/Varargs.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ object Varargs {
1515
* '{ List(${Varargs(List(1, 2, 3))}: _*) } // equvalent to '{ List(1, 2, 3) }
1616
* ```
1717
*/
18-
def apply[T](xs: Seq[Expr[T]])(using tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
19-
import qctx.tasty._
20-
Repeated(xs.map[Term](_.unseal).toList, tp.unseal).seal.asInstanceOf[Expr[Seq[T]]]
18+
def apply[T](using s: QuoteScope)(xs: Seq[s.Expr[T]])(using tp: s.Type[T]): s.Expr[Seq[T]] = {
19+
import s.tasty._
20+
Repeated(xs.map[Term](_.unseal).toList, tp.unseal).seal.asInstanceOf[s.Expr[Seq[T]]]
2121
}
2222

2323
/** Matches a literal sequence of expressions and return a sequence of expressions.
@@ -32,10 +32,10 @@ object Varargs {
3232
* }
3333
* ```
3434
*/
35-
def unapply[T](expr: Expr[Seq[T]])(using qctx: QuoteContext): Option[Seq[Expr[T]]] = {
36-
import qctx.tasty._
37-
def rec(tree: Term): Option[Seq[Expr[T]]] = tree match {
38-
case Typed(Repeated(elems, _), _) => Some(elems.map(x => x.seal.asInstanceOf[Expr[T]]))
35+
def unapply[T](using s: QuoteScope)(expr: s.Expr[Seq[T]]): Option[Seq[s.Expr[T]]] = {
36+
import s.tasty._
37+
def rec(tree: Term): Option[Seq[s.Expr[T]]] = tree match {
38+
case Typed(Repeated(elems, _), _) => Some(elems.map(x => x.seal.asInstanceOf[s.Expr[T]]))
3939
case Block(Nil, e) => rec(e)
4040
case Inlined(_, Nil, e) => rec(e)
4141
case _ => None

tests/run-macros/i8007/Macro_1.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ object Macro1 {
1919
def test1Impl[T: Type](value: Expr[T])(using qctx: QuoteContext): Expr[List[String]] = {
2020
import qctx.tasty._
2121

22-
val mirrorTpe = '[Mirror.Of[T]]
23-
24-
Expr.summon(using mirrorTpe).get match {
22+
Expr.summon[Mirror.Of[T]].get match {
2523
case '{ $m: Mirror.ProductOf[T]{ type MirroredElemLabels = $t } } => {
2624
Expr(mirrorFields(t))
2725
}

tests/run-macros/i8007/Macro_2.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ object Macro2 {
4545
def test2Impl[T: Type](value: Expr[T])(using qctx: QuoteContext): Expr[Unit] = {
4646
import qctx.tasty._
4747

48-
val mirrorTpe = '[Mirror.Of[T]]
49-
val mirrorExpr = Expr.summon(using mirrorTpe).get
48+
val mirrorExpr = Expr.summon[Mirror.Of[T]].get
5049
val derivedInstance = JsonEncoder.derived(mirrorExpr)
5150

5251
'{

tests/run-macros/i8007/Macro_3.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object Eq {
3535
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
3636
import qctx.tasty._
3737

38-
val ev: Expr[Mirror.Of[T]] = Expr.summon(using '[Mirror.Of[T]]).get
38+
val ev: Expr[Mirror.Of[T]] = Expr.summon[Mirror.Of[T]].get
3939

4040
ev match {
4141
case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = $elementTypes }} =>

tests/run-macros/string-context-implicits/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using
99
val argShowedExprs = argExprs.map {
1010
case '{ $arg: $tp } =>
1111
val showTp = '[Show[$tp]]
12-
Expr.summon(using showTp) match {
12+
Expr.summon[Show[$tp]] match {
1313
case Some(showExpr) => '{ $showExpr.show($arg) }
1414
case None => Reporting.error(s"could not find implicit for ${showTp.show}", arg); '{???}
1515
}

0 commit comments

Comments
 (0)