Skip to content

Reference types changes to remove subtyping #1407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2020
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
8 changes: 4 additions & 4 deletions docs/wast2json.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ types are supported, with the given JSON format:
| "f32" | `{"type": "f32", "value": <string>}` |
| "f64" | `{"type": "f64", "value": <string>}` |

The `reference-types` proposal adds three more valid types:
The `reference-types` proposal adds three more valid types. In each case the
value can either be an integer or `"null"`:

| type | JSON format |
| - | - |
| "nullref" | `{"type": "nullref", "value": ""}` |
| "hostref" | `{"type": "hostref", "value": <string>}` |
| "externref" | `{"type": "externref", "value": <string>}` |
| "funcref" | `{"type": "funcref", "value": <string>}` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice there that we are missing exnref .. which is a little annoyingly close in name to externref


| "exnref" | `{"type": "exnref", "value": <string>}` |

The `simd` proposal adds another type, with a slightly different syntax.

Expand Down
25 changes: 13 additions & 12 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnTableSizeExpr(Index table_index) override;
Result OnTableFillExpr(Index table_index) override;
Result OnRefFuncExpr(Index func_index) override;
Result OnRefNullExpr() override;
Result OnRefIsNullExpr() override;
Result OnRefNullExpr(Type type) override;
Result OnRefIsNullExpr(Type type) override;
Result OnNopExpr() override;
Result OnRethrowExpr() override;
Result OnReturnExpr() override;
Expand Down Expand Up @@ -213,7 +213,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result EndElemSegmentInitExpr(Index index) override;
Result OnElemSegmentElemType(Index index, Type elem_type) override;
Result OnElemSegmentElemExprCount(Index index, Index count) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
Index func_index) override;

Expand Down Expand Up @@ -247,7 +247,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
Result OnInitExprRefNull(Index index) override;
Result OnInitExprRefNull(Index index, Type type) override;
Result OnInitExprRefFunc(Index index, Index func_index) override;

