Skip to content

Commit b67068a

Browse files
authored
Merge pull request #8 from dotty-staging/add-macro-migration-outline
Add outline for macro migration
2 parents 6d48263 + 881542d commit b67068a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/macros.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,55 @@ Scala 3 will break this limitation but it comes with the cost of rewriting all t
99
While being experimental, the Scala community has largely adopted the Scala 2 [Def Macro](https://docs.scala-lang.org/overviews/macros/overview.html) feature in multiple of ways: code generation, optimizations, ergonomic DSLs...
1010

1111
Here is an incomplete list of libraries that use Scala 2 macros and their migration status:
12+
1213
[Contributors welcome!](CONTRIBUTING.md)
1314

1415
## How to?
1516

17+
### Before rewriting a macro
18+
19+
Before getting deep into reimplementing a macro your should check if it can be supported using Scala 3 new features.
20+
21+
* Can I encode the logic of the macro using the new scala 3 features?
22+
* [List of Scala 3 features](http://dotty.epfl.ch/docs/reference/overview.html)
23+
* Can I use *match types* to reimplement the interface of my macro?
24+
* [Match Types](http://dotty.epfl.ch/docs/reference/new-types/match-types.html)
25+
* Can I use `inline` and the metaprogramming features in `scala.compiletime` to reimplement my logic?
26+
* [Inline](http://dotty.epfl.ch/docs/reference/metaprogramming/inline.html)
27+
* [`scala.compiletime`](http://dotty.epfl.ch/api/scala/compiletime/index.html)
28+
* Can I use the simpler and safer expression based macros to implement my macro?
29+
* [Simple macros](http://dotty.epfl.ch/docs/reference/metaprogramming/macros.html)
30+
* I really need to have access to the raw AST trees
31+
* [TASTy Reflect](http://dotty.epfl.ch/docs/reference/metaprogramming/tasty-reflect.html)
32+
* [TASTy inspector](http://dotty.epfl.ch/docs/reference/metaprogramming/tasty-inspect.html)
33+
34+
A good reference for this is [Shapeless 3](https://github.com/dotty-staging/shapeless/tree/shapeless-3). It uses Scala 3 features most of the time for a feature that would have been macros in Scala 2 and only uses macros where absolutely necessary.
35+
36+
### Defining a project that cross compiles macros
37+
38+
If you are already cross-compiling your macro for different versions of Scala 2 and you have sources folders for each version, then you can add an extra source folder for Scala 3.
39+
40+
* SBT examples:
41+
* *TODO find a simple example project*
42+
* Mill examples
43+
* *TODO find a simple example project*
44+
* [utest](https://github.com/dotty-staging/utest/tree/dotty)
45+
* [sourcecode](https://github.com/dotty-staging/sourcecode/tree/dotty-community-build)
46+
1647
[Contributors welcome!](CONTRIBUTING.md)
1748

1849
## Additional Resources
1950

51+
Documentation:
2052
- [Dotty Documentation](https://dotty.epfl.ch/docs/reference/metaprogramming/toc.html)
21-
- [Macros: The Plan For Scala 3](https://www.scala-lang.org/blog/2018/04/30/in-a-nutshell.html)
53+
- [Macros: The Plan For Scala 3](https://www.scala-lang.org/blog/2018/04/30/in-a-nutshell.html)
54+
55+
56+
Talks:
57+
* [Scala Days - Metaprogramming in Dotty](https://www.youtube.com/watch?v=ZfDS_gJyPTc)
58+
59+
Projects:
60+
* [XML Interpolator](https://github.com/dotty-staging/xml-interpolator/tree/master)
61+
* [Shapeless 3](https://github.com/dotty-staging/shapeless/tree/shapeless-3)
62+
63+
[Contributors welcome!](CONTRIBUTING.md)

0 commit comments

Comments
 (0)