Hi! I have a compiler plugin with a FIR part and b...
# compiler
t
Hi! I have a compiler plugin with a FIR part and backend IR part. The backend IR part works quite well, but the FIR part is stopped working somewhere on the road. Actually, it is not called any more. (Please note that the backend IR part works, so I the compiler recognises the plugin.) I register the plugin like this:
Copy code
class Z2CompilerPluginRegistrar : CompilerPluginRegistrar() {

    override val supportsK2 = true

    override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
        val options = Z2Options(
            resourceOutputDir = configuration.get(Z2Options.CONFIG_KEY_RESOURCE_DIR)!!
        )
        FirExtensionRegistrarAdapter.registerExtension(Z2PluginRegistrar())
        IrGenerationExtension.registerExtension(Z2GenerationExtension(options))
    }

}
The Z2PluginRegistrar is also very simple:
Copy code
class Z2PluginRegistrar : FirExtensionRegistrar() {
    init {
        debug("Z2PluginRegistrar")
    }

    override fun ExtensionRegistrarContext.configurePlugin() {
        debug("configurePlugin")
        +::SchematicDeclarationGenerator
    }
}
The debug interestingly contains the
init
part but it does not contain the
configurePlugin
part. What do I do wrong? The FIR part worked well before, I might made a mistake during some refactoring but I can't figure out where the problem is. The source code is public (this library is not officially published yet, so it's not even close to clean): https://github.com/spxbhuhb/z2/tree/main/z2-kotlin-plugin Any help would be appreciated, thanks in advance.
j
Is it failing in both, IDE and tests?
I found the opposite, IR was not working after upgrading to 1.9.20+
I created a PR with the changes here here
thank you color 1
t
I don't test IDE integration and nothing fails. It simply does not run. I'm still on 1.9.10, deadlines and such. 🙂
h
Did you find a solution? I use the same api but the
configurePlugin
is never called. Or do we need to call it somehow by ourself?
j
I can share what is working for me: • Kotlin version: 2.0.0-dev-7674 • resources/META-INF/services (check image) • extend:
CompilerPluginRegistrar
to add it to the services • inside
fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration)
, call
FirExtensionRegistrarAdapter.registerExtension(SomeFirExtension())
SomeFirExtension
extends
FirExtensionRegistrar
, and
fun ExtensionRegistrarContext.configurePlugin()
adds extensions, mainly I am using
FirDeclarationGenerationExtension
. The previous setup is working in both, tests with the official test framework, and in IDEA, building it from IntelliJ Community sources.
thank you color 1
h
which official test framework do you mean? I use
dev.zacsweers.kctfork
but this framework does not support 2.0.0-Beta1
j
you can see the usage of the official test framework in the OP repository. Mainly check
test
,
testData
and
test-gen
. About kctfork, I have no idea, I haven’t used it before.
A summary could be: • Inside
test
you register the extensions and config everything • Inside
testData
you put the Kotlin files to compile • Inside
test-gen
the tests are generated based on the content of
testData
. To generate the tests you need to run a Gradle task
h
Okay, thank you, I will try it out.
t
Thanks for the info Javier. The deadline that made me disappear had passed, I'll try out your setup to see if it works for me.
👍 1
I solved this one. I had to set the language version to 2 in gradle. In hindsight it is logical. :)
👍 1