From 0d55f19d6dd5172b330e24a1d902b531fb7ce71d Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Mon, 2 Feb 2026 17:54:46 -0800 Subject: [PATCH] Start emitting struct.new_desc in binaries As well as struct.new_default_desc now that V8 has supported these instructions for a couple of versions. Also newly validate in IRBuilder that the correct instruction is used. --- src/wasm/wasm-ir-builder.cpp | 14 ++++++-------- src/wasm/wasm-stack.cpp | 8 ++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 867103cebaa..9640fecebdc 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -2143,10 +2143,9 @@ Result<> IRBuilder::makeStructNew(HeapType type, bool isDesc) { if (isDesc && !type.getDescriptorType()) { return Err{"struct.new_desc of type without descriptor"}; } - // TODO: Uncomment this after a transition period. - // if (!isDesc && type.getDescriptorType()) { - // return Err{"type with descriptor requires struct.new_desc"}; - // } + if (!isDesc && type.getDescriptorType()) { + return Err{"type with descriptor requires struct.new_desc"}; + } StructNew curr(wasm.allocator); curr.type = Type(type, NonNullable, Exact); curr.operands.resize(type.getStruct().fields.size()); @@ -2159,10 +2158,9 @@ Result<> IRBuilder::makeStructNewDefault(HeapType type, bool isDesc) { if (isDesc && !type.getDescriptorType()) { return Err{"struct.new_default_desc of type without descriptor"}; } - // TODO: Uncomment this after a transition period. - // if (!isDesc && type.getDescriptorType()) { - // return Err{"type with descriptor requires struct.new_default_desc"}; - // } + if (!isDesc && type.getDescriptorType()) { + return Err{"type with descriptor requires struct.new_default_desc"}; + } StructNew curr(wasm.allocator); curr.type = Type(type, NonNullable, Exact); CHECK_ERR(visitStructNew(&curr)); diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index a48aab1fdc2..0c836d5d498 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2418,17 +2418,13 @@ void BinaryInstWriter::visitStructNew(StructNew* curr) { o << int8_t(BinaryConsts::GCPrefix); if (curr->isWithDefault()) { if (curr->desc) { - // TODO: Start emitting the new opcode once V8 supports it. - // o << U32LEB(BinaryConsts::StructNewDefaultDesc); - o << U32LEB(BinaryConsts::StructNewDefault); + o << U32LEB(BinaryConsts::StructNewDefaultDesc); } else { o << U32LEB(BinaryConsts::StructNewDefault); } } else { if (curr->desc) { - // TODO: Start emitting the new opcode once V8 supports it. - // o << U32LEB(BinaryConsts::StructNewDesc); - o << U32LEB(BinaryConsts::StructNew); + o << U32LEB(BinaryConsts::StructNewDesc); } else { o << U32LEB(BinaryConsts::StructNew); }