Result OnDataSymbol(Index index, uint32_t flags, string_view name,
Expand Down Expand Up @@ -914,12 +914,12 @@ Result BinaryReaderIR::OnRefFuncExpr(Index func_index) {
return AppendExpr(MakeUnique<RefFuncExpr>(Var(func_index)));
}

Result BinaryReaderIR::OnRefNullExpr() {
return AppendExpr(MakeUnique<RefNullExpr>());
Result BinaryReaderIR::OnRefNullExpr(Type type) {
return AppendExpr(MakeUnique<RefNullExpr>(type));
}

Result BinaryReaderIR::OnRefIsNullExpr() {
return AppendExpr(MakeUnique<RefIsNullExpr>());
Result BinaryReaderIR::OnRefIsNullExpr(Type type) {
return AppendExpr(MakeUnique<RefIsNullExpr>(type));
}

Result BinaryReaderIR::OnNopExpr() {
Expand Down Expand Up @@ -1073,10 +1073,11 @@ Result BinaryReaderIR::OnElemSegmentElemExprCount(Index index, Index count) {
return Result::Ok;
}

Result BinaryReaderIR::OnElemSegmentElemExpr_RefNull(Index segment_index) {
Result BinaryReaderIR::OnElemSegmentElemExpr_RefNull(Index segment_index,
Type type) {
assert(segment_index == module_->elem_segments.size() - 1);
ElemSegment* segment = module_->elem_segments[segment_index];
segment->elem_exprs.emplace_back();
segment->elem_exprs.emplace_back(type);
return Result::Ok;
}

Expand Down Expand Up @@ -1226,9 +1227,9 @@ Result BinaryReaderIR::OnInitExprI64ConstExpr(Index index, uint64_t value) {
return Result::Ok;
}

Result BinaryReaderIR::OnInitExprRefNull(Index index) {
Result BinaryReaderIR::OnInitExprRefNull(Index index, Type type) {
Location loc = GetLocation();
current_init_expr_->push_back(MakeUnique<RefNullExpr>(loc));
current_init_expr_->push_back(MakeUnique<RefNullExpr>(type, loc));
return Result::Ok;
}

Expand Down
24 changes: 20 additions & 4 deletions src/binary-reader-logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,24 @@ Result BinaryReaderLogging::OnComdatEntry(ComdatType kind, Index index) {
return reader_->name(value); \
}

#define DEFINE_TYPE(name) \
Result BinaryReaderLogging::name(Type type) { \
LOGF(#name "(%s)\n", type.GetName()); \
return reader_->name(type); \
}

#define DEFINE_INDEX_DESC(name, desc) \
Result BinaryReaderLogging::name(Index value) { \
LOGF(#name "(" desc ": %" PRIindex ")\n", value); \
return reader_->name(value); \
}

#define DEFINE_INDEX_TYPE(name) \
Result BinaryReaderLogging::name(Index value, Type type) { \
LOGF(#name "(index: %" PRIindex ", type: %s)\n", value, type.GetName()); \
return reader_->name(value, type); \
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part could be split out if you feel like landing sooner.


#define DEFINE_INDEX_INDEX(name, desc0, desc1) \
Result BinaryReaderLogging::name(Index value0, Index value1) { \
LOGF(#name "(" desc0 ": %" PRIindex ", " desc1 ": %" PRIindex ")\n", \
Expand Down Expand Up @@ -777,8 +789,8 @@ DEFINE_INDEX(OnTableGrowExpr)
DEFINE_INDEX(OnTableSizeExpr)
DEFINE_INDEX_DESC(OnTableFillExpr, "table index")
DEFINE_INDEX(OnRefFuncExpr)
DEFINE0(OnRefNullExpr)
DEFINE0(OnRefIsNullExpr)
DEFINE_TYPE(OnRefNullExpr)
DEFINE_TYPE(OnRefIsNullExpr)
DEFINE0(OnNopExpr)
DEFINE0(OnRethrowExpr);
DEFINE_INDEX_DESC(OnReturnCallExpr, "func_index")
Expand All @@ -798,7 +810,7 @@ DEFINE_INDEX(OnElemSegmentCount)
DEFINE_INDEX(BeginElemSegmentInitExpr)
DEFINE_INDEX(EndElemSegmentInitExpr)
DEFINE_INDEX_INDEX(OnElemSegmentElemExprCount, "index", "count")
DEFINE_INDEX(OnElemSegmentElemExpr_RefNull)
DEFINE_INDEX_TYPE(OnElemSegmentElemExpr_RefNull)
DEFINE_INDEX_INDEX(OnElemSegmentElemExpr_RefFunc, "index", "func_index")
DEFINE_INDEX(EndElemSegment)
DEFINE_END(EndElemSection)
Expand All @@ -825,7 +837,7 @@ DEFINE_BEGIN(BeginRelocSection)
DEFINE_END(EndRelocSection)

DEFINE_INDEX_INDEX(OnInitExprGlobalGetExpr, "index", "global_index")
DEFINE_INDEX(OnInitExprRefNull)
DEFINE_INDEX_TYPE(OnInitExprRefNull)
DEFINE_INDEX_INDEX(OnInitExprRefFunc, "index", "func_index")

DEFINE_BEGIN(BeginDylinkSection)
Expand Down Expand Up @@ -891,6 +903,10 @@ Result BinaryReaderLogging::OnOpcodeBlockSig(Type sig_type) {
return reader_->OnOpcodeBlockSig(sig_type);
}

Result BinaryReaderLogging::OnOpcodeType(Type type) {
return reader_->OnOpcodeType(type);
}

Result BinaryReaderLogging::OnEndFunc() {
return reader_->OnEndFunc();
}
Expand Down
9 changes: 5 additions & 4 deletions src/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnOpcodeF64(uint64_t value) override;
Result OnOpcodeV128(v128 value) override;
Result OnOpcodeBlockSig(Type sig_type) override;
Result OnOpcodeType(Type type) override;
Result OnAtomicLoadExpr(Opcode opcode,
uint32_t alignment_log2,
Address offset) override;
Expand Down Expand Up @@ -199,8 +200,8 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnTableSizeExpr(Index table) override;
Result OnTableFillExpr(Index table) override;
Result OnRefFuncExpr(Index index) override;
Result OnRefNullExpr() override;
Result OnRefIsNullExpr() override;
Result OnRefNullExpr(Type type) override;
Result OnRefIsNullExpr(Type type) override;
Result OnNopExpr() override;
Result OnRethrowExpr() override;
Result OnReturnCallExpr(Index func_index) override;
Expand Down Expand Up @@ -239,7 +240,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result EndElemSegmentInitExpr(Index index) override;
Result OnElemSegmentElemType(Index index, Type elem_type) override;
Result OnElemSegmentElemExprCount(Index index, Index count) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
Index func_index) override;
Result EndElemSegment(Index index) override;
Expand Down Expand Up @@ -347,7 +348,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
Result OnInitExprRefNull(Index index) override;
Result OnInitExprRefNull(Index index, Type type) override;
Result OnInitExprRefFunc(Index index, Index func_index) override;

private:
Expand Down
10 changes: 6 additions & 4 deletions src/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnOpcodeF64(uint64_t value) override { return Result::Ok; }
Result OnOpcodeV128(v128 value) override { return Result::Ok; }
Result OnOpcodeBlockSig(Type sig_type) override { return Result::Ok; }
Result OnOpcodeType(Type type) override { return Result::Ok; }
Result OnAtomicLoadExpr(Opcode opcode,
uint32_t alignment_log2,
Address offset) override {
Expand Down Expand Up @@ -276,8 +277,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnTableSizeExpr(Index table_index) override { return Result::Ok; }
Result OnTableFillExpr(Index table_index) override { return Result::Ok; }
Result OnRefFuncExpr(Index func_index) override { return Result::Ok; }
Result OnRefNullExpr() override { return Result::Ok; }
Result OnRefIsNullExpr() override { return Result::Ok; }
Result OnRefNullExpr(Type type) override { return Result::Ok; }
Result OnRefIsNullExpr(Type type) override { return Result::Ok; }
Result OnNopExpr() override { return Result::Ok; }
Result OnRethrowExpr() override { return Result::Ok; }
Result OnReturnCallExpr(Index sig_index) override { return Result::Ok; }
Expand Down Expand Up @@ -324,7 +325,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnElemSegmentElemExprCount(Index index, Index count) override {
return Result::Ok;
}
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override {
Result OnElemSegmentElemExpr_RefNull(Index segment_index,
Type type) override {
return Result::Ok;
}
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
Expand Down Expand Up @@ -508,7 +510,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override {
return Result::Ok;
}
Result OnInitExprRefNull(Index index) override {
Result OnInitExprRefNull(Index index, Type type) override {
return Result::Ok;
}
Result OnInitExprRefFunc(Index index, Index func_index) override {
Expand Down
25 changes: 19 additions & 6 deletions src/binary-reader-objdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase {
Result OnOpcodeF64(uint64_t value) override;
Result OnOpcodeV128(v128 value) override;
Result OnOpcodeBlockSig(Type sig_type) override;
Result OnOpcodeType(Type type) override;

Result OnBrTableExpr(Index num_targets,
Index* target_depths,
Expand Down Expand Up @@ -636,6 +637,12 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeV128(v128 value) {
return Result::Ok;
}

Result BinaryReaderObjdumpDisassemble::OnOpcodeType(Type type) {
Offset immediate_len = state->offset - current_opcode_offset;
LogOpcode(immediate_len, type.GetRefKindName());
return Result::Ok;
}

Result BinaryReaderObjdumpDisassemble::OnBrTableExpr(
Index num_targets,
Index* target_depths,
Expand Down Expand Up @@ -697,6 +704,8 @@ enum class InitExprType {
V128,
Global,
FuncRef,
// TODO: There isn't a nullref anymore, this just represents ref.null of some
// type T.
NullRef,
};

Expand All @@ -709,6 +718,7 @@ struct InitExpr {
uint64_t i64;
uint64_t f64;
v128 v128_v;
Type type;
} value;
};

Expand Down Expand Up @@ -804,7 +814,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
uint8_t flags) override;
Result OnElemSegmentElemType(Index index, Type elem_type) override;
Result OnElemSegmentElemExprCount(Index index, Index count) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
Index func_index) override;

Expand Down Expand Up @@ -838,7 +848,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
Result OnInitExprRefNull(Index index) override;
Result OnInitExprRefNull(Index index, Type type) override;
Result OnInitExprRefFunc(Index index, Index func_index) override;

Result OnDylinkInfo(uint32_t mem_size,
Expand Down Expand Up @@ -1286,8 +1296,10 @@ Result BinaryReaderObjdump::OnExport(Index index,
return Result::Ok;
}

Result BinaryReaderObjdump::OnElemSegmentElemExpr_RefNull(Index segment_index) {
PrintDetails(" - elem[%" PRIindex "] = nullref\n", elem_offset_ + elem_index_);
Result BinaryReaderObjdump::OnElemSegmentElemExpr_RefNull(Index segment_index,
Type type) {
PrintDetails(" - elem[%" PRIindex "] = ref.null %s\n",
elem_offset_ + elem_index_, type.GetName());
elem_index_++;
return Result::Ok;
}
Expand Down Expand Up @@ -1395,7 +1407,7 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
break;
}
case InitExprType::NullRef: {
PrintDetails(" - init nullref\n");
PrintDetails(" - init null\n");
break;
}
}
Expand Down Expand Up @@ -1489,9 +1501,10 @@ Result BinaryReaderObjdump::OnInitExprI64ConstExpr(Index index,
return Result::Ok;
}

Result BinaryReaderObjdump::OnInitExprRefNull(Index index) {
Result BinaryReaderObjdump::OnInitExprRefNull(Index index, Type type) {
InitExpr expr;
expr.type = InitExprType::NullRef;
expr.value.type = type;
HandleInitExpr(expr);
return Result::Ok;
}
Expand Down
Loading