summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-07-15 16:39:52 -0700
committerGitHub <noreply@github.com>2020-07-15 16:39:52 -0700
commitbd52b8845aa8dcbecc8fc14d77a2bd4e64ad6e75 (patch)
tree1cff008fdeeff4f4a2a7aa703a19d0910fa1b72b /src
parent3041d94d21c82c5a31d1d003bfacbcf2fc28b573 (diff)
downloadwabt-bd52b8845aa8dcbecc8fc14d77a2bd4e64ad6e75.tar.gz
wabt-bd52b8845aa8dcbecc8fc14d77a2bd4e64ad6e75.tar.bz2
wabt-bd52b8845aa8dcbecc8fc14d77a2bd4e64ad6e75.zip
Remove ref.is_null type parameter (#1474)
See https://github.com/WebAssembly/reference-types/issues/99. This change also updates the testsuite, so the spec tests pass too. In addition, the behavior of `br_table` is no longer different from MVP, and has a text to confirm this. That is now fixed in `type-checker.cc` too.
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ir.cc6
-rw-r--r--src/binary-reader-logging.cc2
-rw-r--r--src/binary-reader-logging.h2
-rw-r--r--src/binary-reader-nop.h2
-rw-r--r--src/binary-reader.cc9
-rw-r--r--src/binary-reader.h2
-rw-r--r--src/binary-writer.cc4
-rw-r--r--src/interp/binary-reader-interp.cc6
-rw-r--r--src/ir.h2
-rw-r--r--src/shared-validator.cc4
-rw-r--r--src/shared-validator.h2
-rw-r--r--src/type-checker.cc17
-rw-r--r--src/type-checker.h2
-rw-r--r--src/validator.cc2
-rw-r--r--src/wast-parser.cc7
-rw-r--r--src/wat-writer.cc1
16 files changed, 37 insertions, 33 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index e1b41697..0dc9b2b1 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -185,7 +185,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnTableFillExpr(Index table_index) override;
Result OnRefFuncExpr(Index func_index) override;
Result OnRefNullExpr(Type type) override;
- Result OnRefIsNullExpr(Type type) override;
+ Result OnRefIsNullExpr() override;
Result OnNopExpr() override;
Result OnRethrowExpr() override;
Result OnReturnExpr() override;
@@ -919,8 +919,8 @@ Result BinaryReaderIR::OnRefNullExpr(Type type) {
return AppendExpr(MakeUnique<RefNullExpr>(type));
}
-Result BinaryReaderIR::OnRefIsNullExpr(Type type) {
- return AppendExpr(MakeUnique<RefIsNullExpr>(type));
+Result BinaryReaderIR::OnRefIsNullExpr() {
+ return AppendExpr(MakeUnique<RefIsNullExpr>());
}
Result BinaryReaderIR::OnNopExpr() {
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index ef24ad0e..e5d72772 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -790,7 +790,7 @@ DEFINE_INDEX(OnTableSizeExpr)
DEFINE_INDEX_DESC(OnTableFillExpr, "table index")
DEFINE_INDEX(OnRefFuncExpr)
DEFINE_TYPE(OnRefNullExpr)
-DEFINE_TYPE(OnRefIsNullExpr)
+DEFINE0(OnRefIsNullExpr)
DEFINE0(OnNopExpr)
DEFINE0(OnRethrowExpr);
DEFINE_INDEX_DESC(OnReturnCallExpr, "func_index")
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index f5936562..fd1ac13f 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -201,7 +201,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnTableFillExpr(Index table) override;
Result OnRefFuncExpr(Index index) override;
Result OnRefNullExpr(Type type) override;
- Result OnRefIsNullExpr(Type type) override;
+ Result OnRefIsNullExpr() override;
Result OnNopExpr() override;
Result OnRethrowExpr() override;
Result OnReturnCallExpr(Index func_index) override;
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index 1159476a..a00d6b05 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -278,7 +278,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnTableFillExpr(Index table_index) override { return Result::Ok; }
Result OnRefFuncExpr(Index func_index) override { return Result::Ok; }
Result OnRefNullExpr(Type type) override { return Result::Ok; }
- Result OnRefIsNullExpr(Type type) override { return Result::Ok; }
+ Result OnRefIsNullExpr() 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; }
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index ebc088dd..7f195356 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -1573,13 +1573,10 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
break;
}
- case Opcode::RefIsNull: {
- Type type;
- CHECK_RESULT(ReadRefType(&type, "ref.is_null type"));
- CALLBACK(OnRefIsNullExpr, type);
- CALLBACK(OnOpcodeType, type);
+ case Opcode::RefIsNull:
+ CALLBACK(OnRefIsNullExpr);
+ CALLBACK(OnOpcodeBare);
break;
- }
default:
return ReportUnexpectedOpcode(opcode);
diff --git a/src/binary-reader.h b/src/binary-reader.h
index eae1e87d..e50f4b9d 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -267,7 +267,7 @@ class BinaryReaderDelegate {
virtual Result OnTableFillExpr(Index table_index) = 0;
virtual Result OnRefFuncExpr(Index func_index) = 0;
virtual Result OnRefNullExpr(Type type) = 0;
- virtual Result OnRefIsNullExpr(Type type) = 0;
+ virtual Result OnRefIsNullExpr() = 0;
virtual Result OnNopExpr() = 0;
virtual Result OnRethrowExpr() = 0;
virtual Result OnReturnExpr() = 0;
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index fd2b0c24..261190fd 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -684,11 +684,9 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) {
WriteType(stream_, cast<RefNullExpr>(expr)->type, "ref.null type");
break;
}
- case ExprType::RefIsNull: {
+ case ExprType::RefIsNull:
WriteOpcode(stream_, Opcode::RefIsNull);
- WriteType(stream_, cast<RefIsNullExpr>(expr)->type, "ref.is_null type");
break;
- }
case ExprType::Nop:
WriteOpcode(stream_, Opcode::Nop);
break;
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index 20a8368c..8b44cdaf 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -192,7 +192,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
Result OnMemorySizeExpr() override;
Result OnRefFuncExpr(Index func_index) override;
Result OnRefNullExpr(Type type) override;
- Result OnRefIsNullExpr(Type type) override;
+ Result OnRefIsNullExpr() override;
Result OnNopExpr() override;
Result OnReturnExpr() override;
Result OnSelectExpr(Type result_type) override;
@@ -1240,8 +1240,8 @@ Result BinaryReaderInterp::OnRefNullExpr(Type type) {
return Result::Ok;
}
-Result BinaryReaderInterp::OnRefIsNullExpr(Type type) {
- CHECK_RESULT(validator_.OnRefIsNull(loc, type));
+Result BinaryReaderInterp::OnRefIsNullExpr() {
+ CHECK_RESULT(validator_.OnRefIsNull(loc));
istream_.Emit(Opcode::RefIsNull);
return Result::Ok;
}
diff --git a/src/ir.h b/src/ir.h
index 424a11f5..9b456a7b 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -409,7 +409,7 @@ class RefTypeExpr : public ExprMixin<TypeEnum> {
};
typedef RefTypeExpr<ExprType::RefNull> RefNullExpr;
-typedef RefTypeExpr<ExprType::RefIsNull> RefIsNullExpr;
+typedef ExprMixin<ExprType::RefIsNull> RefIsNullExpr;
template <ExprType TypeEnum>
class OpcodeExpr : public ExprMixin<TypeEnum> {
diff --git a/src/shared-validator.cc b/src/shared-validator.cc
index f4a7303e..8b6bef80 100644
--- a/src/shared-validator.cc
+++ b/src/shared-validator.cc
@@ -968,10 +968,10 @@ Result SharedValidator::OnRefFunc(const Location& loc, Var func_var) {
return result;
}
-Result SharedValidator::OnRefIsNull(const Location& loc, Type type) {
+Result SharedValidator::OnRefIsNull(const Location& loc) {
Result result = Result::Ok;
expr_loc_ = &loc;
- result |= typechecker_.OnRefIsNullExpr(type);
+ result |= typechecker_.OnRefIsNullExpr();
return result;
}
diff --git a/src/shared-validator.h b/src/shared-validator.h
index dadb0930..3f77c403 100644
--- a/src/shared-validator.h
+++ b/src/shared-validator.h
@@ -150,7 +150,7 @@ class SharedValidator {
Result OnMemorySize(const Location&);
Result OnNop(const Location&);
Result OnRefFunc(const Location&, Var func_var);
- Result OnRefIsNull(const Location&, Type type);
+ Result OnRefIsNull(const Location&);
Result OnRefNull(const Location&, Type type);
Result OnRethrow(const Location&);
Result OnReturnCall(const Location&, Var func_var);
diff --git a/src/type-checker.cc b/src/type-checker.cc
index b823ce81..5526640a 100644
--- a/src/type-checker.cc
+++ b/src/type-checker.cc
@@ -670,8 +670,21 @@ Result TypeChecker::OnRefNullExpr(Type type) {
return Result::Ok;
}
-Result TypeChecker::OnRefIsNullExpr(Type type) {
- Result result = PopAndCheck1Type(type, "ref.is_null");
+Result TypeChecker::OnRefIsNullExpr() {
+ Type type;
+ Result result = PeekType(0, &type);
+ if (!type.IsRef()) {
+ TypeVector actual;
+ if (Succeeded(result)) {
+ actual.push_back(type);
+ }
+ std::string message =
+ "type mismatch in ref.is_null, expected reference but got " +
+ TypesToString(actual);
+ PrintError("%s", message.c_str());
+ result = Result::Error;
+ }
+ result |= DropTypes(1);
PushType(Type::I32);
return result;
}
diff --git a/src/type-checker.h b/src/type-checker.h
index 0b3560a9..00edef41 100644
--- a/src/type-checker.h
+++ b/src/type-checker.h
@@ -110,7 +110,7 @@ class TypeChecker {
Result OnTableFill(Type elem_type);
Result OnRefFuncExpr(Index func_index);
Result OnRefNullExpr(Type type);
- Result OnRefIsNullExpr(Type type);
+ Result OnRefIsNullExpr();
Result OnRethrow();
Result OnReturn();
Result OnSelect(Type expected);
diff --git a/src/validator.cc b/src/validator.cc
index e23d5be1..58e32e9d 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -438,7 +438,7 @@ Result Validator::OnRefNullExpr(RefNullExpr* expr) {
}
Result Validator::OnRefIsNullExpr(RefIsNullExpr* expr) {
- result_ |= validator_.OnRefIsNull(expr->loc, expr->type);
+ result_ |= validator_.OnRefIsNull(expr->loc);
return Result::Ok;
}
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 90d92f87..c3ed9d28 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -1996,13 +1996,10 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) {
break;
}
- case TokenType::RefIsNull: {
+ case TokenType::RefIsNull:
ErrorUnlessOpcodeEnabled(Consume());
- Type type;
- CHECK_RESULT(ParseRefKind(&type));
- out_expr->reset(new RefIsNullExpr(type, loc));
+ out_expr->reset(new RefIsNullExpr(loc));
break;
- }
case TokenType::Throw:
ErrorUnlessOpcodeEnabled(Consume());
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 66aaf07b..6bdc9f9e 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -824,7 +824,6 @@ Result WatWriter::ExprVisitorDelegate::OnRefNullExpr(RefNullExpr* expr) {
Result WatWriter::ExprVisitorDelegate::OnRefIsNullExpr(RefIsNullExpr* expr) {
writer_->WritePutsSpace(Opcode::RefIsNull_Opcode.GetName());
- writer_->WriteRefKind(expr->type, NextChar::Newline);
return Result::Ok;
}