Skip to content

Commit 1af9030

Browse files
committed
Rename TASTy Reflect reflect/reify methods
1 parent e4bb0b4 commit 1af9030

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
}

0 commit comments

Comments
 (0)