Skip to content

Commit 50acebf

Browse files
committed
Reference types changes to remove subtyping
Main changes: * Rename `anyref` -> `externref` * Remove `nullref` * Rename `hostref` -> `externref` * `ref.null` and `ref.is_null` now have "ref kind" parameter * Add ref kind keywords: `func`, `extern`, `exn`
1 parent 3625539 commit 50acebf

File tree

103 files changed

+3847
-3784
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3847
-3784
lines changed

docs/wast2json.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ The `reference-types` proposal adds three more valid types:
157157

158158
| type | JSON format |
159159
| - | - |
160-
| "nullref" | `{"type": "nullref", "value": ""}` |
161-
| "hostref" | `{"type": "hostref", "value": <string>}` |
160+
| "externref" | `{"type": "externref", "value": <string>}` |
162161
| "funcref" | `{"type": "funcref", "value": <string>}` |
163162

164163

src/binary-reader-ir.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class BinaryReaderIR : public BinaryReaderNop {
184184
Result OnTableSizeExpr(Index table_index) override;
185185
Result OnTableFillExpr(Index table_index) override;
186186
Result OnRefFuncExpr(Index func_index) override;
187-
Result OnRefNullExpr() override;
188-
Result OnRefIsNullExpr() override;
187+
Result OnRefNullExpr(Type type) override;
188+
Result OnRefIsNullExpr(Type type) override;
189189
Result OnNopExpr() override;
190190
Result OnRethrowExpr() override;
191191
Result OnReturnExpr() override;
@@ -213,7 +213,7 @@ class BinaryReaderIR : public BinaryReaderNop {
213213
Result EndElemSegmentInitExpr(Index index) override;
214214
Result OnElemSegmentElemType(Index index, Type elem_type) override;
215215
Result OnElemSegmentElemExprCount(Index index, Index count) override;
216-
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
216+
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
217217
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
218218
Index func_index) override;
219219

@@ -247,7 +247,7 @@ class BinaryReaderIR : public BinaryReaderNop {
247247
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
248248
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
249249
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
250-
Result OnInitExprRefNull(Index index) override;
250+
Result OnInitExprRefNull(Index index, Type type) override;
251251
Result OnInitExprRefFunc(Index index, Index func_index) override;
252252

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

917-
Result BinaryReaderIR::OnRefNullExpr() {
918-
return AppendExpr(MakeUnique<RefNullExpr>());
917+
Result BinaryReaderIR::OnRefNullExpr(Type type) {
918+
return AppendExpr(MakeUnique<RefNullExpr>(type));
919919
}
920920

921-
Result BinaryReaderIR::OnRefIsNullExpr() {
922-
return AppendExpr(MakeUnique<RefIsNullExpr>());
921+
Result BinaryReaderIR::OnRefIsNullExpr(Type type) {
922+
return AppendExpr(MakeUnique<RefIsNullExpr>(type));
923923
}
924924

925925
Result BinaryReaderIR::OnNopExpr() {
@@ -1073,10 +1073,11 @@ Result BinaryReaderIR::OnElemSegmentElemExprCount(Index index, Index count) {
10731073
return Result::Ok;
10741074
}
10751075

1076-
Result BinaryReaderIR::OnElemSegmentElemExpr_RefNull(Index segment_index) {
1076+
Result BinaryReaderIR::OnElemSegmentElemExpr_RefNull(Index segment_index,
1077+
Type type) {
10771078
assert(segment_index == module_->elem_segments.size() - 1);
10781079
ElemSegment* segment = module_->elem_segments[segment_index];
1079-
segment->elem_exprs.emplace_back();
1080+
segment->elem_exprs.emplace_back(type);
10801081
return Result::Ok;
10811082
}
10821083

@@ -1226,9 +1227,9 @@ Result BinaryReaderIR::OnInitExprI64ConstExpr(Index index, uint64_t value) {
12261227
return Result::Ok;
12271228
}
12281229

1229-
Result BinaryReaderIR::OnInitExprRefNull(Index index) {
1230+
Result BinaryReaderIR::OnInitExprRefNull(Index index, Type type) {
12301231
Location loc = GetLocation();
1231-
current_init_expr_->push_back(MakeUnique<RefNullExpr>(loc));
1232+
current_init_expr_->push_back(MakeUnique<RefNullExpr>(type, loc));
12321233
return Result::Ok;
12331234
}
12341235

src/binary-reader-logging.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,24 @@ Result BinaryReaderLogging::OnComdatEntry(ComdatType kind, Index index) {
652652
return reader_->name(value); \
653653
}
654654

655+
#define DEFINE_TYPE(name) \
656+
Result BinaryReaderLogging::name(Type type) { \
657+
LOGF(#name "(%s)\n", type.GetName()); \
658+
return reader_->name(type); \
659+
}
660+
655661
#define DEFINE_INDEX_DESC(name, desc) \
656662
Result BinaryReaderLogging::name(Index value) { \
657663
LOGF(#name "(" desc ": %" PRIindex ")\n", value); \
658664
return reader_->name(value); \
659665
}
660666

667+
#define DEFINE_INDEX_TYPE(name) \
668+
Result BinaryReaderLogging::name(Index value, Type type) { \
669+
LOGF(#name "(index: %" PRIindex ", type: %s)\n", value, type.GetName()); \
670+
return reader_->name(value, type); \
671+
}
672+
661673
#define DEFINE_INDEX_INDEX(name, desc0, desc1) \
662674
Result BinaryReaderLogging::name(Index value0, Index value1) { \
663675
LOGF(#name "(" desc0 ": %" PRIindex ", " desc1 ": %" PRIindex ")\n", \
@@ -777,8 +789,8 @@ DEFINE_INDEX(OnTableGrowExpr)
777789
DEFINE_INDEX(OnTableSizeExpr)
778790
DEFINE_INDEX_DESC(OnTableFillExpr, "table index")
779791
DEFINE_INDEX(OnRefFuncExpr)
780-
DEFINE0(OnRefNullExpr)
781-
DEFINE0(OnRefIsNullExpr)
792+
DEFINE_TYPE(OnRefNullExpr)
793+
DEFINE_TYPE(OnRefIsNullExpr)
782794
DEFINE0(OnNopExpr)
783795
DEFINE0(OnRethrowExpr);
784796
DEFINE_INDEX_DESC(OnReturnCallExpr, "func_index")
@@ -798,7 +810,7 @@ DEFINE_INDEX(OnElemSegmentCount)
798810
DEFINE_INDEX(BeginElemSegmentInitExpr)
799811
DEFINE_INDEX(EndElemSegmentInitExpr)
800812
DEFINE_INDEX_INDEX(OnElemSegmentElemExprCount, "index", "count")
801-
DEFINE_INDEX(OnElemSegmentElemExpr_RefNull)
813+
DEFINE_INDEX_TYPE(OnElemSegmentElemExpr_RefNull)
802814
DEFINE_INDEX_INDEX(OnElemSegmentElemExpr_RefFunc, "index", "func_index")
803815
DEFINE_INDEX(EndElemSegment)
804816
DEFINE_END(EndElemSection)
@@ -825,7 +837,7 @@ DEFINE_BEGIN(BeginRelocSection)
825837
DEFINE_END(EndRelocSection)
826838

827839
DEFINE_INDEX_INDEX(OnInitExprGlobalGetExpr, "index", "global_index")
828-
DEFINE_INDEX(OnInitExprRefNull)
840+
DEFINE_INDEX_TYPE(OnInitExprRefNull)
829841
DEFINE_INDEX_INDEX(OnInitExprRefFunc, "index", "func_index")
830842

831843
DEFINE_BEGIN(BeginDylinkSection)
@@ -891,6 +903,10 @@ Result BinaryReaderLogging::OnOpcodeBlockSig(Type sig_type) {
891903
return reader_->OnOpcodeBlockSig(sig_type);
892904
}
893905

906+
Result BinaryReaderLogging::OnOpcodeType(Type type) {
907+
return reader_->OnOpcodeType(type);
908+
}
909+
894910
Result BinaryReaderLogging::OnEndFunc() {
895911
return reader_->OnEndFunc();
896912
}

src/binary-reader-logging.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
140140
Result OnOpcodeF64(uint64_t value) override;
141141
Result OnOpcodeV128(v128 value) override;
142142
Result OnOpcodeBlockSig(Type sig_type) override;
143+
Result OnOpcodeType(Type type) override;
143144
Result OnAtomicLoadExpr(Opcode opcode,
144145
uint32_t alignment_log2,
145146
Address offset) override;
@@ -199,8 +200,8 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
199200
Result OnTableSizeExpr(Index table) override;
200201
Result OnTableFillExpr(Index table) override;
201202
Result OnRefFuncExpr(Index index) override;
202-
Result OnRefNullExpr() override;
203-
Result OnRefIsNullExpr() override;
203+
Result OnRefNullExpr(Type type) override;
204+
Result OnRefIsNullExpr(Type type) override;
204205
Result OnNopExpr() override;
205206
Result OnRethrowExpr() override;
206207
Result OnReturnCallExpr(Index func_index) override;
@@ -239,7 +240,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
239240
Result EndElemSegmentInitExpr(Index index) override;
240241
Result OnElemSegmentElemType(Index index, Type elem_type) override;
241242
Result OnElemSegmentElemExprCount(Index index, Index count) override;
242-
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
243+
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
243244
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
244245
Index func_index) override;
245246
Result EndElemSegment(Index index) override;
@@ -347,7 +348,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
347348
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
348349
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
349350
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
350-
Result OnInitExprRefNull(Index index) override;
351+
Result OnInitExprRefNull(Index index, Type type) override;
351352
Result OnInitExprRefFunc(Index index, Index func_index) override;
352353

353354
private:

src/binary-reader-nop.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
190190
Result OnOpcodeF64(uint64_t value) override { return Result::Ok; }
191191
Result OnOpcodeV128(v128 value) override { return Result::Ok; }
192192
Result OnOpcodeBlockSig(Type sig_type) override { return Result::Ok; }
193+
Result OnOpcodeType(Type type) override { return Result::Ok; }
193194
Result OnAtomicLoadExpr(Opcode opcode,
194195
uint32_t alignment_log2,
195196
Address offset) override {
@@ -276,8 +277,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
276277
Result OnTableSizeExpr(Index table_index) override { return Result::Ok; }
277278
Result OnTableFillExpr(Index table_index) override { return Result::Ok; }
278279
Result OnRefFuncExpr(Index func_index) override { return Result::Ok; }
279-
Result OnRefNullExpr() override { return Result::Ok; }
280-
Result OnRefIsNullExpr() override { return Result::Ok; }
280+
Result OnRefNullExpr(Type type) override { return Result::Ok; }
281+
Result OnRefIsNullExpr(Type type) override { return Result::Ok; }
281282
Result OnNopExpr() override { return Result::Ok; }
282283
Result OnRethrowExpr() override { return Result::Ok; }
283284
Result OnReturnCallExpr(Index sig_index) override { return Result::Ok; }
@@ -324,7 +325,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
324325
Result OnElemSegmentElemExprCount(Index index, Index count) override {
325326
return Result::Ok;
326327
}
327-
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override {
328+
Result OnElemSegmentElemExpr_RefNull(Index segment_index,
329+
Type type) override {
328330
return Result::Ok;
329331
}
330332
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
@@ -508,7 +510,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
508510
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override {
509511
return Result::Ok;
510512
}
511-
Result OnInitExprRefNull(Index index) override {
513+
Result OnInitExprRefNull(Index index, Type type) override {
512514
return Result::Ok;
513515
}
514516
Result OnInitExprRefFunc(Index index, Index func_index) override {

src/binary-reader-objdump.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase {
403403
Result OnOpcodeF64(uint64_t value) override;
404404
Result OnOpcodeV128(v128 value) override;
405405
Result OnOpcodeBlockSig(Type sig_type) override;
406+
Result OnOpcodeType(Type type) override;
406407

407408
Result OnBrTableExpr(Index num_targets,
408409
Index* target_depths,
@@ -636,6 +637,12 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeV128(v128 value) {
636637
return Result::Ok;
637638
}
638639

640+
Result BinaryReaderObjdumpDisassemble::OnOpcodeType(Type type) {
641+
Offset immediate_len = state->offset - current_opcode_offset;
642+
LogOpcode(immediate_len, type.GetRefKindName());
643+
return Result::Ok;
644+
}
645+
639646
Result BinaryReaderObjdumpDisassemble::OnBrTableExpr(
640647
Index num_targets,
641648
Index* target_depths,
@@ -697,6 +704,8 @@ enum class InitExprType {
697704
V128,
698705
Global,
699706
FuncRef,
707+
// TODO: There isn't a nullref anymore, this just represents ref.null of some
708+
// type T.
700709
NullRef,
701710
};
702711

@@ -709,6 +718,7 @@ struct InitExpr {
709718
uint64_t i64;
710719
uint64_t f64;
711720
v128 v128_v;
721+
Type type;
712722
} value;
713723
};
714724

@@ -804,7 +814,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
804814
uint8_t flags) override;
805815
Result OnElemSegmentElemType(Index index, Type elem_type) override;
806816
Result OnElemSegmentElemExprCount(Index index, Index count) override;
807-
Result OnElemSegmentElemExpr_RefNull(Index segment_index) override;
817+
Result OnElemSegmentElemExpr_RefNull(Index segment_index, Type type) override;
808818
Result OnElemSegmentElemExpr_RefFunc(Index segment_index,
809819
Index func_index) override;
810820

@@ -838,7 +848,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
838848
Result OnInitExprGlobalGetExpr(Index index, Index global_index) override;
839849
Result OnInitExprI32ConstExpr(Index index, uint32_t value) override;
840850
Result OnInitExprI64ConstExpr(Index index, uint64_t value) override;
841-
Result OnInitExprRefNull(Index index) override;
851+
Result OnInitExprRefNull(Index index, Type type) override;
842852
Result OnInitExprRefFunc(Index index, Index func_index) override;
843853

844854
Result OnDylinkInfo(uint32_t mem_size,
@@ -1286,8 +1296,10 @@ Result BinaryReaderObjdump::OnExport(Index index,
12861296
return Result::Ok;
12871297
}
12881298

1289-
Result BinaryReaderObjdump::OnElemSegmentElemExpr_RefNull(Index segment_index) {
1290-
PrintDetails(" - elem[%" PRIindex "] = nullref\n", elem_offset_ + elem_index_);
1299+
Result BinaryReaderObjdump::OnElemSegmentElemExpr_RefNull(Index segment_index,
1300+
Type type) {
1301+
PrintDetails(" - elem[%" PRIindex "] = ref.null %s\n",
1302+
elem_offset_ + elem_index_, type.GetName());
12911303
elem_index_++;
12921304
return Result::Ok;
12931305
}
@@ -1395,7 +1407,7 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
13951407
break;
13961408
}
13971409
case InitExprType::NullRef: {
1398-
PrintDetails(" - init nullref\n");
1410+
PrintDetails(" - init null\n");
13991411
break;
14001412
}
14011413
}
@@ -1489,9 +1501,10 @@ Result BinaryReaderObjdump::OnInitExprI64ConstExpr(Index index,
14891501
return Result::Ok;
14901502
}
14911503

1492-
Result BinaryReaderObjdump::OnInitExprRefNull(Index index) {
1504+
Result BinaryReaderObjdump::OnInitExprRefNull(Index index, Type type) {
14931505
InitExpr expr;
14941506
expr.type = InitExprType::NullRef;
1507+
expr.value.type = type;
14951508
HandleInitExpr(expr);
14961509
return Result::Ok;
14971510
}

0 commit comments

Comments
 (0)