JVM IR: generate Kotlin metadata

Introduce MetadataSource as a way to store the original descriptor for
any element (before any lowerings) and maintain it until the end of the
codegen where it's used in generating the metadata. Note that JVM
signatures written to the metadata are formed from the _resulting_
generated elements, not by mapping the original descriptors.

Some corner cases are not supported yet, namely properties declared in
companion objects, synthetic methods for property annotations,
JvmPackageName, etc.

 #KT-29119 Fixed
This commit is contained in:
Alexander Udalov
2019-02-07 19:34:46 +01:00
parent 3d1858a8c5
commit c357967c2c
108 changed files with 157 additions and 121 deletions
@@ -16,13 +16,15 @@
package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.backend.common.CodegenUtil
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.ir.util.IrDeserializer
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile
@@ -73,7 +75,9 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
private fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
val fileEntry = context.sourceManager.getOrCreateFileEntry(ktFile)
val packageFragmentDescriptor = context.moduleDescriptor.findPackageFragmentForFile(ktFile)!!
val irFile = IrFileImpl(fileEntry, packageFragmentDescriptor)
val irFile = IrFileImpl(fileEntry, packageFragmentDescriptor).apply {
metadata = MetadataSource.File(CodegenUtil.getMemberDescriptorsToGenerate(ktFile, context.bindingContext))
}
context.sourceManager.putFileEntry(irFile, fileEntry)
return irFile
}