Generate Klib JS extensions for proto comparison

This commit is contained in:
Alexey Tsvetkov
2019-10-25 07:46:34 +03:00
committed by romanart
parent 83f060ad3e
commit c694752b4f
7 changed files with 4001 additions and 5448 deletions
+1
View File
@@ -13,6 +13,7 @@ dependencies {
compileOnly(project(":compiler:frontend.java"))
compileOnly(project(":js:js.serializer"))
compileOnly(project(":js:js.frontend"))
compileOnly(project(":kotlin-util-klib-metadata"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
compileOnly(intellijDep()) { includeJars("asm-all", "trove4j", "util", rootProject = rootProject) }
compileOnly(project(":kotlin-reflect-api"))
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
@@ -79,6 +80,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (old.getExtension(BuiltInsProtoBuf.packageFqName) != new.getExtension(BuiltInsProtoBuf.packageFqName)) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.packageFqName) != new.hasExtension(KlibMetadataProtoBuf.packageFqName)) return false
if (old.hasExtension(KlibMetadataProtoBuf.packageFqName)) {
if (old.getExtension(KlibMetadataProtoBuf.packageFqName) != new.getExtension(KlibMetadataProtoBuf.packageFqName)) return false
}
return true
}
enum class ProtoBufPackageKind {
@@ -90,7 +96,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
JVM_EXT_PACKAGE_MODULE_NAME,
JVM_EXT_PACKAGE_LOCAL_VARIABLE_LIST,
JS_EXT_PACKAGE_FQ_NAME,
BUILT_INS_EXT_PACKAGE_FQ_NAME
BUILT_INS_EXT_PACKAGE_FQ_NAME,
KLIB_EXT_PACKAGE_FQ_NAME
}
fun difference(old: ProtoBuf.Package, new: ProtoBuf.Package): EnumSet<ProtoBufPackageKind> {
@@ -136,6 +143,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (old.getExtension(BuiltInsProtoBuf.packageFqName) != new.getExtension(BuiltInsProtoBuf.packageFqName)) result.add(ProtoBufPackageKind.BUILT_INS_EXT_PACKAGE_FQ_NAME)
}
if (old.hasExtension(KlibMetadataProtoBuf.packageFqName) != new.hasExtension(KlibMetadataProtoBuf.packageFqName)) result.add(ProtoBufPackageKind.KLIB_EXT_PACKAGE_FQ_NAME)
if (old.hasExtension(KlibMetadataProtoBuf.packageFqName)) {
if (old.getExtension(KlibMetadataProtoBuf.packageFqName) != new.getExtension(KlibMetadataProtoBuf.packageFqName)) result.add(ProtoBufPackageKind.KLIB_EXT_PACKAGE_FQ_NAME)
}
return result
}
@@ -231,6 +243,25 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.classAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.classAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.classAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.classAnnotation, i), new.getExtension(KlibMetadataProtoBuf.classAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.classFile) != new.hasExtension(KlibMetadataProtoBuf.classFile)) return false
if (old.hasExtension(KlibMetadataProtoBuf.classFile)) {
if (old.getExtension(KlibMetadataProtoBuf.classFile) != new.getExtension(KlibMetadataProtoBuf.classFile)) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.classUniqId) != new.hasExtension(KlibMetadataProtoBuf.classUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.classUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.classUniqId), new.getExtension(KlibMetadataProtoBuf.classUniqId))) return false
}
return true
}
enum class ProtoBufClassKind {
@@ -256,7 +287,10 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
JS_EXT_CLASS_ANNOTATION_LIST,
JS_EXT_CLASS_CONTAINING_FILE_ID,
JAVA_EXT_IS_PACKAGE_PRIVATE_CLASS,
BUILT_INS_EXT_CLASS_ANNOTATION_LIST
BUILT_INS_EXT_CLASS_ANNOTATION_LIST,
KLIB_EXT_CLASS_ANNOTATION_LIST,
KLIB_EXT_CLASS_FILE,
KLIB_EXT_CLASS_UNIQ_ID
}
fun difference(old: ProtoBuf.Class, new: ProtoBuf.Class): EnumSet<ProtoBufClassKind> {
@@ -353,6 +387,25 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.classAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.classAnnotation)) {
result.add(ProtoBufClassKind.KLIB_EXT_CLASS_ANNOTATION_LIST)
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.classAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.classAnnotation, i), new.getExtension(KlibMetadataProtoBuf.classAnnotation, i))) result.add(ProtoBufClassKind.KLIB_EXT_CLASS_ANNOTATION_LIST)
}
}
if (old.hasExtension(KlibMetadataProtoBuf.classFile) != new.hasExtension(KlibMetadataProtoBuf.classFile)) result.add(ProtoBufClassKind.KLIB_EXT_CLASS_FILE)
if (old.hasExtension(KlibMetadataProtoBuf.classFile)) {
if (old.getExtension(KlibMetadataProtoBuf.classFile) != new.getExtension(KlibMetadataProtoBuf.classFile)) result.add(ProtoBufClassKind.KLIB_EXT_CLASS_FILE)
}
if (old.hasExtension(KlibMetadataProtoBuf.classUniqId) != new.hasExtension(KlibMetadataProtoBuf.classUniqId)) result.add(ProtoBufClassKind.KLIB_EXT_CLASS_UNIQ_ID)
if (old.hasExtension(KlibMetadataProtoBuf.classUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.classUniqId), new.getExtension(KlibMetadataProtoBuf.classUniqId))) result.add(ProtoBufClassKind.KLIB_EXT_CLASS_UNIQ_ID)
}
return result
}
@@ -448,6 +501,25 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.functionAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.functionAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.functionAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.functionAnnotation, i), new.getExtension(KlibMetadataProtoBuf.functionAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.functionFile) != new.hasExtension(KlibMetadataProtoBuf.functionFile)) return false
if (old.hasExtension(KlibMetadataProtoBuf.functionFile)) {
if (old.getExtension(KlibMetadataProtoBuf.functionFile) != new.getExtension(KlibMetadataProtoBuf.functionFile)) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.functionUniqId) != new.hasExtension(KlibMetadataProtoBuf.functionUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.functionUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.functionUniqId), new.getExtension(KlibMetadataProtoBuf.functionUniqId))) return false
}
return true
}
@@ -592,6 +664,48 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (!checkEquals(old.getExtension(BuiltInsProtoBuf.compileTimeValue), new.getExtension(BuiltInsProtoBuf.compileTimeValue))) return false
}
if (old.getExtensionCount(KlibMetadataProtoBuf.propertyAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.propertyAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.propertyAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.propertyAnnotation, i), new.getExtension(KlibMetadataProtoBuf.propertyAnnotation, i))) return false
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.propertyGetterAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.propertyGetterAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.propertyGetterAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.propertyGetterAnnotation, i), new.getExtension(KlibMetadataProtoBuf.propertyGetterAnnotation, i))) return false
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.propertySetterAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.propertySetterAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.propertySetterAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.propertySetterAnnotation, i), new.getExtension(KlibMetadataProtoBuf.propertySetterAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.compileTimeValue) != new.hasExtension(KlibMetadataProtoBuf.compileTimeValue)) return false
if (old.hasExtension(KlibMetadataProtoBuf.compileTimeValue)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.compileTimeValue), new.getExtension(KlibMetadataProtoBuf.compileTimeValue))) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.propertyFile) != new.hasExtension(KlibMetadataProtoBuf.propertyFile)) return false
if (old.hasExtension(KlibMetadataProtoBuf.propertyFile)) {
if (old.getExtension(KlibMetadataProtoBuf.propertyFile) != new.getExtension(KlibMetadataProtoBuf.propertyFile)) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.propertyUniqId) != new.hasExtension(KlibMetadataProtoBuf.propertyUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.propertyUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.propertyUniqId), new.getExtension(KlibMetadataProtoBuf.propertyUniqId))) return false
}
return true
}
@@ -629,6 +743,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (!checkEqualsTypeAliasVersionRequirement(old, new)) return false
if (old.hasExtension(KlibMetadataProtoBuf.typeAliasUniqId) != new.hasExtension(KlibMetadataProtoBuf.typeAliasUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.typeAliasUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.typeAliasUniqId), new.getExtension(KlibMetadataProtoBuf.typeAliasUniqId))) return false
}
return true
}
@@ -695,6 +814,20 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.typeParameterAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.typeParameterAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.typeParameterAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.typeParameterAnnotation, i), new.getExtension(KlibMetadataProtoBuf.typeParameterAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.typeParamUniqId) != new.hasExtension(KlibMetadataProtoBuf.typeParamUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.typeParamUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.typeParamUniqId), new.getExtension(KlibMetadataProtoBuf.typeParamUniqId))) return false
}
return true
}
@@ -798,6 +931,15 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.typeAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.typeAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.typeAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.typeAnnotation, i), new.getExtension(KlibMetadataProtoBuf.typeAnnotation, i))) return false
}
}
return true
}
@@ -839,6 +981,20 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.constructorAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.constructorAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.constructorAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.constructorAnnotation, i), new.getExtension(KlibMetadataProtoBuf.constructorAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.constructorUniqId) != new.hasExtension(KlibMetadataProtoBuf.constructorUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.constructorUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.constructorUniqId), new.getExtension(KlibMetadataProtoBuf.constructorUniqId))) return false
}
return true
}
@@ -866,6 +1022,25 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.enumEntryAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.enumEntryAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.enumEntryAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.enumEntryAnnotation, i), new.getExtension(KlibMetadataProtoBuf.enumEntryAnnotation, i))) return false
}
}
if (old.hasExtension(KlibMetadataProtoBuf.enumEntryOrdinal) != new.hasExtension(KlibMetadataProtoBuf.enumEntryOrdinal)) return false
if (old.hasExtension(KlibMetadataProtoBuf.enumEntryOrdinal)) {
if (old.getExtension(KlibMetadataProtoBuf.enumEntryOrdinal) != new.getExtension(KlibMetadataProtoBuf.enumEntryOrdinal)) return false
}
if (old.hasExtension(KlibMetadataProtoBuf.enumEntryUniqId) != new.hasExtension(KlibMetadataProtoBuf.enumEntryUniqId)) return false
if (old.hasExtension(KlibMetadataProtoBuf.enumEntryUniqId)) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.enumEntryUniqId), new.getExtension(KlibMetadataProtoBuf.enumEntryUniqId))) return false
}
return true
}
@@ -877,6 +1052,12 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
return true
}
open fun checkEquals(old: KlibMetadataProtoBuf.DescriptorUniqId, new: KlibMetadataProtoBuf.DescriptorUniqId): Boolean {
if (old.index != new.index) return false
return true
}
open fun checkEquals(old: ProtoBuf.ValueParameter, new: ProtoBuf.ValueParameter): Boolean {
if (old.hasFlags() != new.hasFlags()) return false
if (old.hasFlags()) {
@@ -923,6 +1104,15 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
}
}
if (old.getExtensionCount(KlibMetadataProtoBuf.parameterAnnotation) != new.getExtensionCount(KlibMetadataProtoBuf.parameterAnnotation)) {
return false
}
else {
for(i in 0..old.getExtensionCount(KlibMetadataProtoBuf.parameterAnnotation) - 1) {
if (!checkEquals(old.getExtension(KlibMetadataProtoBuf.parameterAnnotation, i), new.getExtension(KlibMetadataProtoBuf.parameterAnnotation, i))) return false
}
}
return true
}
@@ -1575,6 +1765,10 @@ fun ProtoBuf.Package.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.packageFqName)
}
if (hasExtension(KlibMetadataProtoBuf.packageFqName)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.packageFqName)
}
return hashCode
}
@@ -1671,6 +1865,18 @@ fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.classAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.classAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.classAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.classFile)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.classFile)
}
if (hasExtension(KlibMetadataProtoBuf.classUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.classUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -1751,6 +1957,18 @@ fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.functionAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.functionAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.functionAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.functionFile)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.functionFile)
}
if (hasExtension(KlibMetadataProtoBuf.functionUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.functionUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -1855,6 +2073,30 @@ fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.compileTimeValue).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.propertyAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.propertyAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.propertyGetterAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.propertyGetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.propertySetterAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.propertySetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.compileTimeValue)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.compileTimeValue).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.propertyFile)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.propertyFile)
}
if (hasExtension(KlibMetadataProtoBuf.propertyUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.propertyUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -1895,6 +2137,10 @@ fun ProtoBuf.TypeAlias.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int
hashCode = 31 * hashCode + getVersionRequirement(i)
}
if (hasExtension(KlibMetadataProtoBuf.typeAliasUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.typeAliasUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -1957,6 +2203,14 @@ fun ProtoBuf.TypeParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.typeParameterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.typeParameterAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.typeParameterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.typeParamUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.typeParamUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -2035,6 +2289,10 @@ fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.typeAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -2069,6 +2327,14 @@ fun ProtoBuf.Constructor.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (I
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.constructorAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.constructorAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.constructorAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.constructorUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.constructorUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -2087,6 +2353,18 @@ fun ProtoBuf.EnumEntry.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.enumEntryAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.enumEntryAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.enumEntryAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(KlibMetadataProtoBuf.enumEntryOrdinal)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.enumEntryOrdinal)
}
if (hasExtension(KlibMetadataProtoBuf.enumEntryUniqId)) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.enumEntryUniqId).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -2102,6 +2380,14 @@ fun ProtoBuf.Annotation.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (In
return hashCode
}
fun KlibMetadataProtoBuf.DescriptorUniqId.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
var hashCode = 1
hashCode = 31 * hashCode + index.hashCode()
return hashCode
}
fun ProtoBuf.ValueParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
var hashCode = 1
@@ -2135,6 +2421,10 @@ fun ProtoBuf.ValueParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.parameterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(KlibMetadataProtoBuf.parameterAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(KlibMetadataProtoBuf.parameterAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -30,9 +30,9 @@ import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
import java.util.*
data class Difference(
val isClassAffected: Boolean = false,
val areSubclassesAffected: Boolean = false,
val changedMembersNames: Set<String> = emptySet()
val isClassAffected: Boolean = false,
val areSubclassesAffected: Boolean = false,
val changedMembersNames: Set<String> = emptySet()
)
sealed class ProtoData
@@ -49,14 +49,17 @@ fun ProtoMapValue.toProtoData(packageFqName: FqName): ProtoData =
}
internal val MessageLite.isPrivate: Boolean
get() = Visibilities.isPrivate(ProtoEnumFlags.visibility(
get() = Visibilities.isPrivate(
ProtoEnumFlags.visibility(
when (this) {
is ProtoBuf.Constructor -> Flags.VISIBILITY.get(flags)
is ProtoBuf.Function -> Flags.VISIBILITY.get(flags)
is ProtoBuf.Property -> Flags.VISIBILITY.get(flags)
is ProtoBuf.TypeAlias -> Flags.VISIBILITY.get(flags)
else -> error("Unknown message: $this")
}))
}
)
)
private fun MessageLite.name(nameResolver: NameResolver): String {
return when (this) {
@@ -79,9 +82,9 @@ abstract class DifferenceCalculator {
val result = hashSetOf<String>()
val oldMap =
oldList.groupBy { it.getHashCode({ compareObject.oldGetIndexOfString(it) }, { compareObject.oldGetIndexOfClassId(it) }) }
oldList.groupBy { it.getHashCode({ compareObject.oldGetIndexOfString(it) }, { compareObject.oldGetIndexOfClassId(it) }) }
val newMap =
newList.groupBy { it.getHashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) }) }
newList.groupBy { it.getHashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) }) }
val hashes = oldMap.keys + newMap.keys
for (hash in hashes) {
@@ -100,8 +103,8 @@ abstract class DifferenceCalculator {
}
private fun calcDifferenceForEqualHashes(
oldList: List<MessageLite>,
newList: List<MessageLite>
oldList: List<MessageLite>,
newList: List<MessageLite>
): Collection<String> {
val result = hashSetOf<String>()
val newSet = HashSet(newList)
@@ -110,8 +113,7 @@ abstract class DifferenceCalculator {
val newMember = newSet.firstOrNull { compareObject.checkEquals(oldMember, it) }
if (newMember != null) {
newSet.remove(newMember)
}
else {
} else {
result.add(oldMember.name(compareObject.oldNameResolver))
}
}
@@ -124,8 +126,8 @@ abstract class DifferenceCalculator {
}
protected fun calcDifferenceForNames(
oldList: List<Int>,
newList: List<Int>
oldList: List<Int>,
newList: List<Int>
): Collection<String> {
val oldNames = oldList.map { compareObject.oldNameResolver.getString(it) }.toSet()
val newNames = newList.map { compareObject.newNameResolver.getString(it) }.toSet()
@@ -154,8 +156,8 @@ abstract class DifferenceCalculator {
}
class DifferenceCalculatorForClass(
private val oldData: ClassProtoData,
private val newData: ClassProtoData
private val oldData: ClassProtoData,
private val newData: ClassProtoData
) : DifferenceCalculator() {
override val compareObject = ProtoCompareGenerated(oldData.nameResolver, newData.nameResolver)
@@ -223,8 +225,8 @@ class DifferenceCalculatorForClass(
ProtoBufClassKind.TYPE_TABLE -> {
// TODO
}
ProtoCompareGenerated.ProtoBufClassKind.VERSION_REQUIREMENT_LIST,
ProtoCompareGenerated.ProtoBufClassKind.VERSION_REQUIREMENT_TABLE -> {
ProtoBufClassKind.VERSION_REQUIREMENT_LIST,
ProtoBufClassKind.VERSION_REQUIREMENT_TABLE -> {
// TODO
}
ProtoBufClassKind.FLAGS,
@@ -238,7 +240,7 @@ class DifferenceCalculatorForClass(
}
ProtoBufClassKind.JVM_EXT_CLASS_MODULE_NAME,
ProtoBufClassKind.JS_EXT_CLASS_CONTAINING_FILE_ID -> {
// TODO
// TODO
}
ProtoBufClassKind.JVM_EXT_CLASS_LOCAL_VARIABLE_LIST -> {
// Not affected, local variables are not accessible outside of a file
@@ -250,9 +252,16 @@ class DifferenceCalculatorForClass(
ProtoBufClassKind.BUILT_INS_EXT_CLASS_ANNOTATION_LIST -> {
isClassAffected = true
}
ProtoCompareGenerated.ProtoBufClassKind.JVM_EXT_ANONYMOUS_OBJECT_ORIGIN_NAME -> {
ProtoBufClassKind.JVM_EXT_ANONYMOUS_OBJECT_ORIGIN_NAME -> {
// Not affected, this extension is not used in the compiler
}
ProtoBufClassKind.KLIB_EXT_CLASS_ANNOTATION_LIST -> {
isClassAffected = true
}
ProtoBufClassKind.KLIB_EXT_CLASS_FILE,
ProtoBufClassKind.KLIB_EXT_CLASS_UNIQ_ID -> {
// Not affected (probably?)
}
}
}
@@ -261,8 +270,8 @@ class DifferenceCalculatorForClass(
}
class DifferenceCalculatorForPackageFacade(
private val oldData: PackagePartProtoData,
private val newData: PackagePartProtoData
private val oldData: PackagePartProtoData,
private val newData: PackagePartProtoData
) : DifferenceCalculator() {
override val compareObject = ProtoCompareGenerated(oldData.nameResolver, newData.nameResolver)
@@ -292,7 +301,7 @@ class DifferenceCalculatorForPackageFacade(
ProtoBufPackageKind.TYPE_TABLE,
ProtoBufPackageKind.VERSION_REQUIREMENT_TABLE,
ProtoBufPackageKind.JVM_EXT_PACKAGE_MODULE_NAME,
ProtoBufPackageKind.JS_EXT_PACKAGE_FQ_NAME-> {
ProtoBufPackageKind.JS_EXT_PACKAGE_FQ_NAME -> {
// TODO
}
ProtoBufPackageKind.JVM_EXT_PACKAGE_LOCAL_VARIABLE_LIST -> {
@@ -301,6 +310,9 @@ class DifferenceCalculatorForPackageFacade(
ProtoBufPackageKind.BUILT_INS_EXT_PACKAGE_FQ_NAME -> {
// Not affected
}
ProtoBufPackageKind.KLIB_EXT_PACKAGE_FQ_NAME -> {
// Not affected
}
}
}