Skip to content

Commit c900cde

Browse files
Merge pull request #9961 from dotty-staging/rename-reflect-tasty-to-ast
Rename Reflection `tasty` to `reflect`
2 parents 35c05ca + 01a1dcf commit c900cde

File tree

171 files changed

+341
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+341
-336
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface
9898
*/
9999
object Matcher {
100100

101-
abstract class QuoteMatcher[QCtx <: QuoteContext { val tasty: scala.internal.tasty.CompilerInterface } & Singleton](val qctx: QCtx) {
101+
abstract class QuoteMatcher[QCtx <: QuoteContext { val reflect: scala.internal.tasty.CompilerInterface } & Singleton](val qctx: QCtx) {
102102

103103
// TODO improve performance
104104

105-
// TODO use flag from qctx.tasty. Maybe -debug or add -debug-macros
105+
// TODO use flag from qctx.reflect. Maybe -debug or add -debug-macros
106106
private final val debug = false
107107

108-
import qctx.tasty._
108+
import qctx.reflect._
109109
import Matching._
110110

111111
def patternHoleSymbol: Symbol

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ object QuoteContextImpl {
3030
val syntaxHighlight =
3131
if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI
3232
else SyntaxHighlight.plain
33-
show(using qctx)(tree.asInstanceOf[qctx.tasty.Tree], syntaxHighlight)(using ctx.asInstanceOf[qctx.tasty.Context])
33+
show(using qctx)(tree.asInstanceOf[qctx.reflect.Tree], syntaxHighlight)(using ctx.asInstanceOf[qctx.reflect.Context])
3434
}
3535

36-
private def show(using qctx: QuoteContext)(tree: qctx.tasty.Tree, syntaxHighlight: SyntaxHighlight)(using qctx.tasty.Context) =
36+
private def show(using qctx: QuoteContext)(tree: qctx.reflect.Tree, syntaxHighlight: SyntaxHighlight)(using qctx.reflect.Context) =
3737
tree.showWith(syntaxHighlight)
3838

3939
private[dotty] def checkScopeId(id: ScopeId)(using Context): Unit =
@@ -49,7 +49,7 @@ object QuoteContextImpl {
4949

5050
class QuoteContextImpl private (ctx: Context) extends QuoteContext:
5151

52-
object tasty extends scala.tasty.Reflection, scala.internal.tasty.CompilerInterface:
52+
object reflect extends scala.tasty.Reflection, scala.internal.tasty.CompilerInterface:
5353

5454
def rootContext: Context = ctx
5555

@@ -67,11 +67,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
6767
def pos: Position = self.sourcePos
6868
def symbol: Symbol = self.symbol
6969
def showExtractors: String =
70-
new ExtractorsPrinter[tasty.type](tasty).showTree(self)
70+
new ExtractorsPrinter[reflect.type](reflect).showTree(self)
7171
def show: String =
7272
self.showWith(SyntaxHighlight.plain)
7373
def showWith(syntaxHighlight: SyntaxHighlight): String =
74-
new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showTree(self)
74+
new SourceCodePrinter[reflect.type](reflect)(syntaxHighlight).showTree(self)
7575
def isExpr: Boolean =
7676
self match
7777
case TermTypeTest(self) =>
@@ -1584,13 +1584,13 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
15841584
object TypeMethodsImpl extends TypeMethods:
15851585
extension (self: Type):
15861586
def showExtractors: String =
1587-
new ExtractorsPrinter[tasty.type](tasty).showType(self)
1587+
new ExtractorsPrinter[reflect.type](reflect).showType(self)
15881588

15891589
def show: String =
15901590
self.showWith(SyntaxHighlight.plain)
15911591

15921592
def showWith(syntaxHighlight: SyntaxHighlight): String =
1593-
new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showType(self)
1593+
new SourceCodePrinter[reflect.type](reflect)(syntaxHighlight).showType(self)
15941594

15951595
def seal: scala.quoted.Type[_] =
15961596
new scala.internal.quoted.Type(Inferred(self), QuoteContextImpl.this.hashCode)
@@ -2164,11 +2164,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
21642164
extension (self: Constant):
21652165
def value: Any = self.value
21662166
def showExtractors: String =
2167-
new ExtractorsPrinter[tasty.type](tasty).showConstant(self)
2167+
new ExtractorsPrinter[reflect.type](reflect).showConstant(self)
21682168
def show: String =
21692169
self.showWith(SyntaxHighlight.plain)
21702170
def showWith(syntaxHighlight: SyntaxHighlight): String =
2171-
new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showConstant(self)
2171+
new SourceCodePrinter[reflect.type](reflect)(syntaxHighlight).showConstant(self)
21722172
end extension
21732173
end ConstantMethodsImpl
21742174

@@ -2387,11 +2387,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
23872387
def children: List[Symbol] = self.denot.children
23882388

23892389
def showExtractors: String =
2390-
new ExtractorsPrinter[tasty.type](tasty).showSymbol(self)
2390+
new ExtractorsPrinter[reflect.type](reflect).showSymbol(self)
23912391
def show: String =
23922392
self.showWith(SyntaxHighlight.plain)
23932393
def showWith(syntaxHighlight: SyntaxHighlight): String =
2394-
new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showSymbol(self)
2394+
new SourceCodePrinter[reflect.type](reflect)(syntaxHighlight).showSymbol(self)
23952395

23962396
end extension
23972397

@@ -2523,11 +2523,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25232523
def |(that: Flags): Flags = dotc.core.Flags.extension_|(self)(that)
25242524
def &(that: Flags): Flags = dotc.core.Flags.extension_&(self)(that)
25252525
def showExtractors: String =
2526-
new ExtractorsPrinter[tasty.type](tasty).showFlags(self)
2526+
new ExtractorsPrinter[reflect.type](reflect).showFlags(self)
25272527
def show: String =
25282528
self.showWith(SyntaxHighlight.plain)
25292529
def showWith(syntaxHighlight: SyntaxHighlight): String =
2530-
new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showFlags(self)
2530+
new SourceCodePrinter[reflect.type](reflect)(syntaxHighlight).showFlags(self)
25312531
end extension
25322532
end FlagsMethodsImpl
25332533

@@ -2647,7 +2647,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
26472647
ctx1
26482648

26492649
val qctx1 = dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1)
2650-
.asInstanceOf[QuoteContext { val tasty: QuoteContextImpl.this.tasty.type }]
2650+
.asInstanceOf[QuoteContext { val reflect: QuoteContextImpl.this.reflect.type }]
26512651

26522652
val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) {
26532653
def patternHoleSymbol: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_patternHole
@@ -2671,7 +2671,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
26712671
}
26722672
}
26732673

2674-
end tasty
2674+
end reflect
26752675

26762676
private[this] val hash = QuoteContextImpl.scopeId(using ctx)
26772677
override def hashCode: Int = hash

docs/docs/reference/contextual/derivation-macro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ from the signature. The body of the `derived` method is shown below:
4242

4343
```scala
4444
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
45-
import qctx.tasty._
45+
import qctx.reflect._
4646

4747
val ev: Expr[Mirror.Of[T]] = Expr.summon(using '[Mirror.Of[T]]).get
4848

@@ -177,7 +177,7 @@ object Eq {
177177
}
178178

179179
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
180-
import qctx.tasty._
180+
import qctx.reflect._
181181

182182
val ev: Expr[Mirror.Of[T]] = Expr.summon(using '[Mirror.Of[T]]).get
183183

docs/docs/reference/metaprogramming/tasty-reflect.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ guarantees and may fail at macro expansion time, hence additional explicit
2020
checks must be done.
2121

2222
To provide reflection capabilities in macros we need to add an implicit
23-
parameter of type `scala.quoted.QuoteContext` and import `tasty._` from it in
23+
parameter of type `scala.quoted.QuoteContext` and import `qctx.reflect._` from it in
2424
the scope where it is used.
2525

2626
```scala
@@ -29,19 +29,19 @@ import scala.quoted._
2929
inline def natConst(x: => Int): Int = ${natConstImpl('{x})}
3030

3131
def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
32-
import qctx.tasty._
32+
import qctx.reflect._
3333
...
3434
}
3535
```
3636

3737
### Extractors
3838

39-
`import qctx.tasty._` will provide all extractors and methods on TASTy Reflect
39+
`import qctx.reflect._` will provide all extractors and methods on TASTy Reflect
4040
trees. For example the `Literal(_)` extractor used below.
4141

4242
```scala
4343
def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
44-
import qctx.tasty._
44+
import qctx.reflect._
4545
val xTree: Term = x.unseal
4646
xTree match {
4747
case Inlined(_, _, Literal(Constant(n: Int))) =>
@@ -59,9 +59,9 @@ def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
5959
```
6060

6161
To easily know which extractors are needed, the `showExtractors` method on a
62-
`qctx.tasty.Term` returns the string representation of the extractors.
62+
`qctx.reflect.Term` returns the string representation of the extractors.
6363

64-
The method `qctx.tasty.Term.seal` provides a way to go back to a
64+
The method `qctx.reflect.Term.seal` provides a way to go back to a
6565
`quoted.Expr[Any]`. Note that the type is `Expr[Any]`. Consequently, the type
6666
must be set explicitly with a checked `cast` call. If the type does not conform
6767
to it an exception will be thrown at runtime.
@@ -77,7 +77,7 @@ operation expression passed while calling the `macro` below.
7777
inline def macro(param: => Boolean): Unit = ${ macroImpl('param) }
7878

7979
def macroImpl(param: Expr[Boolean])(using qctx: QuoteContext): Expr[Unit] = {
80-
import qctx.tasty._
80+
import qctx.reflect._
8181
import util._
8282

8383
param.unseal.underlyingArgument match {
@@ -91,15 +91,15 @@ macro(this.checkCondition())
9191

9292
### Positions
9393

94-
The tasty context provides a `rootPosition` value. It corresponds to
94+
The `ast` in the context provides a `rootPosition` value. It corresponds to
9595
the expansion site for macros. The macro authors can obtain various information about that
9696
expansion site. The example below shows how we can obtain position information
9797
such as the start line, the end line or even the source code at the expansion
9898
point.
9999

100100
```scala
101101
def macroImpl()(qctx: QuoteContext): Expr[Unit] = {
102-
import qctx.tasty._
102+
import qctx.reflect._
103103
val pos = rootPosition
104104

105105
val path = pos.sourceFile.jpath.toString

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface
1919
case _ => false
2020
}
2121

22-
def unseal(using qctx: QuoteContext): qctx.tasty.Term =
22+
def unseal(using qctx: QuoteContext): qctx.reflect.Term =
2323
if (qctx.hashCode != scopeId)
2424
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
25-
tree.asInstanceOf[qctx.tasty.Term]
25+
tree.asInstanceOf[qctx.reflect.Term]
2626

2727
override def hashCode: Int = tree.hashCode
2828
override def toString: String = "'{ ... }"
@@ -54,18 +54,18 @@ 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.tasty.termMatch(scrutineeExpr.unseal, patternExpr.unseal).asInstanceOf[Option[Tup]]
57+
qctx1.reflect.termMatch(scrutineeExpr.unseal, patternExpr.unseal).asInstanceOf[Option[Tup]]
5858
}
5959

6060
/** Returns a null expresssion equivalent to `'{null}` */
6161
def `null`: QuoteContext ?=> quoted.Expr[Null] = qctx ?=> {
62-
import qctx.tasty._
62+
import qctx.reflect._
6363
Literal(Constant.Null()).seal.asInstanceOf[quoted.Expr[Null]]
6464
}
6565

6666
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
6767
def Unit: QuoteContext ?=> quoted.Expr[Unit] = qctx ?=> {
68-
import qctx.tasty._
68+
import qctx.reflect._
6969
Literal(Constant.Unit()).seal.asInstanceOf[quoted.Expr[Unit]]
7070
}
7171

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote
1414
}
1515

1616
/** View this expression `quoted.Type[T]` as a `TypeTree` */
17-
def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree =
17+
def unseal(using qctx: QuoteContext): qctx.reflect.TypeTree =
1818
if (qctx.hashCode != scopeId)
1919
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
20-
typeTree.asInstanceOf[qctx.tasty.TypeTree]
20+
typeTree.asInstanceOf[qctx.reflect.TypeTree]
2121

2222
override def hashCode: Int = typeTree.hashCode
2323
override def toString: String = "'[ ... ]"
@@ -37,37 +37,37 @@ 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.tasty.typeTreeMatch(scrutineeType.unseal, patternType.unseal).asInstanceOf[Option[Tup]]
40+
qctx1.reflect.typeTreeMatch(scrutineeType.unseal, patternType.unseal).asInstanceOf[Option[Tup]]
4141
}
4242

