Fix type table serialization in DescriptorSerializer
Always serialize type table (and version requirement table) after everything else, to prevent bugs like KT-51446 where inline class underlying type was added to the type table after it has already been serialized. #KT-51446 Fixed
This commit is contained in:
+11
-27
@@ -78,18 +78,11 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
|
||||
val versionRequirementTableProto = versionRequirementTable?.serialize()
|
||||
if (versionRequirementTableProto != null) {
|
||||
builder.versionRequirementTable = versionRequirementTableProto
|
||||
}
|
||||
|
||||
extension.serializePackage(packageFqName, builder)
|
||||
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
versionRequirementTable?.serialize()?.let { builder.versionRequirementTable = it }
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
@@ -179,11 +172,6 @@ class FirElementSerializer private constructor(
|
||||
builder.companionObjectName = getSimpleNameIndex(companionObject.name)
|
||||
}
|
||||
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
|
||||
val representation = (klass as? FirRegularClass)?.getInlineClassUnderlyingParameter(session)
|
||||
if (representation != null) {
|
||||
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(representation.name)
|
||||
@@ -208,10 +196,9 @@ class FirElementSerializer private constructor(
|
||||
|
||||
writeVersionRequirementForInlineClasses(klass, builder, versionRequirementTable)
|
||||
|
||||
val versionRequirementTableProto = versionRequirementTable.serialize()
|
||||
if (versionRequirementTableProto != null) {
|
||||
builder.versionRequirementTable = versionRequirementTableProto
|
||||
}
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
versionRequirementTable.serialize()?.let { builder.versionRequirementTable = it }
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
@@ -411,11 +398,12 @@ class FirElementSerializer private constructor(
|
||||
builder.addValueParameter(local.valueParameterProto(valueParameter))
|
||||
}
|
||||
|
||||
contractSerializer.serializeContractOfFunctionIfAny(function, builder, this)
|
||||
|
||||
extension.serializeFunction(function, builder, versionRequirementTable, local)
|
||||
|
||||
if (serializeTypeTableToFunction) {
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
}
|
||||
|
||||
versionRequirementTable?.run {
|
||||
@@ -430,10 +418,6 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
contractSerializer.serializeContractOfFunctionIfAny(function, builder, this)
|
||||
|
||||
extension.serializeFunction(function, builder, versionRequirementTable, local)
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -7586,6 +7586,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
+10
-27
@@ -171,11 +171,6 @@ class DescriptorSerializer private constructor(
|
||||
builder.companionObjectName = getSimpleNameIndex(companionObjectDescriptor.name)
|
||||
}
|
||||
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
|
||||
val representation = classDescriptor.inlineClassRepresentation
|
||||
if (representation != null) {
|
||||
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(representation.underlyingPropertyName)
|
||||
@@ -214,10 +209,8 @@ class DescriptorSerializer private constructor(
|
||||
)
|
||||
}
|
||||
|
||||
val versionRequirementTableProto = versionRequirementTable.serialize()
|
||||
if (versionRequirementTableProto != null) {
|
||||
builder.versionRequirementTable = versionRequirementTableProto
|
||||
}
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
versionRequirementTable.serialize()?.let { builder.versionRequirementTable = it }
|
||||
|
||||
return builder
|
||||
}
|
||||
@@ -423,11 +416,12 @@ class DescriptorSerializer private constructor(
|
||||
builder.addValueParameter(local.valueParameter(valueParameterDescriptor))
|
||||
}
|
||||
|
||||
contractSerializer.serializeContractOfFunctionIfAny(descriptor, builder, this)
|
||||
|
||||
extension.serializeFunction(descriptor, builder, versionRequirementTable, local)
|
||||
|
||||
if (serializeTypeTableToFunction) {
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
}
|
||||
|
||||
versionRequirementTable?.run {
|
||||
@@ -450,10 +444,6 @@ class DescriptorSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
contractSerializer.serializeContractOfFunctionIfAny(descriptor, builder, this)
|
||||
|
||||
extension.serializeFunction(descriptor, builder, versionRequirementTable, local)
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
@@ -771,18 +761,11 @@ class DescriptorSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val typeTableProto = typeTable.serialize()
|
||||
if (typeTableProto != null) {
|
||||
builder.typeTable = typeTableProto
|
||||
}
|
||||
|
||||
val versionRequirementTableProto = versionRequirementTable?.serialize()
|
||||
if (versionRequirementTableProto != null) {
|
||||
builder.versionRequirementTable = versionRequirementTableProto
|
||||
}
|
||||
|
||||
extension.serializePackage(packageFqName, builder)
|
||||
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
versionRequirementTable?.serialize()?.let { builder.versionRequirementTable = it }
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -77,6 +77,7 @@ object LanguageSettingsDirectives : SimpleDirectivesContainer() {
|
||||
val DISABLE_CALL_ASSERTIONS by directive("Disable assertions on calls")
|
||||
val NO_UNIFIED_NULL_CHECKS by directive("No unified null checks")
|
||||
val PARAMETERS_METADATA by directive("Add parameters metadata for 1.8 reflection")
|
||||
val USE_TYPE_TABLE by directive("Use type table in metadata serialization")
|
||||
|
||||
// --------------------- Utils ---------------------
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +GenericInlineClassParameter
|
||||
// WITH_STDLIB
|
||||
// USE_TYPE_TABLE
|
||||
// MODULE: lib
|
||||
// FILE: A.kt
|
||||
|
||||
inline class A<T> private constructor(private val value: T) {
|
||||
val publicValue: String get() = value.toString()
|
||||
|
||||
companion object {
|
||||
fun create(c: Char): A<String> = A(c + "K")
|
||||
}
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: B.kt
|
||||
|
||||
fun box(): String = A.create('O').publicValue
|
||||
+6
@@ -7466,6 +7466,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
+6
@@ -7586,6 +7586,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
+6
@@ -596,6 +596,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
+6
@@ -590,6 +590,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
+2
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_OPTIMI
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_UNIFIED_NULL_CHECKS
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.PARAMETERS_METADATA
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.JDK_RELEASE
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.USE_TYPE_TABLE
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
||||
import org.jetbrains.kotlin.test.model.DependencyDescription
|
||||
@@ -147,6 +148,7 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
register(JVM_TARGET, JVMConfigurationKeys.JVM_TARGET)
|
||||
register(SERIALIZE_IR, JVMConfigurationKeys.SERIALIZE_IR)
|
||||
register(JDK_RELEASE, JVMConfigurationKeys.JDK_RELEASE)
|
||||
register(USE_TYPE_TABLE, JVMConfigurationKeys.USE_TYPE_TABLE)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPathApi::class, ExperimentalStdlibApi::class)
|
||||
|
||||
+6
@@ -5700,6 +5700,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateConstructorWithPrivateFieldUsingTypeTable.kt")
|
||||
public void testPrivateConstructorWithPrivateFieldUsingTypeTable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateFieldUsingTypeTable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateTopLevelValInDifferentModule.kt")
|
||||
public void testPrivateTopLevelValInDifferentModule() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user