Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,10 @@
("br_on_cast_fail", "makeBrOnCast(BrOnCastFail)"),
("br_on_cast_desc", "makeBrOnCast(BrOnCastDesc)"),
("br_on_cast_desc_fail", "makeBrOnCast(BrOnCastDescFail)"),
("struct.new", "makeStructNew(false)"),
("struct.new_default", "makeStructNew(true)"),
("struct.new", "makeStructNew(false, false)"),
("struct.new_default", "makeStructNew(true, false)"),
("struct.new_desc", "makeStructNew(false, true)"),
("struct.new_default_desc", "makeStructNew(true, true)"),
("struct.get", "makeStructGet()"),
("struct.get_s", "makeStructGet(true)"),
("struct.get_u", "makeStructGet(false)"),
Expand Down
34 changes: 28 additions & 6 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5315,16 +5315,38 @@ switch (buf[0]) {
switch (buf[10]) {
case '\0':
if (op == "struct.new"sv) {
CHECK_ERR(makeStructNew(ctx, pos, annotations, false));
CHECK_ERR(makeStructNew(ctx, pos, annotations, false, false));
return Ok{};
}
goto parse_error;
case '_':
if (op == "struct.new_default"sv) {
CHECK_ERR(makeStructNew(ctx, pos, annotations, true));
return Ok{};
case '_': {
switch (buf[13]) {
case 'f': {
switch (buf[18]) {
case '\0':
if (op == "struct.new_default"sv) {
CHECK_ERR(makeStructNew(ctx, pos, annotations, true, false));
return Ok{};
}
goto parse_error;
case '_':
if (op == "struct.new_default_desc"sv) {
CHECK_ERR(makeStructNew(ctx, pos, annotations, true, true));
return Ok{};
}
goto parse_error;
default: goto parse_error;
}
}
case 's':
if (op == "struct.new_desc"sv) {
CHECK_ERR(makeStructNew(ctx, pos, annotations, false, true));
return Ok{};
}
goto parse_error;
default: goto parse_error;
}
goto parse_error;
}
default: goto parse_error;
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,13 @@ struct NullInstrParserCtx {
}

template<typename HeapTypeT>
Result<> makeStructNew(Index, const std::vector<Annotation>&, HeapTypeT) {
Result<>
makeStructNew(Index, const std::vector<Annotation>&, HeapTypeT, bool) {
return Ok{};
}
template<typename HeapTypeT>
Result<>
makeStructNewDefault(Index, const std::vector<Annotation>&, HeapTypeT) {
makeStructNewDefault(Index, const std::vector<Annotation>&, HeapTypeT, bool) {
return Ok{};
}
template<typename HeapTypeT>
Expand Down Expand Up @@ -2650,14 +2651,16 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx>, AnnotationParserCtx {

Result<> makeStructNew(Index pos,
const std::vector<Annotation>& annotations,
HeapType type) {
return withLoc(pos, irBuilder.makeStructNew(type));
HeapType type,
bool isDesc) {
return withLoc(pos, irBuilder.makeStructNew(type, isDesc));
}

Result<> makeStructNewDefault(Index pos,
const std::vector<Annotation>& annotations,
HeapType type) {
return withLoc(pos, irBuilder.makeStructNewDefault(type));
HeapType type,
bool isDesc) {
return withLoc(pos, irBuilder.makeStructNewDefault(type, isDesc));
}

Result<> makeStructGet(Index pos,
Expand Down
11 changes: 6 additions & 5 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ makeBrOnNull(Ctx&, Index, const std::vector<Annotation>&, bool onFail = false);
template<typename Ctx>
Result<> makeBrOnCast(Ctx&, Index, const std::vector<Annotation>&, BrOnOp op);
template<typename Ctx>
Result<>
makeStructNew(Ctx&, Index, const std::vector<Annotation>&, bool default_);
Result<> makeStructNew(
Ctx&, Index, const std::vector<Annotation>&, bool default_, bool isDesc);
template<typename Ctx>
Result<> makeStructGet(Ctx&,
Index,
Expand Down Expand Up @@ -2315,13 +2315,14 @@ template<typename Ctx>
Result<> makeStructNew(Ctx& ctx,
Index pos,
const std::vector<Annotation>& annotations,
bool default_) {
bool default_,
bool isDesc) {
auto type = typeidx(ctx);
CHECK_ERR(type);
if (default_) {
return ctx.makeStructNewDefault(pos, annotations, *type);
return ctx.makeStructNewDefault(pos, annotations, *type, isDesc);
}
return ctx.makeStructNew(pos, annotations, *type);
return ctx.makeStructNew(pos, annotations, *type, isDesc);
}

template<typename Ctx>
Expand Down
3 changes: 3 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,9 @@ struct PrintExpressionContents
if (curr->isWithDefault()) {
printMedium(o, "_default");
}
if (curr->desc) {
printMedium(o, "_desc");
}
o << ' ';
printHeapTypeName(curr->type.getHeapType());
}
Expand Down
2 changes: 2 additions & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,8 @@ enum ASTNodes {

StructNew = 0x00,
StructNewDefault = 0x01,
StructNewDesc = 0x20,
StructNewDefaultDesc = 0x21,
StructGet = 0x02,
StructGetS = 0x03,
StructGetU = 0x04,
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
Type in = Type::none,
Type out = Type::none,
std::optional<bool> likely = std::nullopt);
Result<> makeStructNew(HeapType type);
Result<> makeStructNewDefault(HeapType type);
Result<> makeStructNew(HeapType type, bool isDesc);
Result<> makeStructNewDefault(HeapType type, bool isDesc);
Result<>
makeStructGet(HeapType type, Index field, bool signed_, MemoryOrder order);
Result<> makeStructSet(HeapType type, Index field, MemoryOrder order);
Expand Down
10 changes: 8 additions & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4579,9 +4579,15 @@ Result<> WasmBinaryReader::readInst() {
return builder.makeBrOn(label, kind, in, cast);
}
case BinaryConsts::StructNew:
return builder.makeStructNew(getIndexedHeapType());
case BinaryConsts::StructNewDesc: {
bool isDesc = op == BinaryConsts::StructNewDesc;
return builder.makeStructNew(getIndexedHeapType(), isDesc);
}
case BinaryConsts::StructNewDefault:
return builder.makeStructNewDefault(getIndexedHeapType());
case BinaryConsts::StructNewDefaultDesc: {
bool isDesc = op == BinaryConsts::StructNewDefaultDesc;
return builder.makeStructNewDefault(getIndexedHeapType(), isDesc);
}
case BinaryConsts::StructGet:
case BinaryConsts::StructGetS:
case BinaryConsts::StructGetU: {
Expand Down
18 changes: 16 additions & 2 deletions src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,10 +2121,17 @@ Result<> IRBuilder::makeBrOn(
return Ok{};
}

Result<> IRBuilder::makeStructNew(HeapType type) {
Result<> IRBuilder::makeStructNew(HeapType type, bool isDesc) {
if (!type.isStruct()) {
return Err{"expected struct type annotation on struct.new"};
}
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"};
// }
StructNew curr(wasm.allocator);
curr.type = Type(type, NonNullable, Exact);
curr.operands.resize(type.getStruct().fields.size());
Expand All @@ -2133,7 +2140,14 @@ Result<> IRBuilder::makeStructNew(HeapType type) {
return Ok{};
}

Result<> IRBuilder::makeStructNewDefault(HeapType type) {
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"};
// }
StructNew curr(wasm.allocator);
curr.type = Type(type, NonNullable, Exact);
CHECK_ERR(visitStructNew(&curr));
Expand Down
16 changes: 14 additions & 2 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2387,9 +2387,21 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
void BinaryInstWriter::visitStructNew(StructNew* curr) {
o << int8_t(BinaryConsts::GCPrefix);
if (curr->isWithDefault()) {
o << U32LEB(BinaryConsts::StructNewDefault);
if (curr->desc) {
// TODO: Start emitting the new opcode once V8 supports it.
// o << U32LEB(BinaryConsts::StructNewDefaultDesc);
o << U32LEB(BinaryConsts::StructNewDefault);
} else {
o << U32LEB(BinaryConsts::StructNewDefault);
}
} else {
o << U32LEB(BinaryConsts::StructNew);
if (curr->desc) {
// TODO: Start emitting the new opcode once V8 supports it.
// o << U32LEB(BinaryConsts::StructNewDesc);
o << U32LEB(BinaryConsts::StructNew);
} else {
o << U32LEB(BinaryConsts::StructNew);
}
}
parent.writeIndexedHeapType(curr->type.getHeapType());
}
Expand Down
16 changes: 8 additions & 8 deletions test/lit/basic/custom-descriptors.wast
Original file line number Diff line number Diff line change
Expand Up @@ -646,39 +646,39 @@
)

;; CHECK-TEXT: (func $struct-new (type $13) (result (ref (exact $pair)))
;; CHECK-TEXT-NEXT: (struct.new $pair
;; CHECK-TEXT-NEXT: (struct.new_desc $pair
;; CHECK-TEXT-NEXT: (i32.const 0)
;; CHECK-TEXT-NEXT: (i64.const 1)
;; CHECK-TEXT-NEXT: (struct.new_default $pair.desc)
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-BIN: (func $struct-new (type $13) (result (ref (exact $pair)))
;; CHECK-BIN-NEXT: (struct.new $pair
;; CHECK-BIN-NEXT: (struct.new_desc $pair
;; CHECK-BIN-NEXT: (i32.const 0)
;; CHECK-BIN-NEXT: (i64.const 1)
;; CHECK-BIN-NEXT: (struct.new_default $pair.desc)
;; CHECK-BIN-NEXT: )
;; CHECK-BIN-NEXT: )
(func $struct-new (result (ref (exact $pair)))
(struct.new $pair
(struct.new_desc $pair
(i32.const 0)
(i64.const 1)
(struct.new $pair.desc)
)
)

;; CHECK-TEXT: (func $struct-new-default (type $13) (result (ref (exact $pair)))
;; CHECK-TEXT-NEXT: (struct.new_default $pair
;; CHECK-TEXT-NEXT: (struct.new_default_desc $pair
;; CHECK-TEXT-NEXT: (struct.new_default $pair.desc)
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-BIN: (func $struct-new-default (type $13) (result (ref (exact $pair)))
;; CHECK-BIN-NEXT: (struct.new_default $pair
;; CHECK-BIN-NEXT: (struct.new_default_desc $pair
;; CHECK-BIN-NEXT: (struct.new_default $pair.desc)
;; CHECK-BIN-NEXT: )
;; CHECK-BIN-NEXT: )
(func $struct-new-default (result (ref (exact $pair)))
(struct.new_default $pair
(struct.new_default_desc $pair
(struct.new $pair.desc)
)
)
Expand Down Expand Up @@ -896,15 +896,15 @@
;; CHECK-BIN-NODEBUG-NEXT: )

;; CHECK-BIN-NODEBUG: (func $21 (type $13) (result (ref (exact $4)))
;; CHECK-BIN-NODEBUG-NEXT: (struct.new $4
;; CHECK-BIN-NODEBUG-NEXT: (struct.new_desc $4
;; CHECK-BIN-NODEBUG-NEXT: (i32.const 0)
;; CHECK-BIN-NODEBUG-NEXT: (i64.const 1)
;; CHECK-BIN-NODEBUG-NEXT: (struct.new_default $5)
;; CHECK-BIN-NODEBUG-NEXT: )
;; CHECK-BIN-NODEBUG-NEXT: )

;; CHECK-BIN-NODEBUG: (func $22 (type $13) (result (ref (exact $4)))
;; CHECK-BIN-NODEBUG-NEXT: (struct.new_default $4
;; CHECK-BIN-NODEBUG-NEXT: (struct.new_default_desc $4
;; CHECK-BIN-NODEBUG-NEXT: (struct.new_default $5)
;; CHECK-BIN-NODEBUG-NEXT: )
;; CHECK-BIN-NODEBUG-NEXT: )
4 changes: 2 additions & 2 deletions test/lit/ctor-eval/gc-desc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

;; CHECK: (global $ctor-eval$global_2 (ref (exact $desc)) (struct.new_default $desc))

;; CHECK: (global $ctor-eval$global (ref (exact $struct)) (struct.new_default $struct
;; CHECK: (global $ctor-eval$global (ref (exact $struct)) (struct.new_default_desc $struct
;; CHECK-NEXT: (global.get $ctor-eval$global_2)
;; CHECK-NEXT: ))

;; CHECK: (global $global (ref $struct) (global.get $ctor-eval$global))
(global $global (export "g") (ref $struct)
(struct.new $struct
(struct.new_desc $struct
(struct.new $desc)
)
)
Expand Down
Loading
Loading