https://kotlinlang.org logo
#compiler
Title
# compiler
t

Tóth István Zoltán

11/06/2023, 12:30 PM
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

Javier

11/06/2023, 12:55 PM
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

Tóth István Zoltán

11/06/2023, 1:00 PM
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

hfhbd

11/20/2023, 2:50 PM
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

Javier

11/20/2023, 3:11 PM
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.
h

hfhbd

11/20/2023, 3:32 PM
which official test framework do you mean? I use
dev.zacsweers.kctfork
but this framework does not support 2.0.0-Beta1
j

Javier

11/20/2023, 3:35 PM
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

hfhbd

11/20/2023, 3:44 PM
Okay, thank you, I will try it out.
7 Views