Revert "[Wasm] Support lazy associated object initialisation"

This reverts commit 552ee1ee38.
This commit is contained in:
Anastasiia Spaseeva
2024-01-25 14:11:56 +01:00
parent 91002eacda
commit 945f602b91
12 changed files with 58 additions and 140 deletions
@@ -8,16 +8,35 @@ package kotlin.wasm.internal
import kotlin.reflect.wasm.internal.KClassImpl
import kotlin.reflect.KClass
internal var associatedObjects: Map<ULong, Any>? = null
@PublishedApi
internal fun findAssociatedObject(klass: KClass<*>, key: Int): Any? {
val klassId = (klass as? KClassImpl<*>)?.typeData?.typeId ?: return null
return tryGetAssociatedObject(klassId, key)
val map = associatedObjects ?: run {
val newMap: MutableMap<ULong, Any> = mutableMapOf()
initAssociatedObjects(newMap)
associatedObjects = newMap
newMap
}
return map[packIntoULong(klassId, key)]
}
internal fun tryGetAssociatedObject(
@Suppress("UNUSED_PARAMETER") klassId: Int,
@Suppress("UNUSED_PARAMETER") keyId: Int,
): Any? {
internal fun packIntoULong(a: Int, b: Int): ULong =
(a.toUInt().toULong() shl Int.SIZE_BITS) or b.toUInt().toULong()
internal fun addAssociatedObject(
mapToInit: MutableMap<ULong, Any>,
klassId: Int,
keyId: Int,
instance: Any
) {
mapToInit[packIntoULong(klassId, keyId)] = instance
}
internal fun initAssociatedObjects(@Suppress("UNUSED_PARAMETER") mapToInit: MutableMap<ULong, Any>) {
// Init implicitly with AssociatedObjectsLowering
return null
// addAssociatedObject(mapToInit, ...)
}