4343

4444
// TODO generalize following optimizations for all classes without parameters
4545

4646
def Unit: QuoteContext ?=> quoted.Type[Unit] =
47-
qctx.tasty.Type.typeConstructorOf(classOf[Unit]).seal.asInstanceOf[quoted.Type[Unit]]
47+
qctx.reflect.Type.typeConstructorOf(classOf[Unit]).seal.asInstanceOf[quoted.Type[Unit]]
4848

4949
def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
50-
qctx.tasty.Type.typeConstructorOf(classOf[Boolean]).seal.asInstanceOf[quoted.Type[Boolean]]
50+
qctx.reflect.Type.typeConstructorOf(classOf[Boolean]).seal.asInstanceOf[quoted.Type[Boolean]]
5151

5252
def Byte: QuoteContext ?=> quoted.Type[Byte] =
53-
qctx.tasty.Type.typeConstructorOf(classOf[Byte]).seal.asInstanceOf[quoted.Type[Byte]]
53+
qctx.reflect.Type.typeConstructorOf(classOf[Byte]).seal.asInstanceOf[quoted.Type[Byte]]
5454

5555
def Char: QuoteContext ?=> quoted.Type[Char] =
56-
qctx.tasty.Type.typeConstructorOf(classOf[Char]).seal.asInstanceOf[quoted.Type[Char]]
56+
qctx.reflect.Type.typeConstructorOf(classOf[Char]).seal.asInstanceOf[quoted.Type[Char]]
5757

