From 1f5a8fddc9309d4304f841f6533f21a8bc7cfe24 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 13 Jan 2021 11:01:13 +0100 Subject: [PATCH] Update Scala 3 macro reflection --- _overviews/scala3-macros/tutorial/index.md | 8 ++++---- _overviews/scala3-macros/tutorial/reflection.md | 14 +++++++------- scripts/ci.sh | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/_overviews/scala3-macros/tutorial/index.md b/_overviews/scala3-macros/tutorial/index.md index d9b0858392..dd278b5607 100644 --- a/_overviews/scala3-macros/tutorial/index.md +++ b/_overviews/scala3-macros/tutorial/index.md @@ -20,19 +20,19 @@ abstractions and offers more fine-grained control. - [Compile-time operations][compiletime] offer additional metaprogramming utilities that can be used within `inline` methods (for example to improve error reporting), without having to define a macro. -- Starting from `inline`-methods, [macros][macros] are programs that explicitly operate on programs. +- Starting from `inline` methods, [macros][macros] are programs that explicitly operate on programs. - Macros can be defined in terms of a _high-level_ API of [quoted expressions][quotes], that admits simple construction and deconstruction of programs expressions. - - Macros can also be defined in terms of a more _low-level_ API of [TASTy Reflection][tasty], that allows detailed inspection of programs. + - Macros can also be defined in terms of a more _low-level_ API of [Reflection][reflection], that allows detailed inspection of programs. > The tutorial uses the API of Scala 3.0.0-M3. The API had many small changes in this revision. -> 🚧 We are still in the process of writing the tutorial. You can [help us improve it][contributing] 🚧 +> 🚧 We are still in the process of writing the tutorial. You can [help us][contributing] 🚧 [contributing]: {% link scala3/contribute-to-docs.md %} [compiletime]: {% link _overviews/scala3-macros/tutorial/compiletime.md %} [inline]: {% link _overviews/scala3-macros/tutorial/inline.md %} [macros]: {% link _overviews/scala3-macros/tutorial/macros.md %} [quotes]: {% link _overviews/scala3-macros/tutorial/quotes.md %} -[tasty]: {% link _overviews/scala3-macros/tutorial/reflection.md %} +[reflection]: {% link _overviews/scala3-macros/tutorial/reflection.md %} diff --git a/_overviews/scala3-macros/tutorial/reflection.md b/_overviews/scala3-macros/tutorial/reflection.md index aeef82f189..74b7651138 100644 --- a/_overviews/scala3-macros/tutorial/reflection.md +++ b/_overviews/scala3-macros/tutorial/reflection.md @@ -1,13 +1,13 @@ --- type: section -title: Tasty Reflection +title: Reflection num: 6 previous-page: quotes --- The reflection API provides a more complex and comprehensive view on the structure of the code. -It provides a view on the *Typed Abstract Syntax Trees* **TASTy** and their properties such as types, symbols, positions and comments. +It provides a view on the *Typed Abstract Syntax Trees* and their properties such as types, symbols, positions and comments. ## How to use the API @@ -16,19 +16,19 @@ We can use `scala.quoted.quotes` to import it. ```scala def pow(x: Expr[Int])(using Quotes): Expr[Int] = { - import quotes.tasty._ // Import Tree, Type, Symbol, Position, ..... + import quotes.reflect._ // Import Tree, Type, Symbol, Position, ..... ... } ``` This will import all the types and modules (with extension methods) of the API. -The full imported API can be found here: [Reflection](https://dotty.epfl.ch/api/scala/tasty/Reflection.html) +The full imported API can be found here: [Reflection](https://dotty.epfl.ch/api/scala/quoted/Quotes$reflectModule.html?query=trait%20reflectModule) For example to find what is a `Term`, we can see in the hierarchy that it is a subtype of `Statement` which is a subtype of `Tree`. -If we look into the [`TermMethods`](https://dotty.epfl.ch/api/scala/tasty/Reflection/TermMethods.html) we will find all the extension methods that are defined for `Term` such as `Term.tpe` which returns a `Type`. -As it is a subtype of `Tree` we can also look into the [`TreeMethods`](http://dotty.epfl.ch/api/scala/tasty/Reflection/TreeMethods.html) to find more methods such as `Tree.pos`. -Each type also a module with some _static-ish_ methods, for example in the [TypeModule](http://dotty.epfl.ch/api/scala/tasty/Reflection/TypeModule.html) we can find the method `Type.of[T]` with will create an instance of `Type` containing `T`. +If we look into the [`TermMethods`](https://dotty.epfl.ch/api/scala/quoted/Quotes$reflectModule$TermMethods.html) we will find all the extension methods that are defined for `Term` such as `Term.tpe` which returns a `Type`. +As it is a subtype of `Tree` we can also look into the [`TreeMethods`](https://dotty.epfl.ch/api/scala/quoted/Quotes$reflectModule$TreeMethods.html) to find more methods such as `Tree.pos`. +Each type also a module with some _static-ish_ methods, for example in the [`TypeReprModule`](https://dotty.epfl.ch/api/scala/quoted/Quotes$reflectModule$TypeReprModule.html) we can find the method `TypeRepr.of[T]` with will create an instance of `Type` containing `T`. ## Relation with expressions diff --git a/scripts/ci.sh b/scripts/ci.sh index 63ba8dfaeb..5a04734f27 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -16,6 +16,6 @@ bundle exec htmlproofer ./_site/\ --http-status-ignore "400,401,429"\ --empty-alt-ignore\ --allow-hash-href\ - --url-ignore '/https://github.com/scala/docs.scala-lang/blob/master/.*/,/www.oracle.com/,/.*dotty.epfl.ch\/api\/scala\/tasty\/Reflection.*/' + --url-ignore '/https://github.com/scala/docs.scala-lang/blob/master/.*/,/www.oracle.com/' exit 0