diff --git a/community-build/community-projects/PPrint b/community-build/community-projects/PPrint index 4a135e4ad5ef..ee55dc3d4e09 160000 --- a/community-build/community-projects/PPrint +++ b/community-build/community-projects/PPrint @@ -1 +1 @@ -Subproject commit 4a135e4ad5ef5c3e9e2178f2b073db6ee2c6df13 +Subproject commit ee55dc3d4e09f7de6db344e60ae8894d99a28493 diff --git a/community-build/community-projects/dotty-cps-async b/community-build/community-projects/dotty-cps-async index 85c118605802..35ee6fd9cc08 160000 --- a/community-build/community-projects/dotty-cps-async +++ b/community-build/community-projects/dotty-cps-async @@ -1 +1 @@ -Subproject commit 85c118605802eef925b1f56722eba29ecf5ae320 +Subproject commit 35ee6fd9cc08bcae435a21ca704e6897e2dc2cf8 diff --git a/community-build/community-projects/intent b/community-build/community-projects/intent index 7625af676106..e5f5eb0bb942 160000 --- a/community-build/community-projects/intent +++ b/community-build/community-projects/intent @@ -1 +1 @@ -Subproject commit 7625af676106c298e2a44d52c96b5ce947d5cc35 +Subproject commit e5f5eb0bb9424727e70b78cc10a6c6daed78d9a2 diff --git a/community-build/community-projects/minitest b/community-build/community-projects/minitest index da3f4a09bdb4..81b77be2db6f 160000 --- a/community-build/community-projects/minitest +++ b/community-build/community-projects/minitest @@ -1 +1 @@ -Subproject commit da3f4a09bdb4bdc56758473670b57c1b094cd5db +Subproject commit 81b77be2db6f290a638ee87f10ecef1948d9313a diff --git a/community-build/community-projects/munit b/community-build/community-projects/munit index 1e90e9707e02..2d4c5315b871 160000 --- a/community-build/community-projects/munit +++ b/community-build/community-projects/munit @@ -1 +1 @@ -Subproject commit 1e90e9707e02c41049489849dd0e002d48d4b498 +Subproject commit 2d4c5315b871c8d76eda1c96d09984577a806783 diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 2b874f7aaaab..45be76a0a5ec 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 2b874f7aaaab4c567b12aa231ae104545ebf9e05 +Subproject commit 45be76a0a5ecbdbd35aae2502a725618f1180703 diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index 265d237ba3f9..7c681808819e 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit 265d237ba3f97f7f05d309e26d5f0103f49e70c4 +Subproject commit 7c681808819e71f73209016fe88422b1025a208b diff --git a/community-build/community-projects/upickle b/community-build/community-projects/upickle index 6016ebbf4990..0b1f1fea4983 160000 --- a/community-build/community-projects/upickle +++ b/community-build/community-projects/upickle @@ -1 +1 @@ -Subproject commit 6016ebbf49908409cb536edc3b2ed1f214fb6657 +Subproject commit 0b1f1fea4983443a48b895f53837b9da30fce90d diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 992c80ae071b..e9f14a2ce0e1 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 992c80ae071b027f0bfe4371788cb68987531808 +Subproject commit e9f14a2ce0e1212b486dac1372f966466d1270ed diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index a53730def9dc..d1bc3bb4438d 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit a53730def9dce4d44166f317b7cdcefb851644b3 +Subproject commit d1bc3bb4438d613789c926b2e23eee6217665a74 diff --git a/library/src-bootstrapped/scala/quoted/QuoteContext.scala b/library/src-bootstrapped/scala/quoted/QuoteContext.scala index 05bdda565393..85ea6de1f114 100644 --- a/library/src-bootstrapped/scala/quoted/QuoteContext.scala +++ b/library/src-bootstrapped/scala/quoted/QuoteContext.scala @@ -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. * @@ -34,7 +31,7 @@ trait QuoteContext { self => * ``` */ type Nested = QuoteContext { - val reflect: self.tasty.type + val reflect: self.reflect.type } } diff --git a/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala b/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala index 520aec633b9c..af4c41edc9cd 100644 --- a/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala +++ b/library/src-non-bootstrapped/scala/quoted/QuoteContext.scala @@ -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 } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala index 3942d3a1bd4d..3fe67ccc13e8 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala @@ -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") } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala index 1af0eddfbd9e..b2783d55488c 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala @@ -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") } } diff --git a/scala3doc/dotty-docs/docs/docs/reference/contextual/derivation-macro.md b/scala3doc/dotty-docs/docs/docs/reference/contextual/derivation-macro.md index 9a49aef73c34..bd81c7fa226f 100644 --- a/scala3doc/dotty-docs/docs/docs/reference/contextual/derivation-macro.md +++ b/scala3doc/dotty-docs/docs/docs/reference/contextual/derivation-macro.md @@ -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 @@ -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 diff --git a/scala3doc/dotty-docs/docs/docs/reference/metaprogramming/tasty-reflect.md b/scala3doc/dotty-docs/docs/docs/reference/metaprogramming/tasty-reflect.md index d383c1974b97..05d0c2bf49d0 100644 --- a/scala3doc/dotty-docs/docs/docs/reference/metaprogramming/tasty-reflect.md +++ b/scala3doc/dotty-docs/docs/docs/reference/metaprogramming/tasty-reflect.md @@ -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 @@ -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))) => @@ -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. @@ -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 { @@ -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 @@ -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 @@ -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)) - diff --git a/scala3doc/src/dotty/dokka/tasty/TastyParser.scala b/scala3doc/src/dotty/dokka/tasty/TastyParser.scala index 0a7f2621fbf1..694d7fabd5dc 100644 --- a/scala3doc/src/dotty/dokka/tasty/TastyParser.scala +++ b/scala3doc/src/dotty/dokka/tasty/TastyParser.scala @@ -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 diff --git a/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala b/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala index f8cfe8a9f1c7..8911b6e4a0fc 100644 --- a/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala +++ b/tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala @@ -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 * @@ -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 diff --git a/tests/neg-macros/i6976/Macro_1.scala b/tests/neg-macros/i6976/Macro_1.scala index 25543bc03a10..1a95b572f456 100644 --- a/tests/neg-macros/i6976/Macro_1.scala +++ b/tests/neg-macros/i6976/Macro_1.scala @@ -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} } } } diff --git a/tests/pos-macros/i7011/Macros_1.scala b/tests/pos-macros/i7011/Macros_1.scala index 1808c0c1f34e..f269b0cfafe2 100644 --- a/tests/pos-macros/i7011/Macros_1.scala +++ b/tests/pos-macros/i7011/Macros_1.scala @@ -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 diff --git a/tests/pos-macros/i7030/Macros_1.scala b/tests/pos-macros/i7030/Macros_1.scala index a529538e08a7..9c52700ad274 100644 --- a/tests/pos-macros/i7030/Macros_1.scala +++ b/tests/pos-macros/i7030/Macros_1.scala @@ -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 } diff --git a/tests/pos-macros/i8651b.scala b/tests/pos-macros/i8651b.scala index 23739c604bd4..16e588160b0e 100644 --- a/tests/pos-macros/i8651b.scala +++ b/tests/pos-macros/i8651b.scala @@ -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] { diff --git a/tests/pos-macros/i9240/Macro_1.scala b/tests/pos-macros/i9240/Macro_1.scala index 8cc0bf470b93..b08ef7388613 100644 --- a/tests/pos-macros/i9240/Macro_1.scala +++ b/tests/pos-macros/i9240/Macro_1.scala @@ -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._ diff --git a/tests/pos-macros/treemap-unapply/Macro.scala b/tests/pos-macros/treemap-unapply/Macro.scala index 08bebb7e6250..2f39727842f3 100644 --- a/tests/pos-macros/treemap-unapply/Macro.scala +++ b/tests/pos-macros/treemap-unapply/Macro.scala @@ -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] diff --git a/tests/run-macros/i7008/macro_1.scala b/tests/run-macros/i7008/macro_1.scala index 93cbf0ef1a8b..a371f66fb25e 100644 --- a/tests/run-macros/i7008/macro_1.scala +++ b/tests/run-macros/i7008/macro_1.scala @@ -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)}) -} \ No newline at end of file +} diff --git a/tests/run-staging/i6992/Macro_1.scala b/tests/run-staging/i6992/Macro_1.scala index 62c1dbcea807..0ec6ef2cb805 100644 --- a/tests/run-staging/i6992/Macro_1.scala +++ b/tests/run-staging/i6992/Macro_1.scala @@ -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)