From 155eb9b77ad7a87d582fd80534ec400bc7f812b0 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Wed, 5 Apr 2023 20:05:23 +0200 Subject: [PATCH] [Wasm, stdlib] extract Any::identityHashCode to workaround the bug in FunctionDescriptorFactory A fix is on its way -- KT-MR-9426. --- libraries/stdlib/wasm/builtins/kotlin/Any.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/stdlib/wasm/builtins/kotlin/Any.kt b/libraries/stdlib/wasm/builtins/kotlin/Any.kt index ddce260de45..c7568742f60 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Any.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Any.kt @@ -44,15 +44,6 @@ public open class Any @WasmPrimitiveConstructor constructor() { return identityHashCode() } - // Don't use outside, otherwise it could break classes reusing `_hashCode` field, like String. - // Don't inline it into usages, specifically to `hashCode`. - // It was extracted to remove `toString`'s dependency on `hashCode`, which improves output size when DCE is involved. - private fun identityHashCode(): Int { - if (_hashCode == 0) - _hashCode = Random.nextInt(1, Int.MAX_VALUE) - return _hashCode - } - /** * Returns a string representation of the object. */ @@ -64,3 +55,12 @@ public open class Any @WasmPrimitiveConstructor constructor() { return "$qualifiedName@${identityHashCode()}" } } + +// Don't use outside, otherwise it could break classes reusing `_hashCode` field, like String. +// Don't inline it into usages, specifically to `hashCode`. +// It was extracted to remove `toString`'s dependency on `hashCode`, which improves output size when DCE is involved. +private fun Any.identityHashCode(): Int { + if (_hashCode == 0) + _hashCode = Random.nextInt(1, Int.MAX_VALUE) + return _hashCode +}