Compiler Plugins vs Macros

I’m not an expert in compiler plugins or macro programming, but from a high-level perspective both looks similar. What are the differences? Why did Kotlin choose compiler plugins over macros? What is the impact on understandability and tool support?

The key difference is that macros works effectively rewrites the code before the code goes to compiler. Compiler plugin changes how existing code is processed by compiler. The compiler plugin is much more powerful, since it allows to add features not present in the language. Also there could be different level of compiler plugins. Some could affect only AST transformations and effectively work as a better controllable macros, some could affect compilation for specific platform.

1 Like