Good day, friends! I have one more question. Is th...
# compiler
p
Good day, friends! I have one more question. Is there any Kotlin compiler extension to intercept with new IR transformation. I need to use it in my compiler plugin ComponentRegistrar.
r
You can find examples of a package view provider and also subscription to IR generation among other things in the branch we are prototyping for the arrow meta compiler plugin https://github.com/47deg/arrow-meta-prototype/tree/rr-tree-quotes-poc/compiler-plugin/src/main
Feel free to ask any questions in #arrow-meta too
p
Thank you, @raulraja! It helps me to enable IrGeneration extension. But I've faced one more problem : I add field to IrClass on generate phase, but it is not appeared in resulting .class file. Could you suggest what I made wrong? My code of IrGeneratationExstension: IrGenerationExtension.registerExtension(project, object : IrGenerationExtension { override fun generate(file: IrFile, backendContext: BackendContext, bindingContext: BindingContext) { file.transformChildren(object : IrElementTransformer<Unit> { override fun visitClass(declaration: IrClass, data: Unit): IrStatement { declaration.addField("test", backendContext.ir.irModule.irBuiltins.anyType) return super.visitClass(declaration, data) } }, Unit) }
r
You need to generate an Ir field, codegen is the last phase and from this point descriptors are not really considered
You can create code that turns into Ir with the ktPsiFactory and the psi2ir classes or write the Ir classes for your fields directly
Sorry didn't realize you were actually using the IrClass and not a DeclarationDescriptor, try adding your field after you call super. Not sure why that is not working
Also look in the compiler sources for new instances of IrField to copy how the compiler does it
p
Thanks, Raul! I'll try your suggestions.
r
👍