In AVSystem commons library we’re using macros for:
- materialization of
GenCodecinstances - classic typeclass derivation for ADTs
- standalone sealed hierarchy inspection -
SealedUtils, also used for enums, e.g.
compile time reflection of interfaces and proxy materialization in
RPCFramework- this is the base for RPC and REST subsystems of Udash Framework
The last use case is the one that doesn’t seem to have gotten enough love so far in all the macro discussions and it would be a serious blow for us if it wasn’t supported in Scala 3.
Also, our macro engines rely heavily on annotation processing, i.e. accessing annotations of inspected types, classes, methods, parameters, etc which influence how code is generated.
When using macros, we also try to follow these principles where possible:
- use only blackbox macros
- avoid implicit macros, especially the ones that generate a lot of code
- avoid arbitrarily deep type inspection (e.g. only inspect the shallow structure of case class, don’t go into fields) - this means e.g. lack of fully recursive typeclass derivation
- in order to avoid problems with incremental compilation, macros that inspect types should only be invoked in the same compilation unit where inspected types are defined (e.g. in companion object of inspected class)