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
}
}
}
@@ -58,7 +58,7 @@ val PROTO_PATHS: List<ProtoPath> = listOf(
ProtoPath("core/metadata.jvm/src/jvm_metadata.proto"),
ProtoPath("core/metadata.jvm/src/jvm_module.proto"),
ProtoPath("build-common/src/java_descriptors.proto"),
ProtoPath("compiler/util-klib-metadata/src/KlibMetadataProtoBuf.proto", false),
ProtoPath("compiler/util-klib-metadata/src/KlibMetadataProtoBuf.proto"),
ProtoPath("compiler/ir/serialization.common/src/KotlinIr.proto", false)
)
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.generators.protobuf
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
import org.jetbrains.kotlin.library.metadata.DebugKlibMetadataProtoBuf
import org.jetbrains.kotlin.metadata.DebugExtOptionsProtoBuf
import org.jetbrains.kotlin.metadata.DebugProtoBuf
import org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf
@@ -43,13 +44,13 @@ class GenerateProtoBufCompare {
}
private val JAVA_TYPES_WITH_INLINED_EQUALS: EnumSet<Descriptors.FieldDescriptor.JavaType> = EnumSet.of(
Descriptors.FieldDescriptor.JavaType.INT,
Descriptors.FieldDescriptor.JavaType.LONG,
Descriptors.FieldDescriptor.JavaType.FLOAT,
Descriptors.FieldDescriptor.JavaType.DOUBLE,
Descriptors.FieldDescriptor.JavaType.BOOLEAN,
Descriptors.FieldDescriptor.JavaType.STRING,
Descriptors.FieldDescriptor.JavaType.ENUM
Descriptors.FieldDescriptor.JavaType.INT,
Descriptors.FieldDescriptor.JavaType.LONG,
Descriptors.FieldDescriptor.JavaType.FLOAT,
Descriptors.FieldDescriptor.JavaType.DOUBLE,
Descriptors.FieldDescriptor.JavaType.BOOLEAN,
Descriptors.FieldDescriptor.JavaType.STRING,
Descriptors.FieldDescriptor.JavaType.ENUM
)
@@ -63,11 +64,34 @@ class GenerateProtoBufCompare {
private val CHECK_CLASS_ID_EQUALS_NAME = "checkClassIdEquals"
private val HASH_CODE_NAME = "hashCode"
private val jvmExtensions = DebugJvmProtoBuf.getDescriptor().extensions
private val jsExtensions = DebugJsProtoBuf.getDescriptor().extensions
private val javaExtensions = DebugJavaClassProtoBuf.getDescriptor().extensions
private val builtInsExtensions = DebugBuiltInsProtoBuf.getDescriptor().extensions
private val extensionsMap = (jvmExtensions + jsExtensions + javaExtensions + builtInsExtensions).groupBy { it.containingType }
private val extensions = object {
val jvm = DebugJvmProtoBuf.getDescriptor().extensions
val js = DebugJsProtoBuf.getDescriptor().extensions
val java = DebugJavaClassProtoBuf.getDescriptor().extensions
val builtIns = DebugBuiltInsProtoBuf.getDescriptor().extensions
val klib = DebugKlibMetadataProtoBuf.getDescriptor().extensions
private val extensionsMap = (jvm + js + java + builtIns + klib).groupBy { it.containingType }
operator fun get(desc: Descriptors.Descriptor): List<Descriptors.FieldDescriptor>? = extensionsMap[desc]
fun getEnumName(fieldDescriptor: Descriptors.FieldDescriptor): String {
var extensionPrefix = ""
if (fieldDescriptor.isExtension) {
extensionPrefix = when {
fieldDescriptor in jvm -> "jvmExt_"
fieldDescriptor in js -> "jsExt_"
fieldDescriptor in java -> "javaExt_"
fieldDescriptor in builtIns -> "builtInsExt_"
fieldDescriptor in klib -> "klibExt_"
else -> error("Unknown extension")
}
}
return (extensionPrefix + fieldDescriptor.name.javaName + (if (fieldDescriptor.isRepeated) "List" else ""))
.replace("[A-Z]".toRegex()) { "_" + it.value }
.toUpperCase()
}
}
private val allMessages: MutableSet<Descriptors.Descriptor> = linkedSetOf()
private val messagesToProcess: Queue<Descriptors.Descriptor> = LinkedList()
@@ -80,6 +104,7 @@ class GenerateProtoBufCompare {
p.println("package org.jetbrains.kotlin.incremental")
p.println()
p.println("import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf")
p.println("import org.jetbrains.kotlin.metadata.ProtoBuf")
p.println("import org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf")
p.println("import org.jetbrains.kotlin.metadata.deserialization.NameResolver")
@@ -178,7 +203,7 @@ class GenerateProtoBufCompare {
val typeName = descriptor.typeName
val fields = descriptor.fields.filter { !it.isSkip }
val extFields = extensionsMap[descriptor]?.filter { !it.isSkip } ?: emptyList()
val extFields = extensions[descriptor]?.filter { !it.isSkip } ?: emptyList()
p.println()
p.println("fun $typeName.$HASH_CODE_NAME(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {")
@@ -211,11 +236,9 @@ class GenerateProtoBufCompare {
p.println(" $HASH_CODE_NAME = 31 * $HASH_CODE_NAME + ${fieldToHashCode(field, repeatedFieldValue)}")
p.println("}")
}
else if (field.isRequired) {
} else if (field.isRequired) {
p.println("$HASH_CODE_NAME = 31 * $HASH_CODE_NAME + ${fieldToHashCode(field, fieldValue)}")
}
else if (field.isOptional) {
} else if (field.isOptional) {
p.println("if ($hasMethod) {")
p.println(" $HASH_CODE_NAME = 31 * $HASH_CODE_NAME + ${fieldToHashCode(field, fieldValue)}")
p.println("}")
@@ -226,7 +249,7 @@ class GenerateProtoBufCompare {
val typeName = descriptor.typeName
val fields = descriptor.fields.filter { !it.isSkip }
val extFields = extensionsMap[descriptor]?.filter { !it.isSkip } ?: emptyList()
val extFields = extensions[descriptor]?.filter { !it.isSkip } ?: emptyList()
p.println("open fun $CHECK_EQUALS_NAME(old: $typeName, new: $typeName): Boolean {")
p.pushIndent()
@@ -245,11 +268,11 @@ class GenerateProtoBufCompare {
val className = typeName.replace(".", "")
val fields = descriptor.fields.filter { !it.isSkip }
val extFields = extensionsMap[descriptor]?.filter { !it.isSkip } ?: emptyList()
val extFields = extensions[descriptor]?.filter { !it.isSkip } ?: emptyList()
val allFields = fields + extFields
p.println("enum class ${className}Kind {")
p.println(allFields.joinToString(",\n ") { " " + it.enumName })
p.println(allFields.joinToString(",\n ") { " " + extensions.getEnumName(it) })
p.println("}")
p.println()
@@ -299,11 +322,9 @@ class GenerateProtoBufCompare {
fun generate() {
if (field.isRepeated) {
printRepeatedField()
}
else if (field.isRequired) {
} else if (field.isRequired) {
printRequiredField()
}
else if (field.isOptional) {
} else if (field.isOptional) {
printOptionalField()
}
@@ -348,7 +369,8 @@ class GenerateProtoBufCompare {
val fullFieldName = "$outerClassName.$fieldName"
override fun printRepeatedField() {
p.printlnMultiline("""
p.printlnMultiline(
"""
if (old.getExtensionCount($fullFieldName) != new.getExtensionCount($fullFieldName)) {
$statement
}
@@ -357,7 +379,8 @@ class GenerateProtoBufCompare {
${ifWithComparison(field, "getExtension($fullFieldName, i)", statement)}
}
}
""")
"""
)
}
override fun printRequiredField() {
@@ -379,11 +402,11 @@ class GenerateProtoBufCompare {
}
inner class ExtFieldGeneratorForDiff(field: Descriptors.FieldDescriptor, p: Printer) : ExtFieldGeneratorImpl(field, p) {
override fun Descriptors.FieldDescriptor.getStatement(): String = statementForDiff
override fun Descriptors.FieldDescriptor.getStatement(): String = statementForDiff
}
private val Descriptors.FieldDescriptor.statementForDiff: String
get() = "$RESULT_NAME.add(${containingType.typeName.replace(".", "")}Kind.$enumName)"
get() = "$RESULT_NAME.add(${containingType.typeName.replace(".", "")}Kind.${extensions.getEnumName(this)})"
private val Descriptors.FieldDescriptor.isSkip: Boolean
get() = options.getExtension(DebugExtOptionsProtoBuf.skipInComparison)
@@ -402,17 +425,17 @@ class GenerateProtoBufCompare {
}
private fun ifWithComparison(field: Descriptors.FieldDescriptor, expr: String, statement: String) =
when {
field.options.getExtension(DebugExtOptionsProtoBuf.stringIdInTable) ||
field.options.getExtension(DebugExtOptionsProtoBuf.nameIdInTable) ->
"if (!$CHECK_STRING_EQUALS_NAME(old.$expr, new.$expr)) $statement"
field.options.getExtension(DebugExtOptionsProtoBuf.fqNameIdInTable) ->
"if (!$CHECK_CLASS_ID_EQUALS_NAME(old.$expr, new.$expr)) $statement"
field.javaType in JAVA_TYPES_WITH_INLINED_EQUALS ->
"if (old.$expr != new.$expr) $statement"
else ->
"if (!$CHECK_EQUALS_NAME(old.$expr, new.$expr)) $statement"
}
when {
field.options.getExtension(DebugExtOptionsProtoBuf.stringIdInTable) ||
field.options.getExtension(DebugExtOptionsProtoBuf.nameIdInTable) ->
"if (!$CHECK_STRING_EQUALS_NAME(old.$expr, new.$expr)) $statement"
field.options.getExtension(DebugExtOptionsProtoBuf.fqNameIdInTable) ->
"if (!$CHECK_CLASS_ID_EQUALS_NAME(old.$expr, new.$expr)) $statement"
field.javaType in JAVA_TYPES_WITH_INLINED_EQUALS ->
"if (old.$expr != new.$expr) $statement"
else ->
"if (!$CHECK_EQUALS_NAME(old.$expr, new.$expr)) $statement"
}
private fun Printer.printlnIfWithComparison(field: Descriptors.FieldDescriptor, expr: String, statement: String = "return false") {
this.println(ifWithComparison(field, expr, statement))
@@ -427,7 +450,7 @@ class GenerateProtoBufCompare {
private fun fieldToHashCode(field: Descriptors.FieldDescriptor, expr: String): String =
when {
field.options.getExtension(DebugExtOptionsProtoBuf.stringIdInTable) ||
field.options.getExtension(DebugExtOptionsProtoBuf.nameIdInTable) ->
field.options.getExtension(DebugExtOptionsProtoBuf.nameIdInTable) ->
"stringIndexes($expr)"
field.options.getExtension(DebugExtOptionsProtoBuf.fqNameIdInTable) ->
"fqNameIndexes($expr)"
@@ -446,26 +469,6 @@ class GenerateProtoBufCompare {
return outerClassName + fullName.removePrefix(packageHeader)
}
private val Descriptors.FieldDescriptor.enumName: String
get() {
var extensionPrefix = ""
if (isExtension) {
if (this in jvmExtensions) {
extensionPrefix = "jvmExt_"
}
if (this in jsExtensions) {
extensionPrefix = "jsExt_"
}
if (this in javaExtensions) {
extensionPrefix = "javaExt_"
}
if (this in builtInsExtensions) {
extensionPrefix = "builtInsExt_"
}
}
return (extensionPrefix + name.javaName + (if (isRepeated) "List" else "")).replace("[A-Z]".toRegex()) { "_" + it.value }.toUpperCase()
}
private fun Descriptors.FieldDescriptor.helperMethodName(): String {
val packageHeader = this.file.`package`
val descriptor = this.containingType