5858
def Short: QuoteContext ?=> quoted.Type[Short] =
59-
qctx.tasty.Type.typeConstructorOf(classOf[Short]).seal.asInstanceOf[quoted.Type[Short]]
59+
qctx.reflect.Type.typeConstructorOf(classOf[Short]).seal.asInstanceOf[quoted.Type[Short]]
6060

6161
def Int: QuoteContext ?=> quoted.Type[Int] =
62-
qctx.tasty.Type.typeConstructorOf(classOf[Int]).seal.asInstanceOf[quoted.Type[Int]]
62+
qctx.reflect.Type.typeConstructorOf(classOf[Int]).seal.asInstanceOf[quoted.Type[Int]]
6363

6464
def Long: QuoteContext ?=> quoted.Type[Long] =
65-
qctx.tasty.Type.typeConstructorOf(classOf[Long]).seal.asInstanceOf[quoted.Type[Long]]
65+
qctx.reflect.Type.typeConstructorOf(classOf[Long]).seal.asInstanceOf[quoted.Type[Long]]
6666

6767
def Float: QuoteContext ?=> quoted.Type[Float] =
68-
qctx.tasty.Type.typeConstructorOf(classOf[Float]).seal.asInstanceOf[quoted.Type[Float]]
68+
qctx.reflect.Type.typeConstructorOf(classOf[Float]).seal.asInstanceOf[quoted.Type[Float]]
6969

