[Wasm] Add fast path for null in externRefToAny
- Introduce new intrinsics `wasm_ref_cast_null` & `wasm_ref_test_null`. - Support getting type for immediate from generic argument. - Remove redundant null check in `tryGetOrSetExternrefBox`.
This commit is contained in:
@@ -141,13 +141,13 @@ internal fun externRefToAny(ref: ExternalInterfaceType): Any? {
|
||||
// TODO rewrite it so to get something like:
|
||||
// block {
|
||||
// refAsAnyref
|
||||
// br_on_cast_fail 0 $kotlin.Any
|
||||
// br_on_cast_fail null 0 $kotlin.Any
|
||||
// return
|
||||
// }
|
||||
// If ref is an instance of kotlin class -- return it casted to Any
|
||||
val refAsAnyref = ref.externAsWasmAnyref()
|
||||
if (wasm_ref_test<Any>(refAsAnyref)) {
|
||||
return wasm_ref_cast<Any>(refAsAnyref)
|
||||
if (wasm_ref_test_null<Any>(refAsAnyref)) {
|
||||
return wasm_ref_cast_null<Any>(refAsAnyref)
|
||||
}
|
||||
|
||||
// If we have Null in notNullRef -- return null
|
||||
|
||||
@@ -22,9 +22,19 @@ internal fun wasm_unreachable(): Nothing =
|
||||
internal fun <To> wasm_ref_cast(a: Any?): To =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||
@WasmOp(WasmOp.REF_CAST_NULL)
|
||||
internal fun <reified To> wasm_ref_cast_null(a: Any?): To =
|
||||
implementedAsIntrinsic
|
||||
|
||||
internal fun <To> wasm_ref_test(a: Any?): Boolean =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||
@WasmOp(WasmOp.REF_TEST_NULL)
|
||||
internal fun <reified To> wasm_ref_test_null(a: Any?): Boolean =
|
||||
implementedAsIntrinsic
|
||||
|
||||
internal fun <T> wasm_array_copy(destination: T, destinationIndex: Int, source: T, sourceIndex: Int, length: Int): Unit =
|
||||
implementedAsIntrinsic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user