From 795ee9f26d6eba3eca7bc2c4321006ebc022c690 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Mon, 19 Feb 2024 23:00:08 +0100 Subject: [PATCH] [KLIB tool] "dump-metadata-signatures": exclude fake overrides There are few reasons why fake overrides should not be printed: 1. Fake overrides are not serialized in metadata. So, if one will run "dump-metadata" they won't see there any fake overrides. Neither their signatures. It would be inconsistent if "dump-metadata-signatures" command would show them. 2. In order to properly build fake overrides the KLIB tool needs the dependency library with the super class or interface, which is not available unless this is stdlib or one of the built-in Kotlin/Native platform libraries. KLIB tool does not support any reasonable means for passing dependencies through CLI arguments. If such possibility is added in the future, it would be the right time to support printing fake overrides (probably under a separate CLI option). ^KT-62340 --- .../jetbrains/kotlin/cli/klib/SignaturePrinter.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/SignaturePrinter.kt b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/SignaturePrinter.kt index e4e62765b36..958a49fe21d 100644 --- a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/SignaturePrinter.kt +++ b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/SignaturePrinter.kt @@ -36,11 +36,11 @@ internal class SignaturePrinter( } override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit) { - extractSignatureFromDeclaration(descriptor) + extractSignatureFromCallableMember(descriptor) } override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit) { - extractSignatureFromDeclaration(descriptor) { + extractSignatureFromCallableMember(descriptor) { descriptor.getter?.let(::extractSignatureFromDeclaration) descriptor.setter?.let(::extractSignatureFromDeclaration) } @@ -54,6 +54,13 @@ internal class SignaturePrinter( extractSignatureFromDeclaration(descriptor) } + private inline fun extractSignatureFromCallableMember(descriptor: CallableMemberDescriptor, continuation: () -> Unit = {}) { + // Skip fake overrides. + if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) return + + extractSignatureFromDeclaration(descriptor, continuation) + } + private inline fun extractSignatureFromDeclaration(descriptor: DeclarationDescriptorWithVisibility, continuation: () -> Unit = {}) { val isPrivate = when (descriptor.visibility) { DescriptorVisibilities.PUBLIC, @@ -70,3 +77,4 @@ internal class SignaturePrinter( } } } +