On the topic of macro annotations and AST generation, it’s been often mentioned that this is undesirable and that a better approach would be code generation. In scala 2 we do have ast manipulation¹ but in scala 3 we don’t, we also don’t have tools for code generation, we are left with no migration path.
Tasty introspection is nice, but it depends on the code being compiled already. Both Java and Kotlin support annotation processors which allows you to generate more source code during compilation, and that code gets in turn compiled in the same compilation unit, allowing cyclic dependencies between the two. With this one can, more or less, replace annotation macros that alter the ast.
Can this be realistically supported by a compiler plugin, or does this really require direct compiler support?
- Meaning the ability to introduce new symbols that are visible in the compilation. Macro annotations in scala 3 do allow us to change the ast but not the API visible before the macro runs.