From f26e470e8026f803b1bd00685770733c8117b117 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Fri, 9 Feb 2024 19:26:27 +0100 Subject: [PATCH] [klib] Don't show signature clash diagnostics for local declarations For some reason type parameters end up in `GlobdalDeclarationTable`, and thus we tracked them in `IdSignatureClashDetector`, which wasn't right and confused the diagnostic renderer that uses `org.jetbrains.kotlin.resolve.MemberComparator` for sorting the declarations to display in diagnostics. That comparator doesn't know jow to work with type parameters. Besides, type parameters, like many other types of declarations, are not considered public wrt KLIB ABI, so there's no need to show CONFLICTING_KLIB_SIGNATURES_ERROR for them. ^KT-65723 Fixed --- .../common/serialization/DeclarationTable.kt | 2 +- .../signatureClash.diag.txt | 44 +++++++++++-------- .../klibSerializationTests/signatureClash.kt | 25 +++++++++-- .../signatureClash_MPP.diag.txt | 8 ---- .../signatureClash_MPP.kt | 4 +- .../SignatureClashDiagnostics/output.txt | 10 ----- 6 files changed, 50 insertions(+), 43 deletions(-) diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/DeclarationTable.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/DeclarationTable.kt index e591faa5737..c527f44779b 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/DeclarationTable.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/DeclarationTable.kt @@ -37,7 +37,7 @@ abstract class GlobalDeclarationTable(private val mangler: KotlinMangler.IrMangl return table.getOrPut(declaration) { publicIdSignatureComputer.composePublicIdSignature(declaration, compatibleMode) }.also { - if (recordInSignatureClashDetector) { + if (recordInSignatureClashDetector && it.isPubliclyVisible && !it.isLocal) { clashDetector.trackDeclaration(declaration, it) } } diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClash.diag.txt b/compiler/testData/diagnostics/klibSerializationTests/signatureClash.diag.txt index ce2af6b97c3..927825e554d 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClash.diag.txt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClash.diag.txt @@ -8,10 +8,6 @@ var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics -/foo.kt:17:1: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]): - var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics - var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics - /foo.kt:17:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics @@ -21,10 +17,6 @@ val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics -/foo.kt:19:26: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myDelegated|{}myDelegated[0] <- Local[|FIELD PROPERTY_DELEGATE name:myDelegated$delegate type:kotlin.Lazy visibility:private [final,static]] ]): - val `myDelegated$delegate`: kotlin.Lazy defined in com.example.klib.serialization.diagnostics - val `myDelegated$delegate`: kotlin.Lazy defined in com.example.klib.serialization.diagnostics - /foo.kt:19:26: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics @@ -44,10 +36,6 @@ var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics -/main.kt:29:1: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]): - var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics - var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics - /main.kt:29:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics @@ -67,18 +55,38 @@ val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics -/main.kt:37:25: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myDelegated|{}myDelegated[0] <- Local[|FIELD PROPERTY_DELEGATE name:myDelegated$delegate type:kotlin.Lazy visibility:private [final,static]] ]): - val `myDelegated$delegate`: kotlin.Lazy defined in com.example.klib.serialization.diagnostics - val `myDelegated$delegate`: kotlin.Lazy defined in com.example.klib.serialization.diagnostics - /main.kt:37:25: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics -/main.kt:50:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]): +/main.kt:43:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.parameterized|parameterized(0:0){0§}[0]): + fun parameterized(a: T): T defined in com.example.klib.serialization.diagnostics.A + fun parameterized(a: T): kotlin.Unit defined in com.example.klib.serialization.diagnostics.A + +/main.kt:46:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.parameterized|parameterized(0:0){0§}[0]): + fun parameterized(a: T): T defined in com.example.klib.serialization.diagnostics.A + fun parameterized(a: T): kotlin.Unit defined in com.example.klib.serialization.diagnostics.A + +/main.kt:48:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.privateMethod|privateMethod(){}[0]): + fun privateMethod(): kotlin.Int defined in com.example.klib.serialization.diagnostics.A + fun privateMethod(): kotlin.Long defined in com.example.klib.serialization.diagnostics.A + +/main.kt:51:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.privateMethod|privateMethod(){}[0]): + fun privateMethod(): kotlin.Int defined in com.example.klib.serialization.diagnostics.A + fun privateMethod(): kotlin.Long defined in com.example.klib.serialization.diagnostics.A + +/main.kt:54:1: error: Platform declaration clash: The following functions have the same IR signature ([ File '/main.kt' <- com.example.klib.serialization.diagnostics/privateTopLevelFunction|privateTopLevelFunction(){}[0] ]): + fun privateTopLevelFunction(): kotlin.Int defined in com.example.klib.serialization.diagnostics + fun privateTopLevelFunction(): kotlin.Long defined in com.example.klib.serialization.diagnostics + +/main.kt:57:1: error: Platform declaration clash: The following functions have the same IR signature ([ File '/main.kt' <- com.example.klib.serialization.diagnostics/privateTopLevelFunction|privateTopLevelFunction(){}[0] ]): + fun privateTopLevelFunction(): kotlin.Int defined in com.example.klib.serialization.diagnostics + fun privateTopLevelFunction(): kotlin.Long defined in com.example.klib.serialization.diagnostics + +/main.kt:67:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]): fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics -/main.kt:53:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]): +/main.kt:70:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]): fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClash.kt b/compiler/testData/diagnostics/klibSerializationTests/signatureClash.kt index 688689996a0..387b52bc7d7 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClash.kt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClash.kt @@ -14,9 +14,9 @@ package com.example.klib.serialization.diagnostics @Deprecated("", level = DeprecationLevel.HIDDEN) fun foo(): Long = 0L -var myVal: Long = 0L +var myVal: Long = 0L -val myDelegated: Long by lazy { 0L } +val myDelegated: Long by lazy { 0L } // FILE: main.kt package com.example.klib.serialization.diagnostics @@ -26,7 +26,7 @@ fun foo(): String = "" fun foo(): Int = 0 -@Deprecated("", level = DeprecationLevel.HIDDEN) +@Deprecated("", level = DeprecationLevel.HIDDEN) var myVal: Int = 0 @Deprecated("", level = DeprecationLevel.HIDDEN) @@ -34,11 +34,28 @@ val myVal: String get() = "" @Deprecated("", level = DeprecationLevel.HIDDEN) -val myDelegated: Int by lazy { 1 } +val myDelegated: Int by lazy { 1 } @Deprecated("This function moved to the 'lib' module", level = DeprecationLevel.HIDDEN) fun movedToLib() {} +class A { + @Deprecated(message = "", level = DeprecationLevel.HIDDEN) + fun parameterized(a: T): T = a + + fun parameterized(a: T) {} + + @Deprecated(message = "", level = DeprecationLevel.HIDDEN) + private fun privateMethod(): Int = 0 + + private fun privateMethod(): Long = 0L +} + +@Deprecated(message = "", level = DeprecationLevel.HIDDEN) +private fun privateTopLevelFunction(): Int = 0 + +private fun privateTopLevelFunction(): Long = 0L + fun main() { foo() movedToLib() diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.diag.txt b/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.diag.txt index f280f0041d1..7785dbae3e2 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.diag.txt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.diag.txt @@ -11,10 +11,6 @@ Module: common val param: kotlin.Int defined in root package val param: kotlin.Int defined in root package -/common.kt:13:1: error: Platform declaration clash: The following fields have the same IR signature ([ /param|{}param[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:param type:kotlin.Int visibility:private [final,static]] ]): - val param: kotlin.Int defined in root package - val param: kotlin.Int defined in root package - /common.kt:13:1: error: Platform declaration clash: The following functions have the same IR signature (/param.|(){}[0]): fun ``(): kotlin.Int defined in root package fun ``(): kotlin.Int defined in root package @@ -31,10 +27,6 @@ Module: platform val param: kotlin.Int defined in root package val param: kotlin.Int defined in root package -/platform.kt:24:1: error: Platform declaration clash: The following fields have the same IR signature ([ /param|{}param[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:param type:kotlin.Int visibility:private [final,static]] ]): - val param: kotlin.Int defined in root package - val param: kotlin.Int defined in root package - /platform.kt:24:1: error: Platform declaration clash: The following functions have the same IR signature (/param.|(){}[0]): fun ``(): kotlin.Int defined in root package fun ``(): kotlin.Int defined in root package diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.kt b/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.kt index cc0c068406d..b1903f753c5 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.kt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClash_MPP.kt @@ -10,7 +10,7 @@ expect class A fun bar(x: A): Int = 2 // NOTE: This must be REDECLARATION, see KT-59898 -val param = 0 +val param = 0 // MODULE: platform()()(common) // FILE: platform.kt @@ -21,4 +21,4 @@ actual typealias A = B fun bar(x: B): Int = 3 // NOTE: This must be REDECLARATION, see KT-59898 -val param = 0 +val param = 0 diff --git a/native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/output.txt b/native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/output.txt index 8f745865b0b..1f21af6ae23 100644 --- a/native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/output.txt +++ b/native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/output.txt @@ -14,11 +14,6 @@ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10 var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics var myVal: Long = 0L ^^^^^^^^^^^^^^^^^^^^ -native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10:1: error: platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]): - var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics - var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics -var myVal: Long = 0L -^^^^^^^^^^^^^^^^^^^^ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10:1: error: platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics @@ -31,11 +26,6 @@ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15 var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics @Deprecated("", level = DeprecationLevel.HIDDEN) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15:1: error: platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]): - var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics - var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics -@Deprecated("", level = DeprecationLevel.HIDDEN) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15:1: error: platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.|(){}[0]): fun ``(): kotlin.Int defined in com.example.klib.serialization.diagnostics fun ``(): kotlin.Long defined in com.example.klib.serialization.diagnostics