From b472f9c35e0c5896d2d41f1a63bf45849dcf037e Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 19 Dec 2019 16:46:38 +0300 Subject: [PATCH] Provide publicly visible identity hash code. (#3690) * Provide publicly visible identity hash code. * Review feedback. --- .../konan/platform/NativePlatformAnalyzerServices.kt | 6 ++++++ runtime/src/main/kotlin/kotlin/Any.kt | 5 +---- runtime/src/main/kotlin/kotlin/native/Runtime.kt | 9 ++++++++- .../src/main/kotlin/kotlin/native/concurrent/Internal.kt | 1 + .../main/kotlin/kotlin/native/internal/RuntimeUtils.kt | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/extracted/konan.serializer/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformAnalyzerServices.kt b/extracted/konan.serializer/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformAnalyzerServices.kt index 201bf9ebf89..7387a934e46 100644 --- a/extracted/konan.serializer/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformAnalyzerServices.kt +++ b/extracted/konan.serializer/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformAnalyzerServices.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.resolve.konan.platform +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.ImportPath import org.jetbrains.kotlin.resolve.PlatformConfigurator import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices @@ -16,4 +17,9 @@ object NativePlatformAnalyzerServices : PlatformDependentAnalyzerServices() { } override val platformConfigurator: PlatformConfigurator = KonanPlatformConfigurator + + override val excludedImports: List = + listOf("identityHashCode").map { + FqName("kotlin.native.$it") + } } diff --git a/runtime/src/main/kotlin/kotlin/Any.kt b/runtime/src/main/kotlin/kotlin/Any.kt index 5af7b7a9941..c3b4b927e02 100644 --- a/runtime/src/main/kotlin/kotlin/Any.kt +++ b/runtime/src/main/kotlin/kotlin/Any.kt @@ -5,6 +5,7 @@ package kotlin +import kotlin.native.identityHashCode import kotlin.native.internal.ExportTypeInfo /** @@ -47,7 +48,3 @@ public open class Any { return "$className@$hashCodeStr" } } - -@PublishedApi -@SymbolName("Kotlin_Any_hashCode") -external internal fun Any.identityHashCode(): Int diff --git a/runtime/src/main/kotlin/kotlin/native/Runtime.kt b/runtime/src/main/kotlin/kotlin/native/Runtime.kt index 0b4beb81fe9..8336dec2af4 100644 --- a/runtime/src/main/kotlin/kotlin/native/Runtime.kt +++ b/runtime/src/main/kotlin/kotlin/native/Runtime.kt @@ -51,4 +51,11 @@ public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): Report } @SymbolName("Kotlin_setUnhandledExceptionHook") -external private fun setUnhandledExceptionHook0(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? \ No newline at end of file +external private fun setUnhandledExceptionHook0(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? + +/** + * Compute stable wrt potential object relocations by the memory manager identity hash code. + * @return 0 for `null` object, identity hash code otherwise. + */ +@SymbolName("Kotlin_Any_hashCode") +public external fun Any?.identityHashCode(): Int \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt index 5f715c9a0af..fb29e3c5233 100644 --- a/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt @@ -6,6 +6,7 @@ package kotlin.native.concurrent import kotlin.native.internal.ExportForCppRuntime +import kotlin.native.identityHashCode import kotlin.reflect.KClass import kotlinx.cinterop.* diff --git a/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt b/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt index 6f091136107..6f4b894ff11 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt @@ -205,4 +205,4 @@ internal fun listOfInternal(vararg elements: T): List { @PublishedApi @SymbolName("OnUnhandledException") -external internal fun OnUnhandledException(throwable: Throwable) \ No newline at end of file +external internal fun OnUnhandledException(throwable: Throwable)