[Wasm, stdlib] extract Any::identityHashCode to workaround the bug in FunctionDescriptorFactory

A fix is on its way -- KT-MR-9426.
This commit is contained in:
Zalim Bashorov
2023-04-05 20:05:23 +02:00
parent 46459dfa60
commit 155eb9b77a
+9 -9
View File
@@ -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
}