7070
def Double: QuoteContext ?=> quoted.Type[Double] =
71-
qctx.tasty.Type.typeConstructorOf(classOf[Double]).seal.asInstanceOf[quoted.Type[Double]]
71+
qctx.reflect.Type.typeConstructorOf(classOf[Double]).seal.asInstanceOf[quoted.Type[Double]]
7272

7373
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ object Unpickler {
1414
*/
1515
def unpickleExpr[T](repr: PickledQuote, args: PickledArgs): QuoteContext ?=> Expr[T] =
1616
val qctx = quoteContextWithCompilerInterface(summon[QuoteContext])
17-
val tree = qctx.tasty.unpickleExpr(repr, args)
17+
val tree = qctx.reflect.unpickleExpr(repr, args)
1818
new scala.internal.quoted.Expr(tree, qctx.hashCode).asInstanceOf[Expr[T]]
1919

2020
/** Unpickle `repr` which represents a pickled `Type` tree,
2121
* replacing splice nodes with `args`
2222
*/
2323
def unpickleType[T](repr: PickledQuote, args: PickledArgs): QuoteContext ?=> Type[T] =
2424
val qctx = quoteContextWithCompilerInterface(summon[QuoteContext])
25-
val tree = qctx.tasty.unpickleType(repr, args)
25+
val tree = qctx.reflect.unpickleType(repr, args)
2626
new scala.internal.quoted.Type(tree, qctx.hashCode).asInstanceOf[Type[T]]
2727

2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Const {
1515
* ```
1616
*/
1717
def unapply[T](expr: Expr[T])(using qctx: QuoteContext): Option[T] = {
18-
import qctx.tasty._
18+
import qctx.reflect._
1919
def rec(tree: Term): Option[T] = tree match {
2020
case Literal(c) => Some(c.value.asInstanceOf[T])
2121
case Block(Nil, e) => rec(e)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class Expr[+T] private[scala] {
4444
}
4545

4646
/** View this expression `quoted.Expr[T]` as a `Term` */
47-
def unseal(using qctx: QuoteContext): qctx.tasty.Term
47+
def unseal(using qctx: QuoteContext): qctx.reflect.Term
4848

4949
}
5050

@@ -80,7 +80,7 @@ object Expr {
8080
* Some bindings may be elided as an early optimization.
8181
*/
8282
def betaReduce[T](expr: Expr[T])(using qctx: QuoteContext): Expr[T] =
83-
qctx.tasty.Term.betaReduce(expr.unseal) match
83+
qctx.reflect.Term.betaReduce(expr.unseal) match
8484
case Some(expr1) => expr1.seal.asInstanceOf[Expr[T]]
8585
case _ => expr
8686

@@ -89,7 +89,7 @@ object Expr {
8989
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
9090
*/
9191
def block[T](statements: List[Expr[Any]], expr: Expr[T])(using qctx: QuoteContext): Expr[T] = {
92-
import qctx.tasty._
92+
import qctx.reflect._
9393
Block(statements.map(_.unseal), expr.unseal).seal.asInstanceOf[Expr[T]]
9494
}
9595

@@ -191,7 +191,7 @@ object Expr {
191191
* @param qctx current context
192192
*/
193193
def summon[T](using tpe: Type[T])(using qctx: QuoteContext): Option[Expr[T]] = {
194-
import qctx.tasty._
194+
import qctx.reflect._
195195
Implicits.search(tpe.unseal.tpe) match {
196196
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
197197
case isf: ImplicitSearchFailure => None

0 commit comments

Comments
 (0)