[Wasm] Make types for none and noextern consistent with the spec

This commit is contained in:
Zalim Bashorov
2023-07-19 16:54:17 +02:00
committed by Space Team
parent 2d13cbae80
commit 8d440a61e2
4 changed files with 12 additions and 13 deletions
@@ -297,7 +297,7 @@ class BodyGenerator(
return
}
body.buildRefNull(WasmHeapType.Simple.NullNone, location) // this = null
body.buildRefNull(WasmHeapType.Simple.None, location) // this = null
generateCall(expression)
}
@@ -738,7 +738,7 @@ class BodyGenerator(
if (actualType.isNullableNothing() && expectedType.isNullable()) {
if (expectedType.getClass()?.isExternal == true) {
body.buildDrop(location)
body.buildRefNull(WasmHeapType.Simple.NullNoExtern, location)
body.buildRefNull(WasmHeapType.Simple.NoExtern, location)
}
return
}
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.parentOrNull
import org.jetbrains.kotlin.wasm.ir.*
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
@@ -491,8 +490,8 @@ fun generateDefaultInitializerForType(type: WasmType, g: WasmExpressionBuilder)
WasmF32 -> g.buildConstF32(0f, location)
WasmF64 -> g.buildConstF64(0.0, location)
is WasmRefNullType -> g.buildRefNull(type.heapType, location)
is WasmRefNullNoneType -> g.buildRefNull(WasmHeapType.Simple.NullNone, location)
is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NullNoExtern, location)
is WasmRefNullrefType -> g.buildRefNull(WasmHeapType.Simple.None, location)
is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NoExtern, location)
is WasmAnyRef -> g.buildRefNull(WasmHeapType.Simple.Any, location)
is WasmExternRef -> g.buildRefNull(WasmHeapType.Simple.Extern, location)
WasmUnreachableType -> error("Unreachable type can't be initialized")
@@ -517,7 +516,7 @@ fun generateConstExpression(
when (val kind = expression.kind) {
is IrConstKind.Null -> {
val isExternal = expression.type.getClass()?.isExternal ?: expression.type.erasedUpperBound?.isExternal
val bottomType = if (isExternal == true) WasmRefNullExternrefType else WasmRefNullNoneType
val bottomType = if (isExternal == true) WasmRefNullExternrefType else WasmRefNullrefType
body.buildInstr(WasmOp.REF_NULL, location, WasmImmediate.HeapType(bottomType))
}
is IrConstKind.Boolean -> body.buildConstI32(if (kind.valueOf(expression)) 1 else 0, location)
@@ -82,7 +82,7 @@ class WasmTypeTransformer(
WasmF64
builtIns.nothingNType ->
WasmRefNullNoneType
WasmRefNullrefType
// Value will not be created. Just using a random Wasm type.
builtIns.nothingType ->
@@ -25,8 +25,8 @@ object WasmFuncRef : WasmType("funcref", -0x10)
object WasmExternRef : WasmType("externref", -0x11)
object WasmAnyRef : WasmType("anyref", -0x12)
object WasmEqRef : WasmType("eqref", -0x13)
object WasmRefNullNoneType : WasmType("nullnone", -0x1b)
object WasmRefNullExternrefType : WasmType("nullexternref", -0x17)
object WasmRefNullrefType : WasmType("nullref", -0x1b) // Shorthand for (ref null none)
object WasmRefNullExternrefType : WasmType("nullexternref", -0x17) // Shorthand for (ref null noextern)
data class WasmRefNullType(val heapType: WasmHeapType) : WasmType("ref null", -0x14)
data class WasmRefType(val heapType: WasmHeapType) : WasmType("ref", -0x15)
@@ -50,8 +50,8 @@ sealed class WasmHeapType {
object Any : Simple("any", -0x12)
object Eq : Simple("eq", -0x13)
object Struct : Simple("struct", -0x19)
object NullNone : Simple("nullref", -0x1b)
object NullNoExtern : Simple("nullexternref", -0x17)
object None : Simple("none", -0x1b)
object NoExtern : Simple("noextern", -0x17)
override fun toString(): String {
return "Simple:$name(${code.toString(16)})"
@@ -69,8 +69,8 @@ fun WasmType.getHeapType(): WasmHeapType =
when (this) {
is WasmRefType -> heapType
is WasmRefNullType -> heapType
is WasmRefNullNoneType -> WasmHeapType.Simple.NullNone
is WasmRefNullExternrefType -> WasmHeapType.Simple.NullNoExtern
is WasmRefNullrefType -> WasmHeapType.Simple.None
is WasmRefNullExternrefType -> WasmHeapType.Simple.NoExtern
is WasmEqRef -> WasmHeapType.Simple.Eq
is WasmAnyRef -> WasmHeapType.Simple.Any
is WasmFuncRef -> WasmHeapType.Simple.Func