Skip to content

Remove deprecated tasty member #10165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion community-build/community-projects/PPrint
2 changes: 1 addition & 1 deletion community-build/community-projects/dotty-cps-async
Submodule dotty-cps-async updated 34 files
+4 −4 src/main/scala/cps/Async.scala
+7 −7 src/main/scala/cps/CpsExpr.scala
+2 −2 src/main/scala/cps/forest/ApplyTransform.scala
+5 −5 src/main/scala/cps/forest/ApplyTreeTransform.scala
+8 −8 src/main/scala/cps/forest/AssignTransform.scala
+1 −1 src/main/scala/cps/forest/AsyncTreeShifter.scala
+1 −1 src/main/scala/cps/forest/AwaitTreeTransform.scala
+5 −5 src/main/scala/cps/forest/BlockTransform.scala
+4 −4 src/main/scala/cps/forest/CpsTree.scala
+1 −1 src/main/scala/cps/forest/IdentTransform.scala
+1 −1 src/main/scala/cps/forest/IfTransform.scala
+2 −2 src/main/scala/cps/forest/ImportTransform.scala
+3 −3 src/main/scala/cps/forest/InlinedTransform.scala
+1 −1 src/main/scala/cps/forest/KnownTreeFragments.scala
+4 −4 src/main/scala/cps/forest/LambdaTreeTransform.scala
+2 −2 src/main/scala/cps/forest/MatchTreeTransform.scala
+3 −3 src/main/scala/cps/forest/NewTransform.scala
+2 −2 src/main/scala/cps/forest/ReturnTransform.scala
+10 −10 src/main/scala/cps/forest/RootTreeTransform.scala
+2 −2 src/main/scala/cps/forest/SelectTreeTransform.scala
+2 −2 src/main/scala/cps/forest/SuperTransform.scala
+2 −2 src/main/scala/cps/forest/ThisTransform.scala
+1 −1 src/main/scala/cps/forest/ThrowTransform.scala
+11 −11 src/main/scala/cps/forest/TransformUtil.scala
+6 −6 src/main/scala/cps/forest/TreeTransformScope.scala
+4 −4 src/main/scala/cps/forest/TryTransform.scala
+2 −2 src/main/scala/cps/forest/TypeApplyTransform.scala
+7 −7 src/main/scala/cps/forest/TypeApplyTreeTransform.scala
+2 −2 src/main/scala/cps/forest/TypedTransform.scala
+20 −20 src/main/scala/cps/forest/ValDefTransform.scala
+1 −1 src/main/scala/cps/forest/WhileTransform.scala
+1 −1 src/main/scala/cps/forest/application/ApplyArgRecordScope.scala
+1 −1 src/main/scala/cps/forest/application/MethodParamsDescriptorScope.scala
+1 −1 src/main/scala/cps/macroFlags/TypeMarkers.scala
5 changes: 1 addition & 4 deletions library/src-bootstrapped/scala/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ trait QuoteContext { self =>
*/
val reflect: scala.tasty.Reflection

@deprecated("Use `reflect` instead", "")
def tasty: reflect.type = reflect

/** Type of a QuoteContext provided by a splice within a quote that took this context.
* It is only required if working with the reflection API.
*
Expand All @@ -34,7 +31,7 @@ trait QuoteContext { self =>
* ```
*/
type Nested = QuoteContext {
val reflect: self.tasty.type
val reflect: self.reflect.type
}

}
3 changes: 1 addition & 2 deletions library/src-non-bootstrapped/scala/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package scala.quoted
trait QuoteContext { self =>

val reflect: scala.tasty.Reflection
def tasty: reflect.type = reflect

type Nested = QuoteContext {
val tasty: self.tasty.type
val reflect: self.reflect.type
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Macro {
inline def f(): Unit = ${ macroImplementation }

def macroImplementation(using qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty._
import qctx.reflect._
error("some error", rootPosition)
'{ println("Implementation in MacroCompileError") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.quoted._
object MacroRuntime {

def impl()(using qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty._
import qctx.reflect._
error("some error", rootPosition)
'{ println("Implementation in MacroCompileError") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ from the signature. The body of the `derived` method is shown below:

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

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

Expand Down Expand Up @@ -177,7 +177,7 @@ object Eq {
}

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
layout: doc-page
title: "TASTy Reflect"
title: "Quoted Reflect"
---

TASTy Reflect enables inspection and construction of Typed Abstract Syntax Trees
Reflection enables inspection and construction of Typed Abstract Syntax Trees
(Typed-AST). It may be used on quoted expressions (`quoted.Expr`) and quoted
types (`quoted.Type`) from [Macros](./macros.md) or on full TASTy files.

If you are writing macros, please first read [Macros](./macros.md).
You may find all you need without using TASTy Reflect.
You may find all you need without using reflection.


## API: From quotes and splices to TASTy reflect trees and back
## API: From quotes and splices to reflect trees and back

With `quoted.Expr` and `quoted.Type` we can compute code but also analyze code
by inspecting the ASTs. [Macros](./macros.md) provide the guarantee that the
generation of code will be type-correct. Using TASTy Reflect will break these
generation of code will be type-correct. Using reflect will break these
guarantees and may fail at macro expansion time, hence additional explicit
checks must be done.

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

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

def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
import qctx.tasty._
import qctx.reflect._
...
}
```

### Extractors

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

```scala
def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
import qctx.tasty._
import qctx.reflect._
val xTree: Term = x.unseal
xTree match {
case Inlined(_, _, Literal(Constant(n: Int))) =>
Expand All @@ -59,9 +59,9 @@ def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
```

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

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

def macroImpl(param: Expr[Boolean])(using qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty._
import qctx.reflect._
import util._

param.unseal.underlyingArgument match {
Expand All @@ -99,7 +99,7 @@ point.

```scala
def macroImpl()(qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty._
import qctx.reflect._
val pos = rootPosition

val path = pos.sourceFile.jpath.toString
Expand Down Expand Up @@ -136,7 +136,7 @@ def collectPatternVariables(tree: Tree)(implicit ctx: Context): List[Symbol] = {
```

A `TreeTraverser` extends a `TreeAccumulator` and performs the same traversal
but without returning any value. Finally a `TreeMap` performs a transformation.
but without returning any value. Finally, a `TreeMap` performs a transformation.

#### Let

Expand All @@ -150,8 +150,3 @@ def let(rhs: Term)(body: Ident => Term): Term = ...

def lets(terms: List[Term])(body: List[Term] => Term): Term = ...
```

## More Examples

* Start experimenting with TASTy Reflect ([link](https://github.com/nicolasstucki/tasty-reflection-exercise))

2 changes: 1 addition & 1 deletion scala3doc/src/dotty/dokka/tasty/TastyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ case class SbtDokkaTastyInspector(

override def run(implicit ctx: Context): Unit =
val qctx = QuoteContextImpl()
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.tasty.Tree])
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree])

end TastyInspectorPhase

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait TastyInspector:
self =>

/** Process a TASTy file using TASTy reflect */
protected def processCompilationUnit(using QuoteContext)(root: qctx.tasty.Tree): Unit
protected def processCompilationUnit(using QuoteContext)(root: qctx.reflect.Tree): Unit

/** Load and process TASTy files using TASTy reflect
*
Expand Down Expand Up @@ -85,7 +85,7 @@ trait TastyInspector:

override def run(implicit ctx: Context): Unit =
val qctx = QuoteContextImpl()
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.tasty.Tree])
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree])

end TastyInspectorPhase

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6976/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object macros {
inline def mcr(x: => Any) = ${mcrImpl('x)}

def mcrImpl(body: Expr[Any])(using ctx: QuoteContext) : Expr[Any] = {
import ctx.tasty._
import ctx.reflect._
body.unseal match { case Block(_, _) => '{2} }
}
}
4 changes: 2 additions & 2 deletions tests/pos-macros/i7011/Macros_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import scala.quoted._

inline def mcr(body: => Any): Unit = ${mcrImpl('body)}

def mcrImpl[T](body: Expr[Any])(using ctx: QuoteContext) : Expr[Any] = {
import ctx.tasty.{_, given}
def mcrImpl[T](body: Expr[Any])(using QuoteContext) : Expr[Any] = {
import qctx.reflect._

val bTree = body.unseal
val under = bTree.underlyingArgument
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-macros/i7030/Macros_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def innerImpl(exprs: Expr[Any])(using QuoteContext): Expr[Any] =
'{$exprs ; ()}

inline def outer(expr: => Any): Any = ${outerImpl('expr)}
def outerImpl(body: Expr[Any])(using ctx: QuoteContext): Expr[Any] = {
import ctx.tasty._
def outerImpl(body: Expr[Any])(using QuoteContext): Expr[Any] = {
import qctx.reflect._
body.unseal.underlyingArgument.seal
}
4 changes: 2 additions & 2 deletions tests/pos-macros/i8651b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ object Macros {

inline def coroutine[T](inline body: Any): Coroutine[T] = ${ coroutineImpl('{body}) }

def coroutineImpl[T: Type](expr: Expr[_ <: Any])(implicit qtx: QuoteContext): Expr[Coroutine[T]] = {
import qtx.tasty.{_, given}
def coroutineImpl[T: Type](expr: Expr[_ <: Any])(using QuoteContext): Expr[Coroutine[T]] = {
import qctx.reflect._

'{
new Coroutine[T] {
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i9240/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inline def diveInto[T]: String = ${ diveIntoImpl[T]() }

def diveIntoImpl[T]()(implicit qctx: QuoteContext, ttype: Type[T]): Expr[String] =
import qctx.reflect._
Expr( unwindType(qctx.tasty)(TypeRepr.of[T]) )
Expr( unwindType(qctx.reflect)(TypeRepr.of[T]) )

def unwindType(reflect: Reflection)(aType: reflect.TypeRepr): String =
import reflect._
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-macros/treemap-unapply/Macro.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import scala.quoted._

inline def mcr(x: => Unit): Unit = ${mcrImpl('x)}
def mcrImpl(x: Expr[Unit])(using ctx: QuoteContext) : Expr[Unit] =
import ctx.tasty._
def mcrImpl(x: Expr[Unit])(using QuoteContext) : Expr[Unit] =
import qctx.reflect._
val tr: Term = x.unseal
object m extends TreeMap
m.transformTerm(tr).seal.cast[Unit]
6 changes: 3 additions & 3 deletions tests/run-macros/i7008/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def mcrProxy(expr: Expr[Boolean])(using QuoteContext): Expr[Unit] = {
res
}

def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T])(using ctx: QuoteContext, tt: Type[T]): Expr[Unit] = {
import ctx.tasty._
def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T])(using QuoteContext, Type[T]): Expr[Unit] = {
import qctx.reflect._
val arg = Varargs(Seq('{(Box($expr))}))
Expr.betaReduce('{$func($arg)})
}
}
2 changes: 1 addition & 1 deletion tests/run-staging/i6992/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object macros {
class Foo { val x = 10 }

def mcrImpl(body: Expr[Any])(using ctx: QuoteContext): Expr[Any] = {
import ctx.tasty._
import ctx.reflect._
try {
body match {
case '{$x: Foo} => Expr(run(x).x)
Expand Down