Skip to content

Commit 11a9a78

Browse files
Merge pull request #5474 from dotty-staging/rename-tasty-to-quote-methods
Rename reflect/reify and make them plain methods
2 parents a64e083 + 1af9030 commit 11a9a78

File tree

26 files changed

+61
-60
lines changed

26 files changed

+61
-60
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 CoreImpl {
99

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

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

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

20-
def reify[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] = {
20+
def seal[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 CoreImpl {
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]]).reflect
31+
val tp = QuotedTypeDeco(implicitly[scala.quoted.Type[T]]).unseal
3232
ctx0.typer.typed(term, tp.tpe)
3333
if (ctx0.reporter.hasErrors) {
3434
val stack = new Exception().getStackTrace

docs/docs/reference/tasty-reflect.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
layout: doc-page
3-
title: "TASTy reflect"
3+
title: "TASTy Reflect"
44
---
55

66
TASTy Reflect enables inspection and construction of Typed Abstract Syntax Trees (TAST).
77
It may be used on quoted expressions (`quoted.Expr`) and quoted types (`quoted.Type`) from [Principled Meta-programming](./principled-meta-programming.html)
88
or on full TASTy files.
99

10-
If you are writing macros, please first read [Principled Meta-programming](./principled-meta-programming.html).
10+
If you are writing macros, please first read [Principled Meta-programming](./principled-meta-programming.html).
1111
You may find all you need without using TASTy Reflect.
1212

1313

@@ -32,13 +32,13 @@ def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = {
3232
}
3333
```
3434

35-
`import reflection._` will provide a `reflect` extension method on `quoted.Expr` and `quoted.Type` which return a `reflection.Term` and `reflection.TypeTree` respectively.
35+
`import reflection._` will provide a `unseal` extension method on `quoted.Expr` and `quoted.Type` which return a `reflection.Term` and `reflection.TypeTree` respectively.
3636
It will also import all extractors and methods on TASTy Reflect trees. For example the `Term.Literal(_)` extractor used below.
3737

3838
```scala
3939
def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = {
4040
import reflection._
41-
val xTree: Term = x.reflect
41+
val xTree: Term = x.unseal
4242
xTree match {
4343
case Term.Literal(Constant.Int(n)) =>
4444
if (n <= 0)
@@ -53,9 +53,10 @@ def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = {
5353
To easily know which extractors are needed, the `reflection.Term.show` method returns the string representation of the extractors.
5454

5555
The method `reflection.Term.reify[T]` provides a way to to go back to a `quoted.Expr`.
56-
Note that the type must be set explicitly and that if it does not conform to it an exception will be thrown.
56+
Note that the type must be set explicitly and that if it does not conform to it an exception will be thrown.
5757
In the code above we could have replaced `n.toExpr` by `xTree.reify[Int]`.
58-
58+
59+
5960
## Inspect a TASTy file
6061

6162
To inspect the TASTy Reflect trees of a TASTy file a consumer can be defined in the following way.
@@ -78,7 +79,7 @@ object Test {
7879
}
7980
}
8081
```
81-
82+
8283
## TASTy Reflect API
8384

8485
TASTy Reflect provides the following types:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ trait QuotedOps extends Core {
55

66
trait QuotedExprAPI {
77
/** View this expression `Expr[T]` as a `Term` */
8-
def reflect(implicit ctx: Context): Term
8+
def unseal(implicit ctx: Context): Term
99
}
1010
implicit def QuotedExprDeco[T](expr: quoted.Expr[T]): QuotedExprAPI
1111

1212
trait QuotedTypeAPI {
1313
/** View this expression `Type[T]` as a `TypeTree` */
14-
def reflect(implicit ctx: Context): TypeTree
14+
def unseal(implicit ctx: Context): TypeTree
1515
}
1616
implicit def QuotedTypeDeco[T](tpe: quoted.Type[T]): QuotedTypeAPI
1717

1818
trait TermToQuotedAPI {
1919
/** 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]
20+
def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
2121
}
2222
implicit def TermToQuoteDeco(term: Term): TermToQuotedAPI
2323

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[R <: Reflection with Singleton](val reflect: Reflection)
2525
case Term.Inlined(_, Nil, e) => const(e)
2626
case _ => None
2727
}
28-
const(expr.reflect)
28+
const(expr.unseal)
2929
}
3030
}

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 reflect: Reflection): Expr[Unit] = {
1818
import reflect._
1919

20-
val tree = cond.reflect
20+
val tree = cond.unseal
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.reify[Boolean])) // Buggy code. To generate the errors
37+
'(assertTrue(~left.seal[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.reflect match {
16+
x.unseal 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.reflect match {
16+
x.unseal 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
@@ -40,7 +40,7 @@ object Macros {
4040
}
4141
}
4242

43-
val tree = x.reflect
43+
val tree = x.unseal
4444
output.traverseTree(tree)
4545
'(print(~buff.result().toExpr))
4646
}

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.reflect match {
20+
x.unseal 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.reflect match {
20+
x.unseal 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/gestalt-type-toolbox-reflect/Macro_1.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ object TypeToolbox {
99
inline def =:=[A, B]: Boolean = ~tpEqImpl('[A], '[B])
1010
private def tpEqImpl[A, B](a: Type[A], b: Type[B])(implicit reflect: Reflection): Expr[Boolean] = {
1111
import reflect._
12-
val res = a.reflect.tpe =:= b.reflect.tpe
12+
val res = a.unseal.tpe =:= b.unseal.tpe
1313
res.toExpr
1414
}
1515

1616
/** is `tp1` a subtype of `tp2` */
1717
inline def <:<[A, B]: Boolean = ~tpLEqImpl('[A], '[B])
1818
private def tpLEqImpl[A, B](a: Type[A], b: Type[B])(implicit reflect: Reflection): Expr[Boolean] = {
1919
import reflect._
20-
val res = a.reflect.tpe <:< b.reflect.tpe
20+
val res = a.unseal.tpe <:< b.unseal.tpe
2121
res.toExpr
2222
}
2323

2424
/** type associated with the tree */
2525
inline def typeOf[T, Expected](a: T): Boolean = ~typeOfImpl('(a), '[Expected])
2626
private def typeOfImpl(a: Expr[_], expected: Type[_])(implicit reflect: Reflection): Expr[Boolean] = {
2727
import reflect._
28-
val res = a.reflect.tpe =:= expected.reflect.tpe
28+
val res = a.unseal.tpe =:= expected.unseal.tpe
2929
res.toExpr
3030
}
3131

3232
/** does the type refer to a case class? */
3333
inline def isCaseClass[A]: Boolean = ~isCaseClassImpl('[A])
3434
private def isCaseClassImpl(tp: Type[_])(implicit reflect: Reflection): Expr[Boolean] = {
3535
import reflect._
36-
val res = tp.reflect.symbol match {
36+
val res = tp.unseal.symbol match {
3737
case IsClassSymbol(sym) => sym.flags.isCase
3838
case _ => false
3939
}
@@ -44,66 +44,66 @@ object TypeToolbox {
4444
inline def caseFields[T]: List[String] = ~caseFieldsImpl('[T])
4545
private def caseFieldsImpl(tp: Type[_])(implicit reflect: Reflection): Expr[List[String]] = {
4646
import reflect._
47-
val fields = tp.reflect.symbol.asClass.caseFields.map(_.name)
47+
val fields = tp.unseal.symbol.asClass.caseFields.map(_.name)
4848
fields.toExpr
4949
}
5050

5151
inline def fieldIn[T](inline mem: String): String = ~fieldInImpl('[T], mem)
5252
private def fieldInImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[String] = {
5353
import reflect._
54-
val field = t.reflect.symbol.asClass.field(mem)
54+
val field = t.unseal.symbol.asClass.field(mem)
5555
field.map(_.name).getOrElse("").toExpr
5656
}
5757

5858
inline def fieldsIn[T]: Seq[String] = ~fieldsInImpl('[T])
5959
private def fieldsInImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = {
6060
import reflect._
61-
val fields = t.reflect.symbol.asClass.fields
61+
val fields = t.unseal.symbol.asClass.fields
6262
fields.map(_.name).toList.toExpr
6363
}
6464

6565
inline def methodIn[T](inline mem: String): Seq[String] = ~methodInImpl('[T], mem)
6666
private def methodInImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[Seq[String]] = {
6767
import reflect._
68-
t.reflect.symbol.asClass.classMethod(mem).map(_.name).toExpr
68+
t.unseal.symbol.asClass.classMethod(mem).map(_.name).toExpr
6969
}
7070

7171
inline def methodsIn[T]: Seq[String] = ~methodsInImpl('[T])
7272
private def methodsInImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = {
7373
import reflect._
74-
t.reflect.symbol.asClass.classMethods.map(_.name).toExpr
74+
t.unseal.symbol.asClass.classMethods.map(_.name).toExpr
7575
}
7676

7777
inline def method[T](inline mem: String): Seq[String] = ~methodImpl('[T], mem)
7878
private def methodImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[Seq[String]] = {
7979
import reflect._
80-
t.reflect.symbol.asClass.method(mem).map(_.name).toExpr
80+
t.unseal.symbol.asClass.method(mem).map(_.name).toExpr
8181
}
8282

8383
inline def methods[T]: Seq[String] = ~methodsImpl('[T])
8484
private def methodsImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = {
8585
import reflect._
86-
t.reflect.symbol.asClass.methods.map(_.name).toExpr
86+
t.unseal.symbol.asClass.methods.map(_.name).toExpr
8787
}
8888

8989
inline def typeTag[T](x: T): String = ~typeTagImpl('[T])
9090
private def typeTagImpl(tp: Type[_])(implicit reflect: Reflection): Expr[String] = {
9191
import reflect._
92-
val res = tp.reflect.tpe.showCode
92+
val res = tp.unseal.tpe.showCode
9393
res.toExpr
9494
}
9595

9696
inline def companion[T1, T2]: Boolean = ~companionImpl('[T1], '[T2])
9797
private def companionImpl(t1: Type[_], t2: Type[_])(implicit reflect: Reflection): Expr[Boolean] = {
9898
import reflect._
99-
val res = t1.reflect.symbol.asClass.companionModule.contains(t2.reflect.symbol)
99+
val res = t1.unseal.symbol.asClass.companionModule.contains(t2.unseal.symbol)
100100
res.toExpr
101101
}
102102

103103
inline def companionName[T1]: String = ~companionNameImpl('[T1])
104104
private def companionNameImpl(tp: Type[_])(implicit reflect: Reflection): Expr[String] = {
105105
import reflect._
106-
val companionClassOpt = tp.reflect.symbol match {
106+
val companionClassOpt = tp.unseal.symbol match {
107107
case IsClassSymbol(sym) => sym.companionClass
108108
case IsValSymbol(sym) => sym.companionClass
109109
case _ => None

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 reflect: Reflection): Expr[String] = {
1010
import reflect._
11-
(sc.reflect.underlyingArgument.show + "\n" + args.reflect.underlyingArgument.show).toExpr
11+
(sc.unseal.underlyingArgument.show + "\n" + args.unseal.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 reflect: Reflection): Expr[String] = {
99
import reflect._
10-
(arg1.reflect.underlyingArgument.show + "\n" + arg2.reflect.underlyingArgument.show).toExpr
10+
(arg1.unseal.underlyingArgument.show + "\n" + arg2.unseal.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 reflect: Reflection): Expr[Unit] = {
99
import reflect._
10-
val tree = x.reflect
10+
val tree = x.unseal
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
@@ -33,7 +33,7 @@ object Macros {
3333
}
3434
}
3535

36-
val tree = x.reflect
36+
val tree = x.unseal
3737
output.traverseTree(tree)
3838
'(print(~buff.result().toExpr))
3939
}

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

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

24-
e.reflect.tpe match {
24+
e.unseal.tpe match {
2525
case Type.SymRef(IsValSymbol(sym), pre) =>
2626
sym.tree.tpt.tpe match {
2727
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 reflect: Reflection): Expr[Unit] = {
1111
import reflect._
1212

13-
val tree = x.reflect
13+
val tree = x.unseal
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 reflect: Reflection): Expr[Unit] = {
1111
import reflect._
1212

13-
val tree = x.reflect
13+
val tree = x.unseal
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
@@ -19,7 +19,7 @@ object Macros {
1919
}
2020
}
2121

22-
val tree = x.reflect
22+
val tree = x.unseal
2323
traverser.traverseTree(tree)
2424
'(print(~buff.result().toExpr))
2525
}

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

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

12-
val tree = x.reflect
12+
val tree = x.unseal
1313
'{
1414
println(~tree.show.toExpr)
1515
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.reflect.tpe)
42-
val keys = name(h.reflect.tpe) :: names(t.reflect.tpe)
41+
val key = name(k.unseal.tpe)
42+
val keys = name(h.unseal.tpe) :: names(t.unseal.tpe)
4343

4444
val index = keys.indexOf(key)
4545

0 commit comments

Comments
 (0)