提交 ea01c97a 编写于 作者: A Alexander Udalov

Write underlying property name & type for inline class to metadata

This will be used in the compiler starting from 1.5.20 instead of the
currently used approach of looking for the single value parameter of the
primary constructor. The problem with the current approach is that
primary constructor can be private (since 1.4.30) and the property could
always be private. Relying on private declarations from metadata is
dangerous; for example lazy IR doesn't usually create stubs for private
declarations, and it didn't create stubs for private inline class
constructors before b5f9b1df, which led to the problem reported in
KT-44723.
上级 5baa2e0e
......@@ -182,6 +182,21 @@ open class ProtoCompareGenerated(
if (!checkEqualsClassSealedSubclassFqName(old, new)) return false
if (old.hasInlineClassUnderlyingPropertyName() != new.hasInlineClassUnderlyingPropertyName()) return false
if (old.hasInlineClassUnderlyingPropertyName()) {
if (!checkStringEquals(old.inlineClassUnderlyingPropertyName, new.inlineClassUnderlyingPropertyName)) return false
}
if (old.hasInlineClassUnderlyingType() != new.hasInlineClassUnderlyingType()) return false
if (old.hasInlineClassUnderlyingType()) {
if (!checkEquals(old.inlineClassUnderlyingType, new.inlineClassUnderlyingType)) return false
}
if (old.hasInlineClassUnderlyingTypeId() != new.hasInlineClassUnderlyingTypeId()) return false
if (old.hasInlineClassUnderlyingTypeId()) {
if (!checkEquals(oldTypeTable.getType(old.inlineClassUnderlyingTypeId), newTypeTable.getType(new.inlineClassUnderlyingTypeId))) return false
}
if (!checkEqualsClassVersionRequirement(old, new)) return false
if (old.hasVersionRequirementTable() != new.hasVersionRequirementTable()) return false
......@@ -266,6 +281,9 @@ open class ProtoCompareGenerated(
TYPE_ALIAS_LIST,
ENUM_ENTRY_LIST,
SEALED_SUBCLASS_FQ_NAME_LIST,
INLINE_CLASS_UNDERLYING_PROPERTY_NAME,
INLINE_CLASS_UNDERLYING_TYPE,
INLINE_CLASS_UNDERLYING_TYPE_ID,
VERSION_REQUIREMENT_LIST,
VERSION_REQUIREMENT_TABLE,
JVM_EXT_CLASS_MODULE_NAME,
......@@ -314,6 +332,21 @@ open class ProtoCompareGenerated(
if (!checkEqualsClassSealedSubclassFqName(old, new)) result.add(ProtoBufClassKind.SEALED_SUBCLASS_FQ_NAME_LIST)
if (old.hasInlineClassUnderlyingPropertyName() != new.hasInlineClassUnderlyingPropertyName()) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_PROPERTY_NAME)
if (old.hasInlineClassUnderlyingPropertyName()) {
if (!checkStringEquals(old.inlineClassUnderlyingPropertyName, new.inlineClassUnderlyingPropertyName)) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_PROPERTY_NAME)
}
if (old.hasInlineClassUnderlyingType() != new.hasInlineClassUnderlyingType()) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE)
if (old.hasInlineClassUnderlyingType()) {
if (!checkEquals(old.inlineClassUnderlyingType, new.inlineClassUnderlyingType)) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE)
}
if (old.hasInlineClassUnderlyingTypeId() != new.hasInlineClassUnderlyingTypeId()) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID)
if (old.hasInlineClassUnderlyingTypeId()) {
if (!checkEquals(oldTypeTable.getType(old.inlineClassUnderlyingTypeId), newTypeTable.getType(new.inlineClassUnderlyingTypeId))) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID)
}
if (!checkEqualsClassVersionRequirement(old, new)) result.add(ProtoBufClassKind.VERSION_REQUIREMENT_LIST)
if (old.hasVersionRequirementTable() != new.hasVersionRequirementTable()) result.add(ProtoBufClassKind.VERSION_REQUIREMENT_TABLE)
......@@ -1728,6 +1761,18 @@ fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
hashCode = 31 * hashCode + fqNameIndexes(getSealedSubclassFqName(i))
}
if (hasInlineClassUnderlyingPropertyName()) {
hashCode = 31 * hashCode + stringIndexes(inlineClassUnderlyingPropertyName)
}
if (hasInlineClassUnderlyingType()) {
hashCode = 31 * hashCode + inlineClassUnderlyingType.hashCode(stringIndexes, fqNameIndexes, typeById)
}
if (hasInlineClassUnderlyingTypeId()) {
hashCode = 31 * hashCode + typeById(inlineClassUnderlyingTypeId).hashCode(stringIndexes, fqNameIndexes, typeById)
}
for(i in 0..versionRequirementCount - 1) {
hashCode = 31 * hashCode + getVersionRequirement(i)
}
......
......@@ -290,6 +290,11 @@ class DifferenceCalculatorForClass(
isClassAffected = true
areSubclassesAffected = true
}
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_PROPERTY_NAME,
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE,
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID -> {
isClassAffected = true
}
}
}
......
......@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.IntValue
import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.nonSourceAnnotations
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
import org.jetbrains.kotlin.serialization.deserialization.descriptorVisibility
......@@ -150,6 +149,21 @@ class DescriptorSerializer private constructor(
builder.typeTable = typeTableProto
}
classDescriptor.underlyingRepresentation()?.let { parameter ->
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(parameter.name)
val property = callableMembers.single {
it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == parameter.name
}
if (!property.visibility.isPublicAPI) {
if (useTypeTable()) {
builder.inlineClassUnderlyingTypeId = typeId(parameter.type)
} else {
builder.setInlineClassUnderlyingType(type(parameter.type))
}
}
}
if (versionRequirementTable == null) error("Version requirements must be serialized for classes: $classDescriptor")
builder.addAllVersionRequirement(versionRequirementTable.serializeVersionRequirements(classDescriptor))
......
......@@ -26,7 +26,7 @@ class JvmMetadataVersion(versionArray: IntArray, val isStrictSemantics: Boolean)
companion object {
@JvmField
val INSTANCE = JvmMetadataVersion(1, 5, 0)
val INSTANCE = JvmMetadataVersion(1, 5, 1)
@JvmField
val INVALID_VERSION = JvmMetadataVersion()
......
......@@ -233,6 +233,11 @@ message Class {
repeated int32 sealed_subclass_fq_name = 16 [packed = true, (fq_name_id_in_table) = true];
optional int32 inline_class_underlying_property_name = 17 [(name_id_in_table) = true];
optional Type inline_class_underlying_type = 18;
optional int32 inline_class_underlying_type_id = 19 [(type_id_in_table) = true];
optional TypeTable type_table = 30;
// Index into the VersionRequirementTable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册