IR: Avoid overwriting of property signature descriptions

^KT-64085
^KT-64082
This commit is contained in:
Dmitriy Dolovov
2023-12-06 21:15:25 +01:00
committed by Space Team
parent 03cf13705e
commit c9f4a1a841
12 changed files with 148 additions and 24 deletions
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.ir.util.KotlinMangler
import org.jetbrains.kotlin.name.FqName
abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Declaration>> {
private data class PropertyAccessorIdHashAndDescription(val id: Long, val description: String)
protected var packageFqn: FqName = FqName.ROOT
protected val classFqnSegments = mutableListOf<String>()
@@ -26,7 +28,7 @@ abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Dec
*
* This property is made private to enforce always setting [description] along with it.
*/
private var hashIdAcc: Long? = null
private var propertyAccessorIdHashAndDescription: PropertyAccessorIdHashAndDescription? = null
protected var overridden: List<Declaration>? = null
protected var mask = 0L
@@ -73,12 +75,12 @@ abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Dec
protected fun setHashIdAndDescription(id: Long, description: String, isPropertyAccessor: Boolean) {
if (isPropertyAccessor) {
hashIdAcc = id
propertyAccessorIdHashAndDescription = PropertyAccessorIdHashAndDescription(id, description)
} else {
hashId = id
}
this.description = description
}
}
protected abstract fun accept(d: Declaration)
@@ -86,7 +88,7 @@ abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Dec
this.packageFqn = FqName.ROOT
this.classFqnSegments.clear()
this.hashId = null
this.hashIdAcc = null
this.propertyAccessorIdHashAndDescription = null
this.mask = 0L
this.overridden = null
this.description = null
@@ -125,7 +127,20 @@ abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Dec
buildContainerSignature(preservedContainer)
}
hashIdAcc == null -> {
propertyAccessorIdHashAndDescription != null -> {
val accessorSignature = IdSignature.CommonSignature(
packageFqName = packageFqName,
declarationFqName = classFqName,
id = propertyAccessorIdHashAndDescription!!.id,
mask = mask,
description = propertyAccessorIdHashAndDescription!!.description,
)
propertyAccessorIdHashAndDescription = null
classFqnSegments.run { removeAt(lastIndex) }
val propertySignature = build()
IdSignature.AccessorSignature(propertySignature, accessorSignature)
}
else -> {
IdSignature.CommonSignature(
packageFqName = packageFqName,
declarationFqName = classFqName,
@@ -134,19 +149,6 @@ abstract class IdSignatureBuilder<Declaration : Any, Mangler : KotlinMangler<Dec
description = description,
)
}
else -> {
val accessorSignature = IdSignature.CommonSignature(
packageFqName = packageFqName,
declarationFqName = classFqName,
id = hashIdAcc,
mask = mask,
description = description,
)
hashIdAcc = null
classFqnSegments.run { removeAt(lastIndex) }
val propertySignature = build()
IdSignature.AccessorSignature(propertySignature, accessorSignature)
}
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ final class classifiers.test/DataClass { // classifiers.test/DataClass|null[0]
open enum class classifiers.test/EnumClassWithEntryClasses : kotlin/Enum<classifiers.test/EnumClassWithEntryClasses> { // classifiers.test/EnumClassWithEntryClasses|null[0]
final val entries // classifiers.test/EnumClassWithEntryClasses.entries|#static{}entries[0]
final fun <get-entries>(): kotlin.enums/EnumEntries<classifiers.test/EnumClassWithEntryClasses> // classifiers.test/EnumClassWithEntryClasses.entries.<get-entries>|<get-entries>#static(){}[0]
open val overriddenProperty // classifiers.test/EnumClassWithEntryClasses.overriddenProperty|<get-overriddenProperty>(){}[0]
open val overriddenProperty // classifiers.test/EnumClassWithEntryClasses.overriddenProperty|{}overriddenProperty[0]
open fun <get-overriddenProperty>(): kotlin/String // classifiers.test/EnumClassWithEntryClasses.overriddenProperty.<get-overriddenProperty>|<get-overriddenProperty>(){}[0]
open fun overriddenFunction(): kotlin/String // classifiers.test/EnumClassWithEntryClasses.overriddenFunction|overriddenFunction(){}[0]
final fun valueOf(kotlin/String): classifiers.test/EnumClassWithEntryClasses // classifiers.test/EnumClassWithEntryClasses.valueOf|valueOf#static(kotlin.String){}[0]
@@ -0,0 +1,34 @@
// MODULE: kt64082_kt64085
class ConstHolder1 {
private fun local() {
println(CONST_VAL)
}
companion object {
const val CONST_VAL: String = ""
}
}
class ConstHolder2 {
companion object {
const val CONST_VAL: String = ""
}
}
class Reader {
private val properties: Named
init {
properties = NamedImpl()
properties.name
}
}
interface Named {
val name: String
}
class NamedImpl : Named {
override val name: String = ""
}
@@ -0,0 +1,32 @@
// Rendering settings:
// - Signature version: 1
// - Show manifest properties: false
// - Show declarations: true
// Library unique name: <kt64082_kt64085>
final class /ConstHolder1 { // /ConstHolder1|null[0]
constructor <init>() // /ConstHolder1.<init>|-5645683436151566731[0]
final object Companion { // /ConstHolder1.Companion|null[0]
final const val CONST_VAL // /ConstHolder1.Companion.CONST_VAL|-8347527175481482751[0]
final fun <get-CONST_VAL>(): kotlin/String // /ConstHolder1.Companion.CONST_VAL.<get-CONST_VAL>|-4753750709173816321[0]
}
}
final class /ConstHolder2 { // /ConstHolder2|null[0]
constructor <init>() // /ConstHolder2.<init>|-5645683436151566731[0]
final object Companion { // /ConstHolder2.Companion|null[0]
final const val CONST_VAL // /ConstHolder2.Companion.CONST_VAL|-8347527175481482751[0]
final fun <get-CONST_VAL>(): kotlin/String // /ConstHolder2.Companion.CONST_VAL.<get-CONST_VAL>|-4753750709173816321[0]
}
}
abstract interface /Named { // /Named|null[0]
abstract val name // /Named.name|4231860309499509769[0]
abstract fun <get-name>(): kotlin/String // /Named.name.<get-name>|5879344792307730109[0]
}
final class /NamedImpl : /Named { // /NamedImpl|null[0]
final val name // /NamedImpl.name|4231860309499509769[0]
final fun <get-name>(): kotlin/String // /NamedImpl.name.<get-name>|5879344792307730109[0]
constructor <init>() // /NamedImpl.<init>|-5645683436151566731[0]
}
final class /Reader { // /Reader|null[0]
constructor <init>() // /Reader.<init>|-5645683436151566731[0]
}
@@ -0,0 +1,32 @@
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: false
// - Show declarations: true
// Library unique name: <kt64082_kt64085>
final class /ConstHolder1 { // /ConstHolder1|null[0]
constructor <init>() // /ConstHolder1.<init>|<init>(){}[0]
final object Companion { // /ConstHolder1.Companion|null[0]
final const val CONST_VAL // /ConstHolder1.Companion.CONST_VAL|{}CONST_VAL[0]
final fun <get-CONST_VAL>(): kotlin/String // /ConstHolder1.Companion.CONST_VAL.<get-CONST_VAL>|<get-CONST_VAL>(){}[0]
}
}
final class /ConstHolder2 { // /ConstHolder2|null[0]
constructor <init>() // /ConstHolder2.<init>|<init>(){}[0]
final object Companion { // /ConstHolder2.Companion|null[0]
final const val CONST_VAL // /ConstHolder2.Companion.CONST_VAL|{}CONST_VAL[0]
final fun <get-CONST_VAL>(): kotlin/String // /ConstHolder2.Companion.CONST_VAL.<get-CONST_VAL>|<get-CONST_VAL>(){}[0]
}
}
abstract interface /Named { // /Named|null[0]
abstract val name // /Named.name|{}name[0]
abstract fun <get-name>(): kotlin/String // /Named.name.<get-name>|<get-name>(){}[0]
}
final class /NamedImpl : /Named { // /NamedImpl|null[0]
final val name // /NamedImpl.name|{}name[0]
final fun <get-name>(): kotlin/String // /NamedImpl.name.<get-name>|<get-name>(){}[0]
constructor <init>() // /NamedImpl.<init>|<init>(){}[0]
}
final class /Reader { // /Reader|null[0]
constructor <init>() // /Reader.<init>|<init>(){}[0]
}
@@ -97,6 +97,12 @@ public class ClassicJsLibraryAbiReaderTestGenerated extends AbstractClassicJsLib
runTest("compiler/testData/klib/dump-abi/content/inheritance.kt");
}
@Test
@TestMetadata("kt64082-kt64085.kt")
public void testKt64082_kt64085() throws Exception {
runTest("compiler/testData/klib/dump-abi/content/kt64082-kt64085.kt");
}
@Test
@TestMetadata("root_package.kt")
public void testRoot_package() throws Exception {
@@ -97,6 +97,12 @@ public class FirJsLibraryAbiReaderTestGenerated extends AbstractFirJsLibraryAbiR
runTest("compiler/testData/klib/dump-abi/content/inheritance.kt");
}
@Test
@TestMetadata("kt64082-kt64085.kt")
public void testKt64082_kt64085() throws Exception {
runTest("compiler/testData/klib/dump-abi/content/kt64082-kt64085.kt");
}
@Test
@TestMetadata("root_package.kt")
public void testRoot_package() throws Exception {
@@ -13,11 +13,11 @@ kotlin.collections/Collection.iterator|iterator(){}[0]
kotlin.collections/Collection|null[0]
kotlin.collections/Iterator|null[0]
kotlin.collections/List.size.<get-size>|<get-size>(){}[0]
kotlin.collections/List.size|<get-size>(){}[0]
kotlin.collections/List.size|{}size[0]
kotlin.collections/List|null[0]
kotlin.collections/Map.Entry|null[0]
kotlin.collections/Map.entries.<get-entries>|<get-entries>(){}[0]
kotlin.collections/Map.entries|<get-entries>(){}[0]
kotlin.collections/Map.entries|{}entries[0]
kotlin.collections/Map|null[0]
kotlin.collections/Set|null[0]
kotlin/Any.<init>|<init>(){}[0]
@@ -3,7 +3,7 @@ imported/test|test(){}[0]
// Imported signatures: 11
bar/publicVal.<get-publicVal>|<get-publicVal>(){}[0]
bar/publicVal|<get-publicVal>(){}[0]
bar/publicVal|{}publicVal[0]
foo/PublicClass.<init>|<init>(kotlin.Int){}[0]
foo/PublicClass|null[0]
foo/publicFun|publicFun(){}[0]
@@ -26,13 +26,13 @@ imported_from_cinterop.lib/Base.init|objc:init[100]
imported_from_cinterop.lib/Base.nonOverriddenFunction|objc:nonOverriddenFunction[100]
imported_from_cinterop.lib/Base.nonOverriddenProperty.<get-nonOverriddenProperty>|objc:nonOverriddenProperty#Accessor[100]
imported_from_cinterop.lib/Base.nonOverriddenProperty.<set-nonOverriddenProperty>|objc:setNonOverriddenProperty:#Accessor[100]
imported_from_cinterop.lib/Base.nonOverriddenProperty|objc:nonOverriddenProperty#Accessor[100]
imported_from_cinterop.lib/Base.nonOverriddenProperty|objc:nonOverriddenProperty[100]
imported_from_cinterop.lib/Base.nonOverriddenProperty|{}nonOverriddenProperty[100]
imported_from_cinterop.lib/Base.overriddenFunction|objc:overriddenFunction[100]
imported_from_cinterop.lib/Base.overriddenProperty.<get-overriddenProperty>|objc:overriddenProperty#Accessor[100]
imported_from_cinterop.lib/Base.overriddenProperty.<set-overriddenProperty>|objc:setOverriddenProperty:#Accessor[100]
imported_from_cinterop.lib/Base.overriddenProperty|objc:overriddenProperty#Accessor[100]
imported_from_cinterop.lib/Base.overriddenProperty|objc:overriddenProperty[100]
imported_from_cinterop.lib/Base.overriddenProperty|{}overriddenProperty[100]
imported_from_cinterop.lib/Base.setNonOverriddenProperty|objc:setNonOverriddenProperty:[100]
imported_from_cinterop.lib/Base.setOverriddenProperty|objc:setOverriddenProperty:[100]
imported_from_cinterop.lib/Base.toString|toString(){}[100]
@@ -101,6 +101,12 @@ public class FirNativeLibraryAbiReaderTest extends AbstractNativeLibraryAbiReade
runTest("compiler/testData/klib/dump-abi/content/inheritance.kt");
}
@Test
@TestMetadata("kt64082-kt64085.kt")
public void testKt64082_kt64085() throws Exception {
runTest("compiler/testData/klib/dump-abi/content/kt64082-kt64085.kt");
}
@Test
@TestMetadata("root_package.kt")
public void testRoot_package() throws Exception {
@@ -97,6 +97,12 @@ public class NativeLibraryAbiReaderTest extends AbstractNativeLibraryAbiReaderTe
runTest("compiler/testData/klib/dump-abi/content/inheritance.kt");
}
@Test
@TestMetadata("kt64082-kt64085.kt")
public void testKt64082_kt64085() throws Exception {
runTest("compiler/testData/klib/dump-abi/content/kt64082-kt64085.kt");
}
@Test
@TestMetadata("root_package.kt")
public void testRoot_package() throws Exception {