Rewrite IR plugin infrastructure (and serialization plugin) so it won't emit LazyIR.

LazyIR was emitted because plugin was not able to declare symbols, only to reference them.
Moreover, declarations added by frontend plugin were also unbound symbols produced by psi2ir,
and declaration stub generator was stubbing them with LazyIR – therefore access to global symbol table is not enough for plugins. IrProvider won't help here, because some functions produced by plugin have circular dependencies.

By moving compiler plugins step between psi2ir and declaration stub generator, both problems are resolved
– unbound symbols produced by psi2ir and compiler plugins are declared where they would be declared if this was a user code,
and only unbound symbols left are external dependencies, which is a correct input for lazy ir.
This commit is contained in:
Leonid Startsev
2019-11-15 18:33:46 +03:00
parent e4d0d450ab
commit 3e18350a1f
13 changed files with 187 additions and 145 deletions
@@ -5,14 +5,13 @@
package org.jetbrains.kotlinx.serialization.compiler.extensions
import org.jetbrains.kotlin.backend.common.BackendContext
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.js.translate.context.TranslationContext
import org.jetbrains.kotlin.js.translate.declaration.DeclarationBodyVisitor
import org.jetbrains.kotlin.psi.KtPureClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlinx.serialization.idea.runIfEnabledOn
class SerializationIDECodegenExtension : SerializationCodegenExtension() {
@@ -32,7 +31,7 @@ class SerializationIDEJsExtension : SerializationJsExtension() {
}
class SerializationIDEIrExtension : SerializationLoweringExtension() {
override fun generate(file: IrFile, backendContext: BackendContext, bindingContext: BindingContext) {
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
/* No-op don't enable IR extensions in IDE */
}
}