JVM IR: add KotlinTypeMapperBase, do not use KotlinTypeMapper in metadata serialization
This commit is contained in:
+6
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.codegen.coroutines.isResumeImplMethodName
|
||||
import org.jetbrains.kotlin.codegen.inline.coroutines.CoroutineTransformer
|
||||
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmCodegenStringTable
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapperBase
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
@@ -46,6 +47,9 @@ class AnonymousObjectTransformer(
|
||||
private lateinit var sourceMapper: SourceMapper
|
||||
private val languageVersionSettings = inliningContext.state.languageVersionSettings
|
||||
|
||||
// TODO: use IrTypeMapper in the IR backend
|
||||
private val typeMapper: KotlinTypeMapperBase = state.typeMapper
|
||||
|
||||
override fun doTransform(parentRemapper: FieldRemapper): InlineResult {
|
||||
val innerClassNodes = ArrayList<InnerClassNode>()
|
||||
val classBuilder = createRemappingClassBuilderViaFactory(inliningContext)
|
||||
@@ -226,7 +230,7 @@ class AnonymousObjectTransformer(
|
||||
when (header.kind) {
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
val (nameResolver, classProto) = JvmProtoBufUtil.readClassDataFrom(data, strings)
|
||||
val newStringTable = JvmCodegenStringTable(state.typeMapper, nameResolver)
|
||||
val newStringTable = JvmCodegenStringTable(typeMapper, nameResolver)
|
||||
val newProto = classProto.toBuilder().apply {
|
||||
setExtension(JvmProtoBuf.anonymousObjectOriginName, newStringTable.getStringIndex(oldObjectType.internalName))
|
||||
}.build()
|
||||
@@ -234,7 +238,7 @@ class AnonymousObjectTransformer(
|
||||
}
|
||||
KotlinClassHeader.Kind.SYNTHETIC_CLASS -> {
|
||||
val (nameResolver, functionProto) = JvmProtoBufUtil.readFunctionDataFrom(data, strings)
|
||||
val newStringTable = JvmCodegenStringTable(state.typeMapper, nameResolver)
|
||||
val newStringTable = JvmCodegenStringTable(typeMapper, nameResolver)
|
||||
val newProto = functionProto.toBuilder().apply {
|
||||
setExtension(JvmProtoBuf.lambdaClassOriginName, newStringTable.getStringIndex(oldObjectType.internalName))
|
||||
}.build()
|
||||
|
||||
+4
-6
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.serialization
|
||||
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapperBase
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmNameResolver
|
||||
@@ -15,12 +15,11 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.DescriptorAwareStringTable
|
||||
|
||||
class JvmCodegenStringTable @JvmOverloads constructor(
|
||||
private val typeMapper: KotlinTypeMapper,
|
||||
private val typeMapper: KotlinTypeMapperBase,
|
||||
nameResolver: JvmNameResolver? = null
|
||||
) : JvmStringTable(nameResolver), DescriptorAwareStringTable {
|
||||
override fun getLocalClassIdReplacement(descriptor: ClassifierDescriptorWithTypeParameters): ClassId {
|
||||
val container = descriptor.containingDeclaration
|
||||
return when (container) {
|
||||
override fun getLocalClassIdReplacement(descriptor: ClassifierDescriptorWithTypeParameters): ClassId =
|
||||
when (val container = descriptor.containingDeclaration) {
|
||||
is ClassifierDescriptorWithTypeParameters -> getLocalClassIdReplacement(container).createNestedClassId(descriptor.name)
|
||||
is PackageFragmentDescriptor -> {
|
||||
throw IllegalStateException("getLocalClassIdReplacement should only be called for local classes: $descriptor")
|
||||
@@ -30,5 +29,4 @@ class JvmCodegenStringTable @JvmOverloads constructor(
|
||||
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
||||
import org.jetbrains.kotlin.codegen.createFreeFakeLocalPropertyDescriptor
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.*
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapperBase
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -39,10 +40,13 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
|
||||
class JvmSerializerExtension(private val bindings: JvmSerializationBindings, state: GenerationState) : SerializerExtension() {
|
||||
class JvmSerializerExtension @JvmOverloads constructor(
|
||||
private val bindings: JvmSerializationBindings,
|
||||
state: GenerationState,
|
||||
private val typeMapper: KotlinTypeMapperBase = state.typeMapper
|
||||
) : SerializerExtension() {
|
||||
private val globalBindings = state.globalSerializationBindings
|
||||
private val codegenBinding = state.bindingContext
|
||||
private val typeMapper = state.typeMapper
|
||||
override val stringTable = JvmCodegenStringTable(typeMapper)
|
||||
private val useTypeTable = state.useTypeTableInSerializer
|
||||
private val moduleName = state.moduleName
|
||||
|
||||
@@ -89,7 +89,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
||||
private val isIrBackend: Boolean = false,
|
||||
private val typePreprocessor: ((KotlinType) -> KotlinType?)? = null,
|
||||
private val namePreprocessor: ((ClassDescriptor) -> String?)? = null
|
||||
) {
|
||||
): KotlinTypeMapperBase() {
|
||||
private val isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||
|
||||
private val typeMappingConfiguration = object : TypeMappingConfiguration<Type> {
|
||||
@@ -224,7 +224,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
||||
return mapType(type, signatureVisitor, TypeMappingMode.GENERIC_ARGUMENT)
|
||||
}
|
||||
|
||||
fun mapClass(classifier: ClassifierDescriptor): Type {
|
||||
override fun mapClass(classifier: ClassifierDescriptor): Type {
|
||||
return mapType(classifier.defaultType, null, TypeMappingMode.CLASS_DECLARATION)
|
||||
}
|
||||
|
||||
@@ -274,10 +274,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
||||
return mapInlineClassType(kotlinType, TypeMappingMode.DEFAULT, typeMappingConfiguration)
|
||||
}
|
||||
|
||||
fun mapDefaultImpls(descriptor: ClassDescriptor): Type {
|
||||
return Type.getObjectType(mapType(descriptor).internalName + JvmAbi.DEFAULT_IMPLS_SUFFIX)
|
||||
}
|
||||
|
||||
private fun writeGenericType(
|
||||
type: KotlinType,
|
||||
asmType: Type,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen.state
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
abstract class KotlinTypeMapperBase {
|
||||
abstract fun mapClass(classifier: ClassifierDescriptor): Type
|
||||
|
||||
fun mapDefaultImpls(descriptor: ClassDescriptor): Type =
|
||||
Type.getObjectType(mapClass(descriptor).internalName + JvmAbi.DEFAULT_IMPLS_SUFFIX)
|
||||
}
|
||||
Reference in New Issue
Block a user