[Wasm] Rename dateref to structref
This commit is contained in:
committed by
Space Team
parent
1e0be4e0af
commit
1749bafc30
@@ -289,8 +289,8 @@ class WasmSymbols(
|
||||
}
|
||||
}
|
||||
|
||||
private val wasmDataRefClass = getIrClass(FqName("kotlin.wasm.internal.reftypes.dataref"))
|
||||
val wasmDataRefType by lazy { wasmDataRefClass.defaultType }
|
||||
private val wasmStructRefClass = getIrClass(FqName("kotlin.wasm.internal.reftypes.structref"))
|
||||
val wasmStructRefType by lazy { wasmStructRefClass.defaultType }
|
||||
|
||||
val wasmAnyRefClass = getIrClass(FqName("kotlin.wasm.internal.reftypes.anyref"))
|
||||
|
||||
|
||||
+2
-2
@@ -314,7 +314,7 @@ class BodyGenerator(
|
||||
if (klassSymbol.owner.hasInterfaceSuperClass()) {
|
||||
body.buildGetGlobal(context.referenceGlobalClassITable(klassSymbol), location)
|
||||
} else {
|
||||
body.buildRefNull(WasmHeapType.Simple.Data, location)
|
||||
body.buildRefNull(WasmHeapType.Simple.Struct, location)
|
||||
}
|
||||
|
||||
body.buildConstI32Symbol(context.referenceTypeId(klassSymbol), location)
|
||||
@@ -543,7 +543,7 @@ class BodyGenerator(
|
||||
val parameterLocal = functionContext.referenceLocal(SyntheticLocalType.IS_INTERFACE_PARAMETER)
|
||||
body.buildSetLocal(parameterLocal, location)
|
||||
body.buildBlock("isInterface", WasmI32) { outerLabel ->
|
||||
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
|
||||
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Struct)) { innerLabel ->
|
||||
body.buildGetLocal(parameterLocal, location)
|
||||
body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1), location)
|
||||
|
||||
|
||||
+1
-1
@@ -364,7 +364,7 @@ class DeclarationGenerator(
|
||||
createClassITable(metadata)
|
||||
|
||||
val vtableRefGcType = WasmRefType(WasmHeapType.Type(context.referenceVTableGcType(symbol)))
|
||||
val classITableRefGcType = WasmRefNullType(WasmHeapType.Simple.Data)
|
||||
val classITableRefGcType = WasmRefNullType(WasmHeapType.Simple.Struct)
|
||||
val fields = mutableListOf<WasmStructFieldDeclaration>()
|
||||
fields.add(WasmStructFieldDeclaration("vtable", vtableRefGcType, false))
|
||||
fields.add(WasmStructFieldDeclaration("itable", classITableRefGcType, false))
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ class WasmTypeTransformer(
|
||||
when (val name = klass.name.identifier) {
|
||||
"anyref" -> WasmAnyRef
|
||||
"eqref" -> WasmEqRef
|
||||
"dataref" -> WasmRefNullType(WasmHeapType.Simple.Data)
|
||||
"structref" -> WasmRefNullType(WasmHeapType.Simple.Struct)
|
||||
"i31ref" -> WasmI31Ref
|
||||
"funcref" -> WasmRefNullType(WasmHeapType.Simple.Func)
|
||||
else -> error("Unknown reference type $name")
|
||||
|
||||
+9
-9
@@ -282,7 +282,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
// Thus, we export helper "caller" method that JavaScript will use to call kotlin closures:
|
||||
//
|
||||
// @JsExport
|
||||
// fun __callFunction_<signatureString>(f: dataref, p1: JsType1, p2: JsType2, ...): JsTypeRes {
|
||||
// fun __callFunction_<signatureString>(f: structref, p1: JsType1, p2: JsType2, ...): JsTypeRes {
|
||||
// return adapt(
|
||||
// cast<FunctionN>(f).invoke(
|
||||
// adapt(p1),
|
||||
@@ -302,7 +302,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
// @JsFun("""(f) => {
|
||||
// (p1, p2, ...) => <wasm-exports>.__callFunction_<signatureString>(f, p1, p2, ...)
|
||||
// }""")
|
||||
// external fun __convertKotlinClosureToJsClosure_<signatureString>(f: dataref): ExternalRef
|
||||
// external fun __convertKotlinClosureToJsClosure_<signatureString>(f: structref): ExternalRef
|
||||
//
|
||||
val kotlinToJsClosureConvertor = context.kotlinClosureToJsConverters.getOrPut(functionTypeInfo.signatureString) {
|
||||
createKotlinToJsClosureConvertor(functionTypeInfo)
|
||||
@@ -436,7 +436,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
result.parent = currentParent
|
||||
result.addValueParameter {
|
||||
name = Name.identifier("f")
|
||||
type = context.wasmSymbols.wasmDataRefType
|
||||
type = context.wasmSymbols.wasmStructRefType
|
||||
}
|
||||
var count = 0
|
||||
info.adaptedParameterTypes.forEach { type ->
|
||||
@@ -476,7 +476,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
result.parent = currentParent
|
||||
result.addValueParameter {
|
||||
name = Name.identifier("f")
|
||||
type = context.wasmSymbols.wasmDataRefType
|
||||
type = context.wasmSymbols.wasmStructRefType
|
||||
}
|
||||
val builder = context.createIrBuilder(result.symbol)
|
||||
// TODO: Cache created JS closures
|
||||
@@ -722,24 +722,24 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
}
|
||||
|
||||
/**
|
||||
* Current V8 Wasm GC mandates dataref type instead of structs and arrays
|
||||
* Current V8 Wasm GC mandates structref type instead of structs and arrays
|
||||
*/
|
||||
inner class SendKotlinObjectToJsAdapter(
|
||||
override val fromType: IrType
|
||||
) : InteropTypeAdapter {
|
||||
override val toType: IrType = context.wasmSymbols.wasmDataRefType
|
||||
override val toType: IrType = context.wasmSymbols.wasmStructRefType
|
||||
override fun adapt(expression: IrExpression, builder: IrBuilderWithScope): IrExpression {
|
||||
return builder.irReinterpretCast(expression, toType)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current V8 Wasm GC mandates dataref type instead of structs and arrays
|
||||
* Current V8 Wasm GC mandates structref type instead of structs and arrays
|
||||
*/
|
||||
inner class ReceivingKotlinObjectFromJsAdapter(
|
||||
override val toType: IrType
|
||||
) : InteropTypeAdapter {
|
||||
override val fromType: IrType = context.wasmSymbols.wasmDataRefType
|
||||
override val fromType: IrType = context.wasmSymbols.wasmStructRefType
|
||||
override fun adapt(expression: IrExpression, builder: IrBuilderWithScope): IrExpression {
|
||||
val call = builder.irCall(context.wasmSymbols.refCastNull)
|
||||
call.putValueArgument(0, expression)
|
||||
@@ -749,7 +749,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
||||
}
|
||||
|
||||
/**
|
||||
* Current V8 Wasm GC mandates dataref type instead of structs and arrays
|
||||
* Current V8 Wasm GC mandates structref type instead of structs and arrays
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,23 +43,23 @@ fun testExterRef() {
|
||||
check(null2ExternRef() == null)
|
||||
}
|
||||
|
||||
class DataRefImpl
|
||||
typealias DataRef = JsReference<DataRefImpl>
|
||||
class StructRefImpl
|
||||
typealias StructRef = JsReference<StructRefImpl>
|
||||
|
||||
fun notNullDataRef(x: DataRef): DataRef = js("x")
|
||||
fun notNullStructRef(x: StructRef): StructRef = js("x")
|
||||
|
||||
fun notNull2DataRef(x: DataRef): DataRef = js("null")
|
||||
fun notNull2StructRef(x: StructRef): StructRef = js("null")
|
||||
|
||||
fun nullDataRef(x: DataRef): DataRef? = js("x")
|
||||
fun nullStructRef(x: StructRef): StructRef? = js("x")
|
||||
|
||||
fun null2DataRef(x: DataRef): DataRef? = js("null")
|
||||
fun null2StructRef(x: StructRef): StructRef? = js("null")
|
||||
|
||||
fun testDataRef() {
|
||||
val dataRef = DataRefImpl().toJsReference()
|
||||
check(notNullDataRef(dataRef) == dataRef)
|
||||
checkNPE { notNull2DataRef(dataRef) }
|
||||
check (nullDataRef(dataRef) == dataRef)
|
||||
check (null2DataRef(dataRef) == null)
|
||||
fun testStructRef() {
|
||||
val structRef = StructRefImpl().toJsReference()
|
||||
check(notNullStructRef(structRef) == structRef)
|
||||
checkNPE { notNull2StructRef(structRef) }
|
||||
check (nullStructRef(structRef) == structRef)
|
||||
check (null2StructRef(structRef) == null)
|
||||
}
|
||||
|
||||
fun notNullInt(): Int = js("123")
|
||||
@@ -125,7 +125,7 @@ fun testFloat() {
|
||||
fun box(): String {
|
||||
testString()
|
||||
testExterRef()
|
||||
testDataRef()
|
||||
testStructRef()
|
||||
testInt()
|
||||
testBoolean()
|
||||
testShort()
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
|
||||
package kotlin.wasm.internal
|
||||
|
||||
import kotlin.wasm.internal.reftypes.anyref
|
||||
import kotlin.wasm.internal.reftypes.dataref
|
||||
import kotlin.wasm.internal.reftypes.funcref
|
||||
import kotlin.wasm.internal.reftypes.i31ref
|
||||
import kotlin.wasm.internal.ExternalInterfaceType
|
||||
|
||||
@WasmOp(WasmOp.UNREACHABLE)
|
||||
|
||||
@@ -21,6 +21,6 @@ import kotlin.wasm.internal.*
|
||||
|
||||
internal interface anyref
|
||||
internal interface eqref : anyref
|
||||
internal interface dataref : eqref
|
||||
internal interface structref : eqref
|
||||
internal interface i31ref : eqref
|
||||
internal interface funcref : anyref
|
||||
@@ -35,7 +35,7 @@ data class WasmRefType(val heapType: WasmHeapType) : WasmType("ref", -0x15)
|
||||
object WasmI31Ref : WasmType("i31ref", -0x16)
|
||||
|
||||
@Suppress("unused")
|
||||
object WasmDataRef : WasmType("dataref", -0x19)
|
||||
object WasmStructRef : WasmType("structref", -0x19)
|
||||
|
||||
sealed class WasmHeapType {
|
||||
data class Type(val type: WasmSymbolReadOnly<WasmTypeDeclaration>) : WasmHeapType() {
|
||||
@@ -49,7 +49,7 @@ sealed class WasmHeapType {
|
||||
object Extern : Simple("extern", -0x11)
|
||||
object Any : Simple("any", -0x12)
|
||||
object Eq : Simple("eq", -0x13)
|
||||
object Data : Simple("data", -0x19)
|
||||
object Struct : Simple("struct", -0x19)
|
||||
object NullNone : Simple("nullref", -0x1b)
|
||||
object NullNoExtern : Simple("nullexternref", -0x17)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user