Skip to content

Commit

Permalink
Remove unwind
Browse files Browse the repository at this point in the history
`unwind` was removed. See WebAssembly/exception-handling#156.
  • Loading branch information
aheejin committed Jun 26, 2021
1 parent 9500425 commit 533607c
Show file tree
Hide file tree
Showing 34 changed files with 11 additions and 339 deletions.
28 changes: 2 additions & 26 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnUnaryExpr(Opcode opcode) override;
Result OnTernaryExpr(Opcode opcode) override;
Result OnUnreachableExpr() override;
Result OnUnwindExpr() override;
Result EndFunctionBody(Index index) override;
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override;
Result OnSimdLoadLaneExpr(Opcode opcode,
Expand Down Expand Up @@ -813,7 +812,6 @@ Result BinaryReaderIR::OnEndExpr() {

case LabelType::Func:
case LabelType::Catch:
case LabelType::Unwind:
break;
}

Expand Down Expand Up @@ -1015,7 +1013,7 @@ Result BinaryReaderIR::AppendCatch(Catch&& catch_) {
if (try_->kind == TryKind::Invalid) {
try_->kind = TryKind::Catch;
} else if (try_->kind != TryKind::Catch) {
PrintError("catch not allowed in try-unwind or try-delegate");
PrintError("catch not allowed in try-delegate");
return Result::Error;
}

Expand All @@ -1032,28 +1030,6 @@ Result BinaryReaderIR::OnCatchAllExpr() {
return AppendCatch(Catch(GetLocation()));
}

Result BinaryReaderIR::OnUnwindExpr() {
LabelNode* label = nullptr;
CHECK_RESULT(TopLabel(&label));

if (label->label_type != LabelType::Try) {
PrintError("unwind not inside try block");
return Result::Error;
}

auto* try_ = cast<TryExpr>(label->context);

if (try_->kind == TryKind::Invalid) {
try_->kind = TryKind::Unwind;
} else if (try_->kind != TryKind::Unwind) {
PrintError("unwind not allowed in try-catch or try-delegate");
return Result::Error;
}

label->exprs = &try_->unwind;
return Result::Ok;
}

Result BinaryReaderIR::OnDelegateExpr(Index depth) {
LabelNode* label = nullptr;
CHECK_RESULT(TopLabel(&label));
Expand All @@ -1068,7 +1044,7 @@ Result BinaryReaderIR::OnDelegateExpr(Index depth) {
if (try_->kind == TryKind::Invalid) {
try_->kind = TryKind::Delegate;
} else if (try_->kind != TryKind::Delegate) {
PrintError("delegate not allowed in try-catch or try-unwind");
PrintError("delegate not allowed in try-catch");
return Result::Error;
}

Expand Down
1 change: 0 additions & 1 deletion src/binary-reader-logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ DEFINE_LOAD_STORE_OPCODE(OnLoadZeroExpr);
DEFINE_LOAD_STORE_OPCODE(OnStoreExpr);
DEFINE_INDEX_DESC(OnThrowExpr, "tag_index")
DEFINE0(OnUnreachableExpr)
DEFINE0(OnUnwindExpr)
DEFINE_OPCODE(OnUnaryExpr)
DEFINE_OPCODE(OnTernaryExpr)
DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(OnSimdLoadLaneExpr);
Expand Down
1 change: 0 additions & 1 deletion src/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnUnaryExpr(Opcode opcode) override;
Result OnTernaryExpr(Opcode opcode) override;
Result OnUnreachableExpr() override;
Result OnUnwindExpr() override;
Result OnAtomicWaitExpr(Opcode opcode,
Address alignment_log2,
Address offset) override;
Expand Down
1 change: 0 additions & 1 deletion src/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnUnaryExpr(Opcode opcode) override { return Result::Ok; }
Result OnTernaryExpr(Opcode opcode) override { return Result::Ok; }
Result OnUnreachableExpr() override { return Result::Ok; }
Result OnUnwindExpr() override { return Result::Ok; }
Result EndFunctionBody(Index index) override { return Result::Ok; }
Result EndCodeSection() override { return Result::Ok; }
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override {
Expand Down
1 change: 0 additions & 1 deletion src/binary-reader-objdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(size_t data_size,
case Opcode::Else:
case Opcode::Catch:
case Opcode::CatchAll:
case Opcode::Unwind:
indent_level--;
default:
break;
Expand Down
6 changes: 0 additions & 6 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1435,12 +1435,6 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
break;
}

case Opcode::Unwind: {
CALLBACK0(OnUnwindExpr);
CALLBACK0(OnOpcodeBare);
break;
}

case Opcode::Delegate: {
Index index;
CHECK_RESULT(ReadIndex(&index, "depth"));
Expand Down
1 change: 0 additions & 1 deletion src/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ class BinaryReaderDelegate {
virtual Result OnUnaryExpr(Opcode opcode) = 0;
virtual Result OnTernaryExpr(Opcode opcode) = 0;
virtual Result OnUnreachableExpr() = 0;
virtual Result OnUnwindExpr() = 0;
virtual Result EndFunctionBody(Index index) = 0;
virtual Result EndCodeSection() = 0;

Expand Down
5 changes: 0 additions & 5 deletions src/binary-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,11 +1006,6 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) {
}
WriteOpcode(stream_, Opcode::End);
break;
case TryKind::Unwind:
WriteOpcode(stream_, Opcode::Unwind);
WriteExprList(func, try_expr->unwind);
WriteOpcode(stream_, Opcode::End);
break;
case TryKind::Delegate:
WriteOpcode(stream_, Opcode::Delegate);
WriteU32Leb128(stream_,
Expand Down
3 changes: 1 addition & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ enum class LabelType {
Else,
Try,
Catch,
Unwind,

First = Func,
Last = Unwind,
Last = Catch,
};
static const int kLabelTypeCount = WABT_ENUM_COUNT(LabelType);

Expand Down
16 changes: 0 additions & 16 deletions src/expr-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ Result ExprVisitor::VisitExpr(Expr* root_expr) {
CHECK_RESULT(delegate_->EndTryExpr(try_expr));
}
break;
case TryKind::Unwind:
CHECK_RESULT(delegate_->OnUnwindExpr(try_expr));
PushExprlist(State::Unwind, expr, try_expr->unwind);
break;
case TryKind::Delegate:
CHECK_RESULT(delegate_->OnDelegateExpr(try_expr));
break;
Expand Down Expand Up @@ -141,18 +137,6 @@ Result ExprVisitor::VisitExpr(Expr* root_expr) {
}
break;
}

case State::Unwind: {
auto try_expr = cast<TryExpr>(expr);
auto& iter = expr_iter_stack_.back();
if (iter != try_expr->unwind.end()) {
PushDefault(&*iter++);
} else {
CHECK_RESULT(delegate_->EndTryExpr(try_expr));
PopExprlist();
}
break;
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/expr-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ExprVisitor {
Loop,
Try,
Catch,
Unwind,
};

Result HandleDefaultState(Expr*);
Expand Down Expand Up @@ -118,7 +117,6 @@ class ExprVisitor::Delegate {
virtual Result OnUnreachableExpr(UnreachableExpr*) = 0;
virtual Result BeginTryExpr(TryExpr*) = 0;
virtual Result OnCatchExpr(TryExpr*, Catch*) = 0;
virtual Result OnUnwindExpr(TryExpr*) = 0;
virtual Result OnDelegateExpr(TryExpr*) = 0;
virtual Result EndTryExpr(TryExpr*) = 0;
virtual Result OnThrowExpr(ThrowExpr*) = 0;
Expand Down Expand Up @@ -193,7 +191,6 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result OnUnreachableExpr(UnreachableExpr*) override { return Result::Ok; }
Result BeginTryExpr(TryExpr*) override { return Result::Ok; }
Result OnCatchExpr(TryExpr*, Catch*) override { return Result::Ok; }
Result OnUnwindExpr(TryExpr*) override { return Result::Ok; }
Result OnDelegateExpr(TryExpr*) override { return Result::Ok; }
Result EndTryExpr(TryExpr*) override { return Result::Ok; }
Result OnThrowExpr(ThrowExpr*) override { return Result::Ok; }
Expand Down
1 change: 0 additions & 1 deletion src/interp/interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,6 @@ RunResult Thread::StepInternal(Trap::Ptr* out_trap) {
case O::Try:
case O::Catch:
case O::CatchAll:
case O::Unwind:
case O::Delegate:
case O::Throw:
case O::Rethrow:
Expand Down
1 change: 0 additions & 1 deletion src/interp/istream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ Instr Istream::Read(Offset* offset) const {
case Opcode::Rethrow:
case Opcode::Throw:
case Opcode::Try:
case Opcode::Unwind:
case Opcode::ReturnCall:
// Not used.
break;
Expand Down
2 changes: 0 additions & 2 deletions src/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ typedef std::vector<Catch> CatchVector;
enum class TryKind {
Invalid,
Catch,
Unwind,
Delegate
};

Expand Down Expand Up @@ -609,7 +608,6 @@ class TryExpr : public ExprMixin<ExprType::Try> {
TryKind kind;
Block block;
CatchVector catches;
ExprList unwind;
Var delegate_target;
};

Expand Down
1 change: 0 additions & 1 deletion src/lexer-keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,3 @@ i64.trunc_u:sat/f64, TokenType::Convert, Opcode::I64TruncSatF64U
set_global, TokenType::GlobalSet, Opcode::GlobalSet
set_local, TokenType::LocalSet, Opcode::LocalSet
tee_local, TokenType::LocalTee, Opcode::LocalTee
unwind, TokenType::Unwind, Opcode::Unwind
1 change: 0 additions & 1 deletion src/opcode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ bool Opcode::IsEnabled(const Features& features) const {
switch (enum_) {
case Opcode::Try:
case Opcode::Catch:
case Opcode::Unwind:
case Opcode::Delegate:
case Opcode::Throw:
case Opcode::Rethrow:
Expand Down
1 change: 0 additions & 1 deletion src/opcode.def
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x06, Try, "try", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x07, Catch, "catch", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x08, Throw, "throw", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x09, Rethrow, "rethrow", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0a, Unwind, "unwind", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0b, End, "end", "")
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0c, Br, "br", "")
WABT_OPCODE(___, I32, ___, ___, 0, 0, 0x0d, BrIf, "br_if", "")
Expand Down
5 changes: 2 additions & 3 deletions src/prebuilt/lexer-keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
{
enum
{
TOTAL_KEYWORDS = 611,
TOTAL_KEYWORDS = 610,
MIN_WORD_LENGTH = 2,
MAX_WORD_LENGTH = 29,
MIN_HASH_VALUE = 19,
Expand Down Expand Up @@ -457,8 +457,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
{"i64x2.bitmask", TokenType::Unary, Opcode::I64X2Bitmask},
#line 383 "src/lexer-keywords.txt"
{"i64.atomic.store32", TokenType::AtomicStore, Opcode::I64AtomicStore32},
#line 631 "src/lexer-keywords.txt"
{"unwind", TokenType::Unwind, Opcode::Unwind},
{""},
#line 407 "src/lexer-keywords.txt"
{"i64.load32_u", TokenType::Load, Opcode::I64Load32U},
{""},
Expand Down
7 changes: 0 additions & 7 deletions src/shared-validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,4 @@ Result SharedValidator::OnUnreachable(const Location& loc) {
return result;
}

Result SharedValidator::OnUnwind(const Location& loc) {
Result result = Result::Ok;
expr_loc_ = &loc;
result |= typechecker_.OnUnwind();
return result;
}

} // namespace wabt
1 change: 0 additions & 1 deletion src/shared-validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class SharedValidator {
Result OnTry(const Location&, Type sig_type);
Result OnUnary(const Location&, Opcode);
Result OnUnreachable(const Location&);
Result OnUnwind(const Location&);

private:
struct FuncType {
Expand Down
3 changes: 1 addition & 2 deletions src/token.def
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ WABT_TOKEN(Throw, "throw")
WABT_TOKEN(Try, "try")
WABT_TOKEN(Unary, "UNARY")
WABT_TOKEN(Unreachable, "unreachable")
WABT_TOKEN(Unwind, "unwind")
WABT_TOKEN_FIRST(Opcode, AtomicFence)
WABT_TOKEN_LAST(Opcode, Unwind)
WABT_TOKEN_LAST(Opcode, Unreachable)

/* Tokens with string data. */
WABT_TOKEN(AlignEqNat, "align=")
Expand Down
26 changes: 2 additions & 24 deletions src/type-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,7 @@ Result TypeChecker::OnEnd(Label* label,
Result TypeChecker::OnEnd() {
Result result = Result::Ok;
static const char* s_label_type_name[] = {
"function", "block", "loop", "if", "if false branch", "try",
"try catch", "try unwind"};
"function", "block", "loop", "if", "if false branch", "try", "try catch"};
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_label_type_name) == kLabelTypeCount);
Label* label;
CHECK_RESULT(TopLabel(&label));
Expand All @@ -618,15 +617,7 @@ Result TypeChecker::OnEnd() {
}

const char* desc = s_label_type_name[static_cast<int>(label->label_type)];
if (label->label_type == LabelType::Unwind) {
// Unwind is unusual in that it always unwinds the control stack at the end,
// and therefore the return type of the unwind expressions are not the same
// as the block return type.
TypeVector empty;
result |= OnEnd(label, empty, desc, desc);
} else {
result |= OnEnd(label, label->result_types, desc, desc);
}
result |= OnEnd(label, label->result_types, desc, desc);
return result;
}

Expand Down Expand Up @@ -914,19 +905,6 @@ Result TypeChecker::OnUnreachable() {
return SetUnreachable();
}

Result TypeChecker::OnUnwind() {
Result result = Result::Ok;
Label* label;
CHECK_RESULT(TopLabel(&label));
result |= CheckLabelType(label, LabelType::Try);
result |= PopAndCheckSignature(label->result_types, "try block");
result |= CheckTypeStackEnd("try block");
ResetTypeStackToLabel(label);
label->label_type = LabelType::Unwind;
label->unreachable = false;
return result;
}

Result TypeChecker::EndFunction() {
Result result = Result::Ok;
Label* label;
Expand Down
1 change: 0 additions & 1 deletion src/type-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class TypeChecker {
Result OnTry(const TypeVector& param_types, const TypeVector& result_types);
Result OnUnary(Opcode);
Result OnUnreachable();
Result OnUnwind();
Result EndFunction();

static Result CheckType(Type actual, Type expected);
Expand Down
6 changes: 0 additions & 6 deletions src/validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class Validator : public ExprVisitor::Delegate {
Result OnUnreachableExpr(UnreachableExpr*) override;
Result BeginTryExpr(TryExpr*) override;
Result OnCatchExpr(TryExpr*, Catch*) override;
Result OnUnwindExpr(TryExpr*) override;
Result OnDelegateExpr(TryExpr*) override;
Result EndTryExpr(TryExpr*) override;
Result OnThrowExpr(ThrowExpr*) override;
Expand Down Expand Up @@ -499,11 +498,6 @@ Result Validator::OnCatchExpr(TryExpr*, Catch* catch_) {
return Result::Ok;
}

Result Validator::OnUnwindExpr(TryExpr* expr) {
result_ |= validator_.OnUnwind(expr->loc);
return Result::Ok;
}

Result Validator::OnDelegateExpr(TryExpr* expr) {
result_ |= validator_.OnDelegate(expr->loc, expr->delegate_target);
return Result::Ok;
Expand Down
Loading

0 comments on commit 533607c

Please sign in to comment.