[Wasm] Support Milestone 3 of V8 Wasm GC
Advance V8 version to 9.2.212 Relevant Wasm GC changes: https://github.com/WebAssembly/gc/commit/f9f8ffa445c2c0fe4ac284a1d12a8c5477da4457
This commit is contained in:
committed by
Space
parent
9500b2d36e
commit
a468792a19
Generated
+1
@@ -2,6 +2,7 @@
|
||||
<dictionary name="skuzmich">
|
||||
<words>
|
||||
<w>anyref</w>
|
||||
<w>dataref</w>
|
||||
<w>ushr</w>
|
||||
<w>wasm</w>
|
||||
</words>
|
||||
|
||||
+14
-25
@@ -142,7 +142,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
if (klass.getWasmArrayAnnotation() != null) {
|
||||
require(expression.valueArgumentsCount == 1) { "@WasmArrayOf constructs must have exactly one argument" }
|
||||
generateExpression(expression.getValueArgument(0)!!)
|
||||
body.buildRttCanon(context.transformType(klass.defaultType))
|
||||
body.buildRttCanon(wasmGcType)
|
||||
body.buildInstr(
|
||||
WasmOp.ARRAY_NEW_DEFAULT_WITH_RTT,
|
||||
WasmImmediate.GcType(wasmGcType)
|
||||
@@ -242,7 +242,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
val resT = context.transformResultType(function.returnType)
|
||||
if (resT is WasmRefNullType) {
|
||||
generateTypeRTT(function.returnType)
|
||||
body.buildRefCast(fromType = WasmEqRef, toType = resT)
|
||||
body.buildRefCast()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,10 +278,9 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
}
|
||||
|
||||
wasmSymbols.wasmRefCast -> {
|
||||
val fromType = call.getTypeArgument(0)!!
|
||||
val toType = call.getTypeArgument(1)!!
|
||||
val toType = call.getTypeArgument(0)!!
|
||||
generateTypeRTT(toType)
|
||||
body.buildRefCast(context.transformType(fromType), context.transformType(toType))
|
||||
body.buildRefCast()
|
||||
}
|
||||
|
||||
wasmSymbols.wasmFloatNaN -> {
|
||||
@@ -311,7 +310,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
val field = getInlineClassBackingField(klass)
|
||||
|
||||
generateTypeRTT(toType)
|
||||
body.buildRefCast(context.transformType(fromType), context.transformBoxedType(toType))
|
||||
body.buildRefCast()
|
||||
generateInstanceFieldAccess(field)
|
||||
}
|
||||
else -> {
|
||||
@@ -500,6 +499,15 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
var immediates = emptyArray<WasmImmediate>()
|
||||
when (op.immediates.size) {
|
||||
0 -> {
|
||||
when (op) {
|
||||
WasmOp.REF_TEST -> {
|
||||
val toIrType = call.getTypeArgument(0)!!
|
||||
// ref.test takes RTT as a second operand
|
||||
generateTypeRTT(toIrType)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
1 -> {
|
||||
immediates = arrayOf(
|
||||
@@ -513,25 +521,6 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
}
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
when (op) {
|
||||
WasmOp.REF_TEST -> {
|
||||
val fromIrType = call.getValueArgument(0)!!.type
|
||||
val fromWasmType = context.transformBoxedType(fromIrType)
|
||||
val toIrType = call.getTypeArgument(0)!!
|
||||
val toWasmType = context.transformBoxedType(toIrType)
|
||||
immediates = arrayOf(
|
||||
WasmImmediate.HeapType(fromWasmType),
|
||||
WasmImmediate.HeapType(toWasmType),
|
||||
)
|
||||
|
||||
// ref.test takes RTT as a second operand
|
||||
generateTypeRTT(toIrType)
|
||||
}
|
||||
else ->
|
||||
error("Op $opString is unsupported")
|
||||
}
|
||||
}
|
||||
else ->
|
||||
error("Op $opString is unsupported")
|
||||
}
|
||||
|
||||
+5
-6
@@ -211,7 +211,7 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
||||
|
||||
context.defineGcType(symbol, structType)
|
||||
|
||||
var depth = 2
|
||||
var depth = 0
|
||||
val metadata = context.getClassMetadata(symbol)
|
||||
var subMetadata = metadata
|
||||
while (true) {
|
||||
@@ -222,22 +222,21 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
||||
val initBody = mutableListOf<WasmInstr>()
|
||||
val wasmExpressionGenerator = WasmIrExpressionBuilder(initBody)
|
||||
|
||||
val wasmGcType = context.referenceGcType(symbol)
|
||||
val superClass = metadata.superClass
|
||||
if (superClass != null) {
|
||||
val superRTT = context.referenceClassRTT(superClass.klass.symbol)
|
||||
wasmExpressionGenerator.buildGetGlobal(superRTT)
|
||||
wasmExpressionGenerator.buildRttSub(wasmGcType)
|
||||
} else {
|
||||
wasmExpressionGenerator.buildRttCanon(WasmRefType(WasmHeapType.Simple.Eq))
|
||||
wasmExpressionGenerator.buildRttCanon(wasmGcType)
|
||||
}
|
||||
|
||||
wasmExpressionGenerator.buildRttSub(
|
||||
WasmRefType(WasmHeapType.Type(WasmSymbol(structType)))
|
||||
)
|
||||
|
||||
val rtt = WasmGlobal(
|
||||
name = "rtt_of_$nameStr",
|
||||
isMutable = false,
|
||||
type = WasmRtt(depth, WasmHeapType.Type(WasmSymbol(structType))),
|
||||
type = WasmRtt(depth, WasmSymbol(structType)),
|
||||
init = initBody
|
||||
)
|
||||
|
||||
|
||||
+9
@@ -84,6 +84,15 @@ class BuiltInsLowering(val context: WasmBackendContext) : FileLoweringPass {
|
||||
}
|
||||
|
||||
irBuiltins.checkNotNullSymbol -> {
|
||||
|
||||
// Workaround: v8 doesnt support ref.cast-ing unreachable very well.
|
||||
run {
|
||||
val arg = call.getValueArgument(0)!!
|
||||
if (arg.isNullConst()) {
|
||||
return builder.irCall(symbols.wasmUnreachable, irBuiltins.nothingType)
|
||||
}
|
||||
}
|
||||
|
||||
return irCall(call, symbols.ensureNotNull).also {
|
||||
it.putTypeArgument(0, call.type)
|
||||
}
|
||||
|
||||
+2
-4
@@ -194,8 +194,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
subject = cachedValue(),
|
||||
thenPart = builder.irNull(toType),
|
||||
elsePart = builder.irCall(symbols.wasmRefCast, type = toType).apply {
|
||||
putTypeArgument(0, fromType)
|
||||
putTypeArgument(1, toType)
|
||||
putTypeArgument(0, toType)
|
||||
putValueArgument(0, cachedValue())
|
||||
}
|
||||
)
|
||||
@@ -203,8 +202,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
}
|
||||
|
||||
return builder.irCall(symbols.wasmRefCast, type = toType).apply {
|
||||
putTypeArgument(0, fromType)
|
||||
putTypeArgument(1, toType)
|
||||
putTypeArgument(0, toType)
|
||||
putValueArgument(0, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ val v8osString = when (currentOsType) {
|
||||
}
|
||||
|
||||
val v8edition = "rel" // rel or dbg
|
||||
val v8version = "8.8.104"
|
||||
val v8version = "9.2.212"
|
||||
val v8fileName = "v8-${v8osString}-${v8edition}-${v8version}"
|
||||
val v8url = "https://storage.googleapis.com/chromium-v8/official/canary/$v8fileName.zip"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ internal fun wasm_float_nan(): Float =
|
||||
internal fun wasm_double_nan(): Double =
|
||||
implementedAsIntrinsic
|
||||
|
||||
internal fun <From, To> wasm_ref_cast(a: From): To =
|
||||
internal fun <To> wasm_ref_cast(a: Any?): To =
|
||||
implementedAsIntrinsic
|
||||
|
||||
@WasmOp(WasmOp.I32_EQ)
|
||||
|
||||
@@ -62,7 +62,7 @@ sealed class WasmImmediate {
|
||||
constructor(value: WasmGlobal) : this(WasmSymbol(value))
|
||||
}
|
||||
|
||||
class TypeIdx(val value: WasmSymbol<WasmTypeDeclaration>) : WasmImmediate() {
|
||||
class TypeIdx(val value: WasmSymbolReadOnly<WasmTypeDeclaration>) : WasmImmediate() {
|
||||
constructor(value: WasmTypeDeclaration) : this(WasmSymbol(value))
|
||||
}
|
||||
|
||||
@@ -352,14 +352,12 @@ enum class WasmOp(
|
||||
I31_GET_S("i31.get_s", 0xFB_21),
|
||||
I31_GET_U("i31.get_u", 0xFB_22),
|
||||
|
||||
RTT_CANON("rtt.canon", 0xFB_30, HEAP_TYPE),
|
||||
RTT_CANON("rtt.canon", 0xFB_30, TYPE_IDX),
|
||||
|
||||
// TODO: GC spec also has "depth" and "input heap type" immediates. V8 currently implements without them.
|
||||
RTT_SUB("rtt.sub", 0xFB_31, HEAP_TYPE),
|
||||
REF_TEST("ref.test", 0xFB_40, listOf(HEAP_TYPE, HEAP_TYPE)),
|
||||
REF_CAST("ref.cast", 0xFB_41, listOf(HEAP_TYPE, HEAP_TYPE)),
|
||||
RTT_SUB("rtt.sub", 0xFB_31, TYPE_IDX),
|
||||
REF_TEST("ref.test", 0xFB_40),
|
||||
REF_CAST("ref.cast", 0xFB_41),
|
||||
|
||||
// TODO: GC spec also has two heap type immediates. V8 currently implements without them.
|
||||
BR_ON_CAST("br_on_cast", 0xFB_42, listOf(LABEL_IDX)),
|
||||
;
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ class WasmRefType(val heapType: WasmHeapType) : WasmType("ref", -0x15)
|
||||
|
||||
@Suppress("unused")
|
||||
object WasmI31Ref : WasmType("i31ref", -0x16)
|
||||
class WasmRtt(val depth: Int, val heapType: WasmHeapType) : WasmType("rtt", -0x17)
|
||||
class WasmRtt(val depth: Int, val type: WasmSymbolReadOnly<WasmTypeDeclaration>) : WasmType("rtt", -0x17)
|
||||
|
||||
@Suppress("unused")
|
||||
object WasmExnRef : WasmType("exnref", -0x18)
|
||||
object WasmDataRef : WasmType("dataref", -0x19)
|
||||
|
||||
sealed class WasmHeapType {
|
||||
class Type(val type: WasmSymbolReadOnly<WasmTypeDeclaration>) : WasmHeapType() {
|
||||
|
||||
@@ -130,24 +130,20 @@ abstract class WasmExpressionBuilder {
|
||||
}
|
||||
|
||||
|
||||
fun buildRefCast(fromType: WasmType, toType: WasmType) {
|
||||
buildInstr(
|
||||
WasmOp.REF_CAST,
|
||||
WasmImmediate.HeapType(fromType.getHeapType()),
|
||||
WasmImmediate.HeapType(toType.getHeapType())
|
||||
)
|
||||
fun buildRefCast() {
|
||||
buildInstr(WasmOp.REF_CAST)
|
||||
}
|
||||
|
||||
fun buildRefNull(type: WasmHeapType) {
|
||||
buildInstr(WasmOp.REF_NULL, WasmImmediate.HeapType(WasmRefType(type)))
|
||||
}
|
||||
|
||||
fun buildRttSub(heapType: WasmType) {
|
||||
buildInstr(WasmOp.RTT_SUB, WasmImmediate.HeapType(heapType))
|
||||
fun buildRttSub(decl: WasmSymbol<WasmTypeDeclaration>) {
|
||||
buildInstr(WasmOp.RTT_SUB, WasmImmediate.TypeIdx(decl))
|
||||
}
|
||||
|
||||
fun buildRttCanon(heapType: WasmType) {
|
||||
buildInstr(WasmOp.RTT_CANON, WasmImmediate.HeapType(heapType))
|
||||
fun buildRttCanon(decl: WasmSymbol<WasmTypeDeclaration>) {
|
||||
buildInstr(WasmOp.RTT_CANON, WasmImmediate.TypeIdx(decl))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
}
|
||||
if (type is WasmRtt) {
|
||||
b.writeVarUInt32(type.depth)
|
||||
appendHeapType(type.heapType)
|
||||
appendModuleFieldReference(type.type.owner)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
is WasmRtt ->
|
||||
sameLineList("rtt") {
|
||||
appendElement(type.depth.toString())
|
||||
appendHeapType(type.heapType)
|
||||
appendModuleFieldReference(type.type.owner)
|
||||
}
|
||||
|
||||
WasmUnreachableType -> {
|
||||
|
||||
Reference in New Issue
Block a user