[Wasm] Remove wasm_ref_cast and use wasm_ref_cast_null inside the compiler
This commit is contained in:
@@ -180,7 +180,7 @@ class WasmSymbols(
|
|||||||
val refIsNull = getInternalFunction("wasm_ref_is_null")
|
val refIsNull = getInternalFunction("wasm_ref_is_null")
|
||||||
val externRefIsNull = getInternalFunction("wasm_externref_is_null")
|
val externRefIsNull = getInternalFunction("wasm_externref_is_null")
|
||||||
val refTest = getInternalFunction("wasm_ref_test")
|
val refTest = getInternalFunction("wasm_ref_test")
|
||||||
val refCast = getInternalFunction("wasm_ref_cast")
|
val refCastNull = getInternalFunction("wasm_ref_cast_null")
|
||||||
val wasmArrayCopy = getInternalFunction("wasm_array_copy")
|
val wasmArrayCopy = getInternalFunction("wasm_array_copy")
|
||||||
val wasmArrayNewData0 = getInternalFunction("array_new_data0")
|
val wasmArrayNewData0 = getInternalFunction("array_new_data0")
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.expressions.*
|
|||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.wasm.ir.*
|
|
||||||
|
|
||||||
internal class WasmUsefulDeclarationProcessor(
|
internal class WasmUsefulDeclarationProcessor(
|
||||||
override val context: WasmBackendContext,
|
override val context: WasmBackendContext,
|
||||||
@@ -59,7 +58,7 @@ internal class WasmUsefulDeclarationProcessor(
|
|||||||
|
|
||||||
context.wasmSymbols.wasmClassId,
|
context.wasmSymbols.wasmClassId,
|
||||||
context.wasmSymbols.wasmInterfaceId,
|
context.wasmSymbols.wasmInterfaceId,
|
||||||
context.wasmSymbols.refCast,
|
context.wasmSymbols.refCastNull,
|
||||||
context.wasmSymbols.refTest,
|
context.wasmSymbols.refTest,
|
||||||
context.wasmSymbols.boxIntrinsic,
|
context.wasmSymbols.boxIntrinsic,
|
||||||
context.wasmSymbols.wasmArrayCopy -> {
|
context.wasmSymbols.wasmArrayCopy -> {
|
||||||
@@ -183,4 +182,4 @@ internal class WasmUsefulDeclarationProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isExported(declaration: IrDeclaration): Boolean = declaration.isJsExport()
|
override fun isExported(declaration: IrDeclaration): Boolean = declaration.isJsExport()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -392,7 +392,7 @@ class BodyGenerator(
|
|||||||
generateExpression(receiver)
|
generateExpression(receiver)
|
||||||
|
|
||||||
//TODO: check why it could be needed
|
//TODO: check why it could be needed
|
||||||
generateRefCast(receiver.type, klass.defaultType)
|
generateRefNullCast(receiver.type, klass.defaultType)
|
||||||
|
|
||||||
body.buildStructGet(context.referenceGcType(klass.symbol), WasmSymbol(0))
|
body.buildStructGet(context.referenceGcType(klass.symbol), WasmSymbol(0))
|
||||||
body.buildStructGet(context.referenceVTableGcType(klass.symbol), WasmSymbol(vfSlot))
|
body.buildStructGet(context.referenceVTableGcType(klass.symbol), WasmSymbol(vfSlot))
|
||||||
@@ -428,7 +428,7 @@ class BodyGenerator(
|
|||||||
body.buildGetUnit()
|
body.buildGetUnit()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateRefCast(fromType: IrType, toType: IrType) {
|
private fun generateRefNullCast(fromType: IrType, toType: IrType) {
|
||||||
if (!isDownCastAlwaysSuccessInRuntime(fromType, toType)) {
|
if (!isDownCastAlwaysSuccessInRuntime(fromType, toType)) {
|
||||||
body.buildRefCastNullStatic(
|
body.buildRefCastNullStatic(
|
||||||
toType = context.referenceGcType(toType.getRuntimeClass(irBuiltIns).symbol)
|
toType = context.referenceGcType(toType.getRuntimeClass(irBuiltIns).symbol)
|
||||||
@@ -507,8 +507,8 @@ class BodyGenerator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wasmSymbols.refCast -> {
|
wasmSymbols.refCastNull -> {
|
||||||
generateRefCast(
|
generateRefNullCast(
|
||||||
fromType = call.getValueArgument(0)!!.type,
|
fromType = call.getValueArgument(0)!!.type,
|
||||||
toType = call.getTypeArgument(0)!!
|
toType = call.getTypeArgument(0)!!
|
||||||
)
|
)
|
||||||
@@ -540,7 +540,7 @@ class BodyGenerator(
|
|||||||
val klass: IrClass = backendContext.inlineClassesUtils.getInlinedClass(toType)!!
|
val klass: IrClass = backendContext.inlineClassesUtils.getInlinedClass(toType)!!
|
||||||
val field = getInlineClassBackingField(klass)
|
val field = getInlineClassBackingField(klass)
|
||||||
|
|
||||||
generateRefCast(fromType, toType)
|
generateRefNullCast(fromType, toType)
|
||||||
generateInstanceFieldAccess(field)
|
generateInstanceFieldAccess(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -722,7 +722,7 @@ class BodyGenerator(
|
|||||||
|
|
||||||
// REF -> REF -> REF_CAST
|
// REF -> REF -> REF_CAST
|
||||||
if (!expectedIsPrimitive) {
|
if (!expectedIsPrimitive) {
|
||||||
generateRefCast(actualTypeErased, expectedTypeErased)
|
generateRefNullCast(actualTypeErased, expectedTypeErased)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
@@ -674,7 +673,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
|||||||
) : InteropTypeAdapter {
|
) : InteropTypeAdapter {
|
||||||
override val fromType: IrType = context.wasmSymbols.wasmDataRefType
|
override val fromType: IrType = context.wasmSymbols.wasmDataRefType
|
||||||
override fun adapt(expression: IrExpression, builder: IrBuilderWithScope): IrExpression {
|
override fun adapt(expression: IrExpression, builder: IrBuilderWithScope): IrExpression {
|
||||||
val call = builder.irCall(context.wasmSymbols.refCast)
|
val call = builder.irCall(context.wasmSymbols.refCastNull)
|
||||||
call.putValueArgument(0, expression)
|
call.putValueArgument(0, expression)
|
||||||
call.putTypeArgument(0, toType)
|
call.putTypeArgument(0, toType)
|
||||||
return call
|
return call
|
||||||
@@ -772,4 +771,4 @@ class JsInteropFunctionCallsLowering(val context: WasmBackendContext) : BodyLowe
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -242,7 +242,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.irCall(symbols.refCast, type = toType).apply {
|
return builder.irCall(symbols.refCastNull, type = toType).apply {
|
||||||
putTypeArgument(0, toType)
|
putTypeArgument(0, toType)
|
||||||
putValueArgument(0, value)
|
putValueArgument(0, value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,12 @@ import kotlin.wasm.internal.ExternalInterfaceType
|
|||||||
internal fun wasm_unreachable(): Nothing =
|
internal fun wasm_unreachable(): Nothing =
|
||||||
implementedAsIntrinsic
|
implementedAsIntrinsic
|
||||||
|
|
||||||
internal fun <To> wasm_ref_cast(a: Any?): To =
|
|
||||||
implementedAsIntrinsic
|
|
||||||
|
|
||||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||||
@WasmOp(WasmOp.REF_CAST_NULL)
|
|
||||||
internal fun <reified To> wasm_ref_cast_null(a: Any?): To =
|
internal fun <reified To> wasm_ref_cast_null(a: Any?): To =
|
||||||
implementedAsIntrinsic
|
implementedAsIntrinsic
|
||||||
|
|
||||||
internal fun <To> wasm_ref_test(a: Any?): Boolean =
|
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||||
|
internal fun <reified To> wasm_ref_test(a: Any?): Boolean =
|
||||||
implementedAsIntrinsic
|
implementedAsIntrinsic
|
||||||
|
|
||||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||||
|
|||||||
Reference in New Issue
Block a user