[Metadata] Add context receivers to metadata.proto
[Tests] Add JvmVersionRequirementTest
This commit is contained in:
committed by
TeamCityServer
parent
b3591e77be
commit
d47cf315e7
@@ -170,6 +170,10 @@ open class ProtoCompareGenerated(
|
||||
|
||||
if (!checkEqualsClassNestedClassName(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassContextReceiverType(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassContextReceiverTypeId(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassConstructor(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassFunction(old, new)) return false
|
||||
@@ -275,6 +279,8 @@ open class ProtoCompareGenerated(
|
||||
SUPERTYPE_LIST,
|
||||
SUPERTYPE_ID_LIST,
|
||||
NESTED_CLASS_NAME_LIST,
|
||||
CONTEXT_RECEIVER_TYPE_LIST,
|
||||
CONTEXT_RECEIVER_TYPE_ID_LIST,
|
||||
CONSTRUCTOR_LIST,
|
||||
FUNCTION_LIST,
|
||||
PROPERTY_LIST,
|
||||
@@ -320,6 +326,10 @@ open class ProtoCompareGenerated(
|
||||
|
||||
if (!checkEqualsClassNestedClassName(old, new)) result.add(ProtoBufClassKind.NESTED_CLASS_NAME_LIST)
|
||||
|
||||
if (!checkEqualsClassContextReceiverType(old, new)) result.add(ProtoBufClassKind.CONTEXT_RECEIVER_TYPE_LIST)
|
||||
|
||||
if (!checkEqualsClassContextReceiverTypeId(old, new)) result.add(ProtoBufClassKind.CONTEXT_RECEIVER_TYPE_ID_LIST)
|
||||
|
||||
if (!checkEqualsClassConstructor(old, new)) result.add(ProtoBufClassKind.CONSTRUCTOR_LIST)
|
||||
|
||||
if (!checkEqualsClassFunction(old, new)) result.add(ProtoBufClassKind.FUNCTION_LIST)
|
||||
@@ -453,6 +463,10 @@ open class ProtoCompareGenerated(
|
||||
if (!checkEquals(oldTypeTable.getType(old.receiverTypeId), newTypeTable.getType(new.receiverTypeId))) return false
|
||||
}
|
||||
|
||||
if (!checkEqualsFunctionContextReceiverType(old, new)) return false
|
||||
|
||||
if (!checkEqualsFunctionContextReceiverTypeId(old, new)) return false
|
||||
|
||||
if (!checkEqualsFunctionValueParameter(old, new)) return false
|
||||
|
||||
if (!checkEqualsFunctionVersionRequirement(old, new)) return false
|
||||
@@ -552,6 +566,10 @@ open class ProtoCompareGenerated(
|
||||
if (!checkEquals(oldTypeTable.getType(old.receiverTypeId), newTypeTable.getType(new.receiverTypeId))) return false
|
||||
}
|
||||
|
||||
if (!checkEqualsPropertyContextReceiverType(old, new)) return false
|
||||
|
||||
if (!checkEqualsPropertyContextReceiverTypeId(old, new)) return false
|
||||
|
||||
if (old.hasSetterValueParameter() != new.hasSetterValueParameter()) return false
|
||||
if (old.hasSetterValueParameter()) {
|
||||
if (!checkEquals(old.setterValueParameter, new.setterValueParameter)) return false
|
||||
@@ -1367,6 +1385,26 @@ open class ProtoCompareGenerated(
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassContextReceiverType(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.contextReceiverTypeCount != new.contextReceiverTypeCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeCount - 1) {
|
||||
if (!checkEquals(old.getContextReceiverType(i), new.getContextReceiverType(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassContextReceiverTypeId(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.contextReceiverTypeIdCount != new.contextReceiverTypeIdCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeIdCount - 1) {
|
||||
if (!checkEquals(oldTypeTable.getType(old.getContextReceiverTypeId(i)), newTypeTable.getType(new.getContextReceiverTypeId(i)))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassConstructor(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.constructorCount != new.constructorCount) return false
|
||||
|
||||
@@ -1447,6 +1485,26 @@ open class ProtoCompareGenerated(
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsFunctionContextReceiverType(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||
if (old.contextReceiverTypeCount != new.contextReceiverTypeCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeCount - 1) {
|
||||
if (!checkEquals(old.getContextReceiverType(i), new.getContextReceiverType(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsFunctionContextReceiverTypeId(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||
if (old.contextReceiverTypeIdCount != new.contextReceiverTypeIdCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeIdCount - 1) {
|
||||
if (!checkEquals(oldTypeTable.getType(old.getContextReceiverTypeId(i)), newTypeTable.getType(new.getContextReceiverTypeId(i)))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsFunctionValueParameter(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||
if (old.valueParameterCount != new.valueParameterCount) return false
|
||||
|
||||
@@ -1477,6 +1535,26 @@ open class ProtoCompareGenerated(
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsPropertyContextReceiverType(old: ProtoBuf.Property, new: ProtoBuf.Property): Boolean {
|
||||
if (old.contextReceiverTypeCount != new.contextReceiverTypeCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeCount - 1) {
|
||||
if (!checkEquals(old.getContextReceiverType(i), new.getContextReceiverType(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsPropertyContextReceiverTypeId(old: ProtoBuf.Property, new: ProtoBuf.Property): Boolean {
|
||||
if (old.contextReceiverTypeIdCount != new.contextReceiverTypeIdCount) return false
|
||||
|
||||
for(i in 0..old.contextReceiverTypeIdCount - 1) {
|
||||
if (!checkEquals(oldTypeTable.getType(old.getContextReceiverTypeId(i)), newTypeTable.getType(new.getContextReceiverTypeId(i)))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsPropertyVersionRequirement(old: ProtoBuf.Property, new: ProtoBuf.Property): Boolean {
|
||||
if (old.versionRequirementCount != new.versionRequirementCount) return false
|
||||
|
||||
@@ -1742,6 +1820,14 @@ fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
|
||||
hashCode = 31 * hashCode + stringIndexes(getNestedClassName(i))
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeCount - 1) {
|
||||
hashCode = 31 * hashCode + getContextReceiverType(i).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeIdCount - 1) {
|
||||
hashCode = 31 * hashCode + typeById(getContextReceiverTypeId(i)).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..constructorCount - 1) {
|
||||
hashCode = 31 * hashCode + getConstructor(i).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
@@ -1858,6 +1944,14 @@ fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
|
||||
hashCode = 31 * hashCode + typeById(receiverTypeId).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeCount - 1) {
|
||||
hashCode = 31 * hashCode + getContextReceiverType(i).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeIdCount - 1) {
|
||||
hashCode = 31 * hashCode + typeById(getContextReceiverTypeId(i)).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..valueParameterCount - 1) {
|
||||
hashCode = 31 * hashCode + getValueParameter(i).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
@@ -1938,6 +2032,14 @@ fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
|
||||
hashCode = 31 * hashCode + typeById(receiverTypeId).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeCount - 1) {
|
||||
hashCode = 31 * hashCode + getContextReceiverType(i).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
for(i in 0..contextReceiverTypeIdCount - 1) {
|
||||
hashCode = 31 * hashCode + typeById(getContextReceiverTypeId(i)).hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
if (hasSetterValueParameter()) {
|
||||
hashCode = 31 * hashCode + setterValueParameter.hashCode(stringIndexes, fqNameIndexes, typeById)
|
||||
}
|
||||
|
||||
@@ -295,6 +295,11 @@ class DifferenceCalculatorForClass(
|
||||
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID -> {
|
||||
isClassAffected = true
|
||||
}
|
||||
ProtoBufClassKind.CONTEXT_RECEIVER_TYPE_LIST,
|
||||
ProtoBufClassKind.CONTEXT_RECEIVER_TYPE_ID_LIST -> {
|
||||
isClassAffected = true
|
||||
areSubclassesAffected = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+15
@@ -120,6 +120,9 @@
|
||||
"supertypeIdMemoizedSerializedSize": -1,
|
||||
"nestedClassName_": [],
|
||||
"nestedClassNameMemoizedSerializedSize": -1,
|
||||
"contextReceiverType_": [],
|
||||
"contextReceiverTypeId_": [],
|
||||
"contextReceiverTypeIdMemoizedSerializedSize": -1,
|
||||
"constructor_": [
|
||||
{
|
||||
"unknownFields": {
|
||||
@@ -283,6 +286,9 @@
|
||||
"memoizedHashCode": 0
|
||||
},
|
||||
"receiverTypeId_": 0,
|
||||
"contextReceiverType_": [],
|
||||
"contextReceiverTypeId_": [],
|
||||
"contextReceiverTypeIdMemoizedSerializedSize": -1,
|
||||
"valueParameter_": [],
|
||||
"typeTable_": {
|
||||
"unknownFields": {
|
||||
@@ -458,6 +464,9 @@
|
||||
"memoizedHashCode": 0
|
||||
},
|
||||
"receiverTypeId_": 0,
|
||||
"contextReceiverType_": [],
|
||||
"contextReceiverTypeId_": [],
|
||||
"contextReceiverTypeIdMemoizedSerializedSize": -1,
|
||||
"valueParameter_": [],
|
||||
"typeTable_": {
|
||||
"unknownFields": {
|
||||
@@ -635,6 +644,9 @@
|
||||
"memoizedHashCode": 0
|
||||
},
|
||||
"receiverTypeId_": 0,
|
||||
"contextReceiverType_": [],
|
||||
"contextReceiverTypeId_": [],
|
||||
"contextReceiverTypeIdMemoizedSerializedSize": -1,
|
||||
"setterValueParameter_": {
|
||||
"unknownFields": {
|
||||
"bytes": [],
|
||||
@@ -860,6 +872,9 @@
|
||||
"memoizedHashCode": 0
|
||||
},
|
||||
"receiverTypeId_": 0,
|
||||
"contextReceiverType_": [],
|
||||
"contextReceiverTypeId_": [],
|
||||
"contextReceiverTypeIdMemoizedSerializedSize": -1,
|
||||
"setterValueParameter_": {
|
||||
"unknownFields": {
|
||||
"bytes": [],
|
||||
|
||||
@@ -100,6 +100,13 @@ class DescriptorSerializer private constructor(
|
||||
builder.addTypeParameter(typeParameter(typeParameterDescriptor))
|
||||
}
|
||||
|
||||
val contextReceivers = classDescriptor.contextReceivers
|
||||
if (useTypeTable()) {
|
||||
contextReceivers.forEach { builder.addContextReceiverTypeId(typeId(it.type)) }
|
||||
} else {
|
||||
contextReceivers.forEach { builder.addContextReceiverType(type(it.type)) }
|
||||
}
|
||||
|
||||
if (!KotlinBuiltIns.isSpecialClassWithNoSupertypes(classDescriptor)) {
|
||||
// Special classes (Any, Nothing) have no supertypes
|
||||
for (supertype in classDescriptor.typeConstructor.supertypes) {
|
||||
@@ -197,6 +204,12 @@ class DescriptorSerializer private constructor(
|
||||
)
|
||||
}
|
||||
|
||||
if (classDescriptor.contextReceivers.isNotEmpty()) {
|
||||
builder.addVersionRequirement(
|
||||
writeCompilerVersionRequirement(1, 6, 20, versionRequirementTable)
|
||||
)
|
||||
}
|
||||
|
||||
val versionRequirementTableProto = versionRequirementTable.serialize()
|
||||
if (versionRequirementTableProto != null) {
|
||||
builder.versionRequirementTable = versionRequirementTableProto
|
||||
@@ -308,6 +321,13 @@ class DescriptorSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val contextReceivers = descriptor.contextReceiverParameters
|
||||
if (useTypeTable()) {
|
||||
contextReceivers.forEach { builder.addContextReceiverTypeId(local.typeId(it.type)) }
|
||||
} else {
|
||||
contextReceivers.forEach { builder.addContextReceiverType(local.type(it.type)) }
|
||||
}
|
||||
|
||||
versionRequirementTable?.run {
|
||||
builder.addAllVersionRequirement(serializeVersionRequirements(descriptor))
|
||||
|
||||
@@ -319,6 +339,10 @@ class DescriptorSerializer private constructor(
|
||||
builder.addVersionRequirement(writeVersionRequirement(LanguageFeature.InlineClasses))
|
||||
}
|
||||
|
||||
if (descriptor.contextReceiverParameters.isNotEmpty()) {
|
||||
builder.addVersionRequirement(writeCompilerVersionRequirement(1, 6, 20))
|
||||
}
|
||||
|
||||
if (local.metDefinitelyNotNullType) {
|
||||
builder.addVersionRequirement(writeVersionRequirement(LanguageFeature.DefinitelyNonNullableTypes))
|
||||
}
|
||||
@@ -384,6 +408,13 @@ class DescriptorSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val contextReceivers = descriptor.contextReceiverParameters
|
||||
if (useTypeTable()) {
|
||||
contextReceivers.forEach { builder.addContextReceiverTypeId(local.typeId(it.type)) }
|
||||
} else {
|
||||
contextReceivers.forEach { builder.addContextReceiverType(local.type(it.type)) }
|
||||
}
|
||||
|
||||
for (valueParameterDescriptor in descriptor.valueParameters) {
|
||||
builder.addValueParameter(local.valueParameter(valueParameterDescriptor))
|
||||
}
|
||||
@@ -406,6 +437,10 @@ class DescriptorSerializer private constructor(
|
||||
builder.addVersionRequirement(writeVersionRequirement(LanguageFeature.InlineClasses))
|
||||
}
|
||||
|
||||
if (descriptor.contextReceiverParameters.isNotEmpty()) {
|
||||
builder.addVersionRequirement(writeCompilerVersionRequirement(1, 6, 20))
|
||||
}
|
||||
|
||||
if (local.metDefinitelyNotNullType) {
|
||||
builder.addVersionRequirement(writeVersionRequirement(LanguageFeature.DefinitelyNonNullableTypes))
|
||||
}
|
||||
@@ -747,6 +782,9 @@ class DescriptorSerializer private constructor(
|
||||
return writeLanguageVersionRequirement(languageFeature, this)
|
||||
}
|
||||
|
||||
private fun MutableVersionRequirementTable.writeCompilerVersionRequirement(major: Int, minor: Int, patch: Int): Int =
|
||||
writeCompilerVersionRequirement(major, minor, patch, this)
|
||||
|
||||
// Returns a list of indices into versionRequirementTable, or empty list if there's no @RequireKotlin on the descriptor
|
||||
private fun MutableVersionRequirementTable.serializeVersionRequirements(descriptor: DeclarationDescriptor): List<Int> =
|
||||
descriptor.annotations
|
||||
@@ -898,6 +936,17 @@ class DescriptorSerializer private constructor(
|
||||
)
|
||||
}
|
||||
|
||||
fun writeCompilerVersionRequirement(
|
||||
major: Int,
|
||||
minor: Int,
|
||||
patch: Int,
|
||||
versionRequirementTable: MutableVersionRequirementTable
|
||||
): Int = writeVersionRequirement(
|
||||
major, minor, patch,
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION,
|
||||
versionRequirementTable
|
||||
)
|
||||
|
||||
fun writeVersionRequirement(
|
||||
major: Int,
|
||||
minor: Int,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package test
|
||||
|
||||
interface A
|
||||
interface B
|
||||
|
||||
context(A, B)
|
||||
class ClassWithCR {
|
||||
context(A, B)
|
||||
val memberPropWithCR: Any?
|
||||
get() = null
|
||||
|
||||
context(A, B)
|
||||
fun memberFunWithCR() {}
|
||||
}
|
||||
|
||||
context(A, B)
|
||||
fun topLevelFunWithCR() {}
|
||||
|
||||
context(A, B)
|
||||
val topLevelPropWithCR: Any?
|
||||
get() = null
|
||||
@@ -169,4 +169,18 @@ class JvmVersionRequirementTest : AbstractVersionRequirementTest() {
|
||||
shouldBeSingleRequirement = false
|
||||
)
|
||||
}
|
||||
|
||||
fun testContextReceivers() {
|
||||
doTest(
|
||||
VersionRequirement.Version(1, 6, 20), DeprecationLevel.ERROR, null, COMPILER_VERSION, null,
|
||||
fqNamesWithRequirements = listOf(
|
||||
"test.ClassWithCR",
|
||||
"test.ClassWithCR.memberPropWithCR",
|
||||
"test.ClassWithCR.memberFunWithCR",
|
||||
"test.topLevelFunWithCR",
|
||||
"test.topLevelPropWithCR"
|
||||
),
|
||||
customLanguageVersion = LanguageVersion.KOTLIN_1_7
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +225,9 @@ message Class {
|
||||
|
||||
repeated int32 nested_class_name = 7 [packed = true, (name_id_in_table) = true];
|
||||
|
||||
repeated Type context_receiver_type = 20;
|
||||
repeated int32 context_receiver_type_id = 21 [packed = true, (type_id_in_table) = true];
|
||||
|
||||
repeated Constructor constructor = 8;
|
||||
repeated Function function = 9;
|
||||
repeated Property property = 10;
|
||||
@@ -316,6 +319,9 @@ message Function {
|
||||
optional Type receiver_type = 5;
|
||||
optional int32 receiver_type_id = 8 [(type_id_in_table) = true];
|
||||
|
||||
repeated Type context_receiver_type = 10;
|
||||
repeated int32 context_receiver_type_id = 11 [packed = true, (type_id_in_table) = true];
|
||||
|
||||
repeated ValueParameter value_parameter = 6;
|
||||
|
||||
optional TypeTable type_table = 30;
|
||||
@@ -357,6 +363,9 @@ message Property {
|
||||
optional Type receiver_type = 5;
|
||||
optional int32 receiver_type_id = 10 [(type_id_in_table) = true];
|
||||
|
||||
repeated Type context_receiver_type = 12;
|
||||
repeated int32 context_receiver_type_id = 13 [packed = true, (type_id_in_table) = true];
|
||||
|
||||
optional ValueParameter setter_value_parameter = 6;
|
||||
|
||||
/*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user