The Scala 2 macros are compiler-dependent by design. A macro compiled by one version of the compiler cannot be used by another version of the compiler.
Scala 3 is overcoming this limitation by introducing a new principled approach of metaprogramming. While this is an uncontested improvement, it also means that previous macro implementations have to be rewritten from the ground up.
State of the Macro Ecosystem
Some of the most used macro libraries have already been migrated to Scala 3. Check the list of Scala macro libraries.
Before Rewriting a Macro
Before getting deep into reimplementing a macro you should check if it can be supported using Scala 3 new features.
- Can I encode the logic of the macro using the new scala 3 features?
- Can I use match types to reimplement the interface of my macro?
- Can I use
inlineand the metaprogramming features in
scala.compiletimeto reimplement my logic?
- Can I use the simpler and safer expression based macros to implement my macro?
- Do I really need to have access to the raw AST trees?
Macro Reference and Tutorial
You can find the references to these new concepts in the Scala 3 Reference website.
Or you can opt for a more pratical approach by following the Macro Tutorial. It shows and explains how to use these features:
Cross-building a Macro Library
You have written a wonderful macro library and you would like it to be available for Scala 2.13 and Scala 3. There are two different approaches, the traditional cross-building technique and the more recent mixing macros technique.
Both approaches are described in the tutorials section:
Blog posts and talks: