Skip to content

Commit 9437a0f

Browse files
committed
Rename TASTy reflection method to reflect/reify
1 parent 4385494 commit 9437a0f

File tree

24 files changed

+42
-39
lines changed

24 files changed

+42
-39
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import dotty.tools.dotc.reporting.diagnostic.MessageContainer
88
trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with TastyCoreImpl {
99

1010
def QuotedExprDeco[T](x: scala.quoted.Expr[T]): QuotedExprAPI = new QuotedExprAPI {
11-
def toTasty(implicit ctx: Context): Term = PickledQuotes.quotedExprToTree(x)
11+
def reflect(implicit ctx: Context): Term = PickledQuotes.quotedExprToTree(x)
1212
}
1313

1414
def QuotedTypeDeco[T](x: scala.quoted.Type[T]): QuotedTypeAPI = new QuotedTypeAPI {
15-
def toTasty(implicit ctx: Context): TypeTree = PickledQuotes.quotedTypeToTree(x)
15+
def reflect(implicit ctx: Context): TypeTree = PickledQuotes.quotedTypeToTree(x)
1616
}
1717

1818
def TermToQuoteDeco(term: Term): TermToQuotedAPI = new TermToQuotedAPI {
1919

20-
def toExpr[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] = {
20+
def reify[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] = {
2121
typecheck(ctx)
2222
new scala.quoted.Exprs.TastyTreeExpr(term).asInstanceOf[scala.quoted.Expr[T]]
2323
}
@@ -28,7 +28,7 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with TastyCoreImpl {
2828
ctx0.typerState.setReporter(new Reporter {
2929
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = ()
3030
})
31-
val tp = QuotedTypeDeco(implicitly[scala.quoted.Type[T]]).toTasty
31+
val tp = QuotedTypeDeco(implicitly[scala.quoted.Type[T]]).reflect
3232
ctx0.typer.typed(term, tp.tpe)
3333
if (ctx0.reporter.hasErrors) {
3434
val stack = new Exception().getStackTrace

library/src/scala/tasty/reflect/QuotedOps.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ package scala.tasty.reflect
44
trait QuotedOps extends TastyCore {
55

66
trait QuotedExprAPI {
7-
def toTasty(implicit ctx: Context): Term
7+
/** View this expression `Expr[T]` as a `Term` */
8+
def reflect(implicit ctx: Context): Term
89
}
910
implicit def QuotedExprDeco[T](expr: quoted.Expr[T]): QuotedExprAPI
1011

1112
trait QuotedTypeAPI {
12-
def toTasty(implicit ctx: Context): TypeTree
13+
/** View this expression `Type[T]` as a `TypeTree` */
14+
def reflect(implicit ctx: Context): TypeTree
1315
}
1416
implicit def QuotedTypeDeco[T](tpe: quoted.Type[T]): QuotedTypeAPI
1517

1618
trait TermToQuotedAPI {
17-
def toExpr[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
19+
/** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */
20+
def reify[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
1821
}
1922
implicit def TermToQuoteDeco(term: Term): TermToQuotedAPI
2023

library/src/scala/tasty/util/ConstantExtractor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ class ConstantExtractor[T <: Tasty with Singleton](val tasty: T) {
2525
case Term.Inlined(_, Nil, e) => const(e)
2626
case _ => None
2727
}
28-
const(expr.toTasty)
28+
const(expr.reflect)
2929
}
3030
}

tests/neg/tasty-macro-assert-2/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Asserts {
1717
def impl(cond: Expr[Boolean])(implicit tasty: Tasty): Expr[Unit] = {
1818
import tasty._
1919

20-
val tree = cond.toTasty
20+
val tree = cond.reflect
2121

2222
def isOps(tpe: TypeOrBounds): Boolean = tpe match {
2323
case Type.SymRef(IsDefSymbol(sym), _) => sym.name == "Ops" // TODO check that the parent is Asserts
@@ -34,7 +34,7 @@ object Asserts {
3434

3535
tree match {
3636
case Term.Inlined(_, Nil, Term.Apply(Term.Select(OpsTree(left), op, _), right :: Nil)) =>
37-
'(assertTrue(~left.toExpr[Boolean])) // Buggy code. To generate the errors
37+
'(assertTrue(~left.reify[Boolean])) // Buggy code. To generate the errors
3838
case _ =>
3939
'(assertTrue(~cond))
4040
}

tests/neg/tasty-macro-assert/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Asserts {
1717
def impl(cond: Expr[Boolean])(implicit tasty: Tasty): Expr[Unit] = {
1818
import tasty._
1919

20-
val tree = cond.toTasty
20+
val tree = cond.reflect
2121

2222
def isOps(tpe: TypeOrBounds): Boolean = tpe match {
2323
case Type.SymRef(IsDefSymbol(sym), _) => sym.name == "Ops" // TODO check that the parent is Asserts
@@ -34,7 +34,7 @@ object Asserts {
3434

3535
tree match {
3636
case Term.Inlined(_, Nil, Term.Apply(Term.Select(OpsTree(left), op, _), right :: Nil)) =>
37-
'(assertTrue(~left.toExpr[Boolean])) // Buggy code. To generate the errors
37+
'(assertTrue(~left.reify[Boolean])) // Buggy code. To generate the errors
3838
case _ =>
3939
'(assertTrue(~cond))
4040
}

tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Foo {
1313
case IsValSymbol(sym) => sym.tree.show.toExpr
1414
case IsBindSymbol(sym) => sym.tree.show.toExpr
1515
}
16-
x.toTasty match {
16+
x.reflect match {
1717
case Term.Inlined(None, Nil, arg) => definitionString(arg)
1818
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node?
1919
}

tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Foo {
1313
case IsValSymbol(sym) => sym.tree.show.toExpr
1414
case IsBindSymbol(sym) => sym.tree.show.toExpr
1515
}
16-
x.toTasty match {
16+
x.reflect match {
1717
case Term.Inlined(None, Nil, arg) => definitionString(arg)
1818
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node?
1919
}

tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object Macros {
4141
}
4242
}
4343

44-
val tree = x.toTasty
44+
val tree = x.reflect
4545
output.traverseTree(tree)
4646
'(print(~buff.result().toExpr))
4747
}

tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Foo {
1717
case _ => '("NO DEFINTION")
1818
}
1919

20-
x.toTasty match {
20+
x.reflect match {
2121
case Term.Inlined(None, Nil, arg) => definitionString(arg)
2222
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node
2323
}

tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Foo {
1717
case _ => '("NO DEFINTION")
1818
}
1919

20-
x.toTasty match {
20+
x.reflect match {
2121
case Term.Inlined(None, Nil, arg) => definitionString(arg)
2222
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node
2323
}

tests/run-separate-compilation/i5119/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ object Macro {
88
implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc)
99
def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(implicit tasty: Tasty): Expr[String] = {
1010
import tasty._
11-
(sc.toTasty.underlyingArgument.show + "\n" + args.toTasty.underlyingArgument.show).toExpr
11+
(sc.reflect.underlyingArgument.show + "\n" + args.reflect.underlyingArgument.show).toExpr
1212
}
1313
}

tests/run-separate-compilation/i5119b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Macro {
77

88
def impl(arg1: Expr[Any], arg2: Expr[Any])(implicit tasty: Tasty): Expr[String] = {
99
import tasty._
10-
(arg1.toTasty.underlyingArgument.show + "\n" + arg2.toTasty.underlyingArgument.show).toExpr
10+
(arg1.reflect.underlyingArgument.show + "\n" + arg2.reflect.underlyingArgument.show).toExpr
1111
}
1212

1313
}

tests/run-separate-compilation/tasty-argument-tree-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Macros {
77

88
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
99
import tasty._
10-
val tree = x.toTasty
10+
val tree = x.reflect
1111
'{
1212
println()
1313
println("tree: " + ~tree.show.toExpr)

tests/run-separate-compilation/tasty-custom-show/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Macros {
3434
}
3535
}
3636

37-
val tree = x.toTasty
37+
val tree = x.reflect
3838
output.traverseTree(tree)
3939
'(print(~buff.result().toExpr))
4040
}

tests/run-separate-compilation/tasty-eval/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Macros {
2222
override def value(e: Expr[Int])(implicit tasty: Tasty): Option[Int] = {
2323
import tasty._
2424

25-
e.toTasty.tpe match {
25+
e.reflect.tpe match {
2626
case Type.SymRef(IsValSymbol(sym), pre) =>
2727
sym.tree.tpt.tpe match {
2828
case Type.ConstantType(Constant.Int(i)) => Some(i)

tests/run-separate-compilation/tasty-extractors-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macros {
1010
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1111
import tasty._
1212

13-
val tree = x.toTasty
13+
val tree = x.reflect
1414
val treeStr = tree.show
1515
val treeTpeStr = tree.tpe.show
1616

tests/run-separate-compilation/tasty-extractors-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macros {
1010
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1111
import tasty._
1212

13-
val tree = x.toTasty
13+
val tree = x.reflect
1414

1515
val treeStr = tree.show
1616
val treeTpeStr = tree.tpe.show

tests/run-separate-compilation/tasty-extractors-3/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Macros {
2020
}
2121
}
2222

23-
val tree = x.toTasty
23+
val tree = x.reflect
2424
traverser.traverseTree(tree)
2525
'(print(~buff.result().toExpr))
2626
}

tests/run-separate-compilation/tasty-extractors-types/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macros {
1010
def impl[T](x: Type[T])(implicit tasty: Tasty): Expr[Unit] = {
1111
import tasty._
1212

13-
val tree = x.toTasty
13+
val tree = x.reflect
1414
'{
1515
println(~tree.show.toExpr)
1616
println(~tree.tpe.show.toExpr)

tests/run-separate-compilation/tasty-indexed-map/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ object Index {
3838
case _ => Nil
3939
}
4040

41-
val key = name(k.toTasty.tpe)
42-
val keys = name(h.toTasty.tpe) :: names(t.toTasty.tpe)
41+
val key = name(k.reflect.tpe)
42+
val keys = name(h.reflect.tpe) :: names(t.reflect.tpe)
4343

4444
val index = keys.indexOf(key)
4545

tests/run-separate-compilation/tasty-macro-assert/quoted_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Asserts {
1717
def impl(cond: Expr[Boolean])(implicit tasty: Tasty): Expr[Unit] = {
1818
import tasty._
1919

20-
val tree = cond.toTasty
20+
val tree = cond.reflect
2121

2222
def isOps(tpe: TypeOrBounds): Boolean = tpe match {
2323
case Type.SymRef(IsDefSymbol(sym), _) => sym.name == "Ops"// TODO check that the parent is Asserts
@@ -35,8 +35,8 @@ object Asserts {
3535
tree match {
3636
case Term.Inlined(_, Nil, Term.Apply(Term.Select(OpsTree(left), op, _), right :: Nil)) =>
3737
op match {
38-
case "===" => '(assertEquals(~left.toExpr[Any], ~right.toExpr[Any]))
39-
case "!==" => '(assertNotEquals(~left.toExpr[Any], ~right.toExpr[Any]))
38+
case "===" => '(assertEquals(~left.reify[Any], ~right.reify[Any]))
39+
case "!==" => '(assertNotEquals(~left.reify[Any], ~right.reify[Any]))
4040
}
4141
case _ =>
4242
'(assertTrue(~cond))

tests/run-separate-compilation/tasty-subtyping/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ object Macros {
1212

1313
def isTypeEqualImpl[T, U](t: Type[T], u: Type[U])(implicit tasty: Tasty): Expr[Boolean] = {
1414
import tasty._
15-
val isTypeEqual = t.toTasty.tpe =:= u.toTasty.tpe
15+
val isTypeEqual = t.reflect.tpe =:= u.reflect.tpe
1616
isTypeEqual.toExpr
1717
}
1818

1919
def isSubTypeOfImpl[T, U](t: Type[T], u: Type[U])(implicit tasty: Tasty): Expr[Boolean] = {
2020
import tasty._
21-
val isTypeEqual = t.toTasty.tpe <:< u.toTasty.tpe
21+
val isTypeEqual = t.reflect.tpe <:< u.reflect.tpe
2222
isTypeEqual.toExpr
2323
}
2424
}

tests/run-separate-compilation/xml-interpolation-1/XmlQuote_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object XmlQuote {
2727

2828
def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match {
2929
case x :: xs =>
30-
val head = x.toExpr[Any]
30+
val head = x.reify[Any]
3131
val tail = liftListOfAny(xs)
3232
'{ ~head :: ~tail }
3333
case Nil => '(Nil)
@@ -45,7 +45,7 @@ object XmlQuote {
4545
tree.symbol.fullName == "scala.StringContext$.apply"
4646

4747
// XmlQuote.SCOps(StringContext.apply([p0, ...]: String*)
48-
val parts = receiver.toTasty.underlyingArgument match {
48+
val parts = receiver.reflect.underlyingArgument match {
4949
case Apply(conv, List(Apply(fun, List(Typed(Repeated(values), _)))))
5050
if isSCOpsConversion(conv) &&
5151
isStringContextApply(fun) &&
@@ -56,7 +56,7 @@ object XmlQuote {
5656
}
5757

5858
// [a0, ...]: Any*
59-
val Typed(Repeated(args0), _) = args.toTasty.underlyingArgument
59+
val Typed(Repeated(args0), _) = args.reflect.underlyingArgument
6060

6161
val string = parts.mkString("??")
6262
'(new Xml(~string.toExpr, ~liftListOfAny(args0)))

tests/run-separate-compilation/xml-interpolation-2/XmlQuote_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object XmlQuote {
3333
tree.symbol.fullName == "scala.StringContext.<init>"
3434

3535
// XmlQuote.SCOps(StringContext.apply([p0, ...]: String*)
36-
val parts: List[String] = receiver.toTasty.underlying match {
36+
val parts: List[String] = receiver.reflect.underlying match {
3737
case Apply(conv, List(ctx1)) if isSCOpsConversion(conv) =>
3838
ctx1 match {
3939
case Apply(fun, List(Typed(Repeated(values), _))) if isStringContextApply(fun) =>
@@ -48,13 +48,13 @@ object XmlQuote {
4848
}
4949

5050
// [a0, ...]: Any*
51-
val args2: Expr[List[Any]] = args.toTasty.underlyingArgument match {
51+
val args2: Expr[List[Any]] = args.reflect.underlyingArgument match {
5252
case Typed(Repeated(args0), _) => // statically known args, make list directly
5353
def liftListOfAny(lst: List[Expr[Any]]): Expr[List[Any]] = lst match {
5454
case x :: xs => '{ ~x :: ~liftListOfAny(xs) }
5555
case Nil => '(Nil)
5656
}
57-
liftListOfAny(args0.map(_.toExpr[Any]))
57+
liftListOfAny(args0.map(_.reify[Any]))
5858
case _ =>
5959
'((~args).toList)
6060

0 commit comments

Comments
 (0)