[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
+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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user