Is there any example of a working K2 plugin that b...
# compiler
q
Is there any example of a working K2 plugin that builds outside of the Kotlin repo? I see all the ones inside the Kotlin repo use the "jps-compatible" plugin, but I am not sure what that is or how that works.
z
https://github.com/zacsweers/redacted-compiler-plugin “works”, though the K2 compiler plugin API leaves a lot to be desired currently
d
jbs-compatible gradle plugin is internal one which is needed to compile kotlin project using IDEA instead of gradle. It is completely optional so just don't pay attention to it
q
@dmitriy.novozhilov Is it possible to add a custom FirTransformer with the API? The possibilities with the current APIs like FirExpressionResolutionExtension are very limited. I just want a chance to transform any arbitrary FirExpression (maybe by adding an additional FirBodyResolveTransformer), but it looks like FirTotalResolveProcessor just hardcodes all the transformers?
d
It's not possible by design
q
@dmitriy.novozhilov My goal is to wrap some expressions in FirSmartCastExpression, to help the compiler see some valid casts that it can't infer. Will there be a mechanism to do this with a plugin?
d
No, there isn't BTW what the type of smartcasts you want to provide? Can it be described with
returns implies
contract? Or maybe it's generic enough to add it to compiler itself?
q
I want to add smart casts to all function calls that return a specific type so that the user does not need to specify contracts manually. Additionally, I would like to add smart casts to receivers where no function call is involved. This is for emulating higher kinded types by automatically casting a special emulated type to its concrete representation (e.g. Kind<OptionWitness, T> to Option<T>).
I certainly hope that the FIR API will gain more functionality prior to its release. I must say what it can do now is pretty disappointing.