Meta-programming with K2 compiler plugins
summary
Builds several K2 compiler plugins: a declaration checker that enforces lowercase class names (reports warnings), an assignment transformer that rewrites assignments into MutableStateFlow .value writes (works at compile time), an AutoFactory generator that creates nested factory classes (needs FIR+IR and mostly works), and an autoclosure emulation that wraps string args into lambdas for conditional logging. Shows IntelliJ setup (enable in-process compiler, toggle K2 registry flags), uses kotlinc-compile-testing for tests, and warns about unstable APIs, poor docs and partial K2/IDE support.
AI-written summary · about
chapters (11)
- 0:00Meta-programming with K2
- 4:59Kotlin compiler plugin challenges
- 7:33K2 plugin development setup
- 12:53Class name validation with FIR
- 14:41Assignments to StateFlow
- 17:56AutoFactory plugin with FIR and IR
- 24:29Autoclosure for Kotlin
- 29:10Debugging K2 plugins
- 34:30Lessons from K2 plugins
- 38:01Should you build a plugin?
- 40:29Future of K2 plugins
related talks
36mMeta-programming with Kotlin compiler plugins
46mK2 Compiler plugins
33mMeta-programming with KSP and Kotlin compiler plugins
35mK2 compiler in production
44mMeta-programming with KSP and Kotlin compiler plugins
38mKSP and Plugins. Optimizing Kotlin Multiplatform common code
19mDemystifying the Kotlin Compiler
36mWriting a Kotlin Compiler Plugin
