Skip to content

Commit 29323f0

Browse files
authored
[EH] Remove unwind (#1682)
`unwind` was removed. See WebAssembly/exception-handling#156.
1 parent cdc1b45 commit 29323f0

32 files changed

+14
-325
lines changed

src/binary-reader-ir.cc

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ class BinaryReaderIR : public BinaryReaderNop {
199199
Result OnUnaryExpr(Opcode opcode) override;
200200
Result OnTernaryExpr(Opcode opcode) override;
201201
Result OnUnreachableExpr() override;
202-
Result OnUnwindExpr() override;
203202
Result EndFunctionBody(Index index) override;
204203
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override;
205204
Result OnSimdLoadLaneExpr(Opcode opcode,
@@ -813,7 +812,6 @@ Result BinaryReaderIR::OnEndExpr() {
813812

814813
case LabelType::Func:
815814
case LabelType::Catch:
816-
case LabelType::Unwind:
817815
break;
818816
}
819817

@@ -1015,7 +1013,7 @@ Result BinaryReaderIR::AppendCatch(Catch&& catch_) {
10151013
if (try_->kind == TryKind::Invalid) {
10161014
try_->kind = TryKind::Catch;
10171015
} else if (try_->kind != TryKind::Catch) {
1018-
PrintError("catch not allowed in try-unwind or try-delegate");
1016+
PrintError("catch not allowed in try-delegate");
10191017
return Result::Error;
10201018
}
10211019

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

1035-
Result BinaryReaderIR::OnUnwindExpr() {
1036-
LabelNode* label = nullptr;
1037-
CHECK_RESULT(TopLabel(&label));
1038-
1039-
if (label->label_type != LabelType::Try) {
1040-
PrintError("unwind not inside try block");
1041-
return Result::Error;
1042-
}
1043-
1044-
auto* try_ = cast<TryExpr>(label->context);
1045-
1046-
if (try_->kind == TryKind::Invalid) {
1047-
try_->kind = TryKind::Unwind;
1048-
} else if (try_->kind != TryKind::Unwind) {
1049-
PrintError("unwind not allowed in try-catch or try-delegate");
1050-
return Result::Error;
1051-
}
1052-
1053-
label->exprs = &try_->unwind;
1054-
return Result::Ok;
1055-
}
1056-
10571033
Result BinaryReaderIR::OnDelegateExpr(Index depth) {
10581034
LabelNode* label = nullptr;
10591035
CHECK_RESULT(TopLabel(&label));
@@ -1068,7 +1044,7 @@ Result BinaryReaderIR::OnDelegateExpr(Index depth) {
10681044
if (try_->kind == TryKind::Invalid) {
10691045
try_->kind = TryKind::Delegate;
10701046
} else if (try_->kind != TryKind::Delegate) {
1071-
PrintError("delegate not allowed in try-catch or try-unwind");
1047+
PrintError("delegate not allowed in try-catch");
10721048
return Result::Error;
10731049
}
10741050

src/binary-reader-logging.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ DEFINE_LOAD_STORE_OPCODE(OnLoadZeroExpr);
844844
DEFINE_LOAD_STORE_OPCODE(OnStoreExpr);
845845
DEFINE_INDEX_DESC(OnThrowExpr, "tag_index")
846846
DEFINE0(OnUnreachableExpr)
847-
DEFINE0(OnUnwindExpr)
848847
DEFINE_OPCODE(OnUnaryExpr)
849848
DEFINE_OPCODE(OnTernaryExpr)
850849
DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(OnSimdLoadLaneExpr);

src/binary-reader-logging.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
222222
Result OnUnaryExpr(Opcode opcode) override;
223223
Result OnTernaryExpr(Opcode opcode) override;
224224
Result OnUnreachableExpr() override;
225-
Result OnUnwindExpr() override;
226225
Result OnAtomicWaitExpr(Opcode opcode,
227226
Address alignment_log2,
228227
Address offset) override;

src/binary-reader-nop.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ class BinaryReaderNop : public BinaryReaderDelegate {
303303
Result OnUnaryExpr(Opcode opcode) override { return Result::Ok; }
304304
Result OnTernaryExpr(Opcode opcode) override { return Result::Ok; }
305305
Result OnUnreachableExpr() override { return Result::Ok; }
306-
Result OnUnwindExpr() override { return Result::Ok; }
307306
Result EndFunctionBody(Index index) override { return Result::Ok; }
308307
Result EndCodeSection() override { return Result::Ok; }
309308
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override {

src/binary-reader-objdump.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(size_t data_size,
598598
case Opcode::Else:
599599
case Opcode::Catch:
600600
case Opcode::CatchAll:
601-
case Opcode::Unwind:
602601
indent_level--;
603602
default:
604603
break;

src/binary-reader.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,12 +1435,6 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
14351435
break;
14361436
}
14371437

1438-
case Opcode::Unwind: {
1439-
CALLBACK0(OnUnwindExpr);
1440-
CALLBACK0(OnOpcodeBare);
1441-
break;
1442-
}
1443-
14441438
case Opcode::Delegate: {
14451439
Index index;
14461440
CHECK_RESULT(ReadIndex(&index, "depth"));

src/binary-reader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ class BinaryReaderDelegate {
290290
virtual Result OnUnaryExpr(Opcode opcode) = 0;
291291
virtual Result OnTernaryExpr(Opcode opcode) = 0;
292292
virtual Result OnUnreachableExpr() = 0;
293-
virtual Result OnUnwindExpr() = 0;
294293
virtual Result EndFunctionBody(Index index) = 0;
295294
virtual Result EndCodeSection() = 0;
296295

src/binary-writer.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,6 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) {
10061006
}
10071007
WriteOpcode(stream_, Opcode::End);
10081008
break;
1009-
case TryKind::Unwind:
1010-
WriteOpcode(stream_, Opcode::Unwind);
1011-
WriteExprList(func, try_expr->unwind);
1012-
WriteOpcode(stream_, Opcode::End);
1013-
break;
10141009
case TryKind::Delegate:
10151010
WriteOpcode(stream_, Opcode::Delegate);
10161011
WriteU32Leb128(stream_,

src/common.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ enum class LabelType {
230230
Else,
231231
Try,
232232
Catch,
233-
Unwind,
234233

235234
First = Func,
236-
Last = Unwind,
235+
Last = Catch,
237236
};
238237
static const int kLabelTypeCount = WABT_ENUM_COUNT(LabelType);
239238

src/expr-visitor.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ Result ExprVisitor::VisitExpr(Expr* root_expr) {
107107
CHECK_RESULT(delegate_->EndTryExpr(try_expr));
108108
}
109109
break;
110-
case TryKind::Unwind:
111-
CHECK_RESULT(delegate_->OnUnwindExpr(try_expr));
112-
PushExprlist(State::Unwind, expr, try_expr->unwind);
113-
break;
114110
case TryKind::Delegate:
115111
CHECK_RESULT(delegate_->OnDelegateExpr(try_expr));
116112
break;
@@ -141,18 +137,6 @@ Result ExprVisitor::VisitExpr(Expr* root_expr) {
141137
}
142138
break;
143139
}
144-
145-
case State::Unwind: {
146-
auto try_expr = cast<TryExpr>(expr);
147-
auto& iter = expr_iter_stack_.back();
148-
if (iter != try_expr->unwind.end()) {
149-
PushDefault(&*iter++);
150-
} else {
151-
CHECK_RESULT(delegate_->EndTryExpr(try_expr));
152-
PopExprlist();
153-
}
154-
break;
155-
}
156140
}
157141
}
158142

src/expr-visitor.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class ExprVisitor {
4242
Loop,
4343
Try,
4444
Catch,
45-
Unwind,
4645
};
4746

4847
Result HandleDefaultState(Expr*);
@@ -118,7 +117,6 @@ class ExprVisitor::Delegate {
118117
virtual Result OnUnreachableExpr(UnreachableExpr*) = 0;
119118
virtual Result BeginTryExpr(TryExpr*) = 0;
120119
virtual Result OnCatchExpr(TryExpr*, Catch*) = 0;
121-
virtual Result OnUnwindExpr(TryExpr*) = 0;
122120
virtual Result OnDelegateExpr(TryExpr*) = 0;
123121
virtual Result EndTryExpr(TryExpr*) = 0;
124122
virtual Result OnThrowExpr(ThrowExpr*) = 0;
@@ -193,7 +191,6 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
193191
Result OnUnreachableExpr(UnreachableExpr*) override { return Result::Ok; }
194192
Result BeginTryExpr(TryExpr*) override { return Result::Ok; }
195193
Result OnCatchExpr(TryExpr*, Catch*) override { return Result::Ok; }
196-
Result OnUnwindExpr(TryExpr*) override { return Result::Ok; }
197194
Result OnDelegateExpr(TryExpr*) override { return Result::Ok; }
198195
Result EndTryExpr(TryExpr*) override { return Result::Ok; }
199196
Result OnThrowExpr(ThrowExpr*) override { return Result::Ok; }

src/interp/interp.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,6 @@ RunResult Thread::StepInternal(Trap::Ptr* out_trap) {
17941794
case O::Try:
17951795
case O::Catch:
17961796
case O::CatchAll:
1797-
case O::Unwind:
17981797
case O::Delegate:
17991798
case O::Throw:
18001799
case O::Rethrow:

src/interp/istream.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ Instr Istream::Read(Offset* offset) const {
764764
case Opcode::Rethrow:
765765
case Opcode::Throw:
766766
case Opcode::Try:
767-
case Opcode::Unwind:
768767
case Opcode::ReturnCall:
769768
// Not used.
770769
break;

src/ir.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ typedef std::vector<Catch> CatchVector;
380380
enum class TryKind {
381381
Invalid,
382382
Catch,
383-
Unwind,
384383
Delegate
385384
};
386385

@@ -609,7 +608,6 @@ class TryExpr : public ExprMixin<ExprType::Try> {
609608
TryKind kind;
610609
Block block;
611610
CatchVector catches;
612-
ExprList unwind;
613611
Var delegate_target;
614612
};
615613

src/lexer-keywords.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,3 @@ i64.trunc_u:sat/f64, TokenType::Convert, Opcode::I64TruncSatF64U
628628
set_global, TokenType::GlobalSet, Opcode::GlobalSet
629629
set_local, TokenType::LocalSet, Opcode::LocalSet
630630
tee_local, TokenType::LocalTee, Opcode::LocalTee
631-
unwind, TokenType::Unwind, Opcode::Unwind

src/opcode.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ bool Opcode::IsEnabled(const Features& features) const {
6565
switch (enum_) {
6666
case Opcode::Try:
6767
case Opcode::Catch:
68-
case Opcode::Unwind:
6968
case Opcode::Delegate:
7069
case Opcode::Throw:
7170
case Opcode::Rethrow:

src/opcode.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x06, Try, "try", "")
4545
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x07, Catch, "catch", "")
4646
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x08, Throw, "throw", "")
4747
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x09, Rethrow, "rethrow", "")
48-
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0a, Unwind, "unwind", "")
4948
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0b, End, "end", "")
5049
WABT_OPCODE(___, ___, ___, ___, 0, 0, 0x0c, Br, "br", "")
5150
WABT_OPCODE(___, I32, ___, ___, 0, 0, 0x0d, BrIf, "br_if", "")

src/prebuilt/lexer-keywords.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
158158
{
159159
enum
160160
{
161-
TOTAL_KEYWORDS = 611,
161+
TOTAL_KEYWORDS = 610,
162162
MIN_WORD_LENGTH = 2,
163163
MAX_WORD_LENGTH = 29,
164164
MIN_HASH_VALUE = 19,
@@ -457,8 +457,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len)
457457
{"i64x2.bitmask", TokenType::Unary, Opcode::I64X2Bitmask},
458458
#line 383 "src/lexer-keywords.txt"
459459
{"i64.atomic.store32", TokenType::AtomicStore, Opcode::I64AtomicStore32},
460-
#line 631 "src/lexer-keywords.txt"
461-
{"unwind", TokenType::Unwind, Opcode::Unwind},
460+
{""},
462461
#line 407 "src/lexer-keywords.txt"
463462
{"i64.load32_u", TokenType::Load, Opcode::I64Load32U},
464463
{""},

src/shared-validator.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,4 @@ Result SharedValidator::OnUnreachable(const Location& loc) {
12411241
return result;
12421242
}
12431243

1244-
Result SharedValidator::OnUnwind(const Location& loc) {
1245-
Result result = Result::Ok;
1246-
expr_loc_ = &loc;
1247-
result |= typechecker_.OnUnwind();
1248-
return result;
1249-
}
1250-
12511244
} // namespace wabt

src/shared-validator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ class SharedValidator {
175175
Result OnTry(const Location&, Type sig_type);
176176
Result OnUnary(const Location&, Opcode);
177177
Result OnUnreachable(const Location&);
178-
Result OnUnwind(const Location&);
179178

180179
private:
181180
struct FuncType {

src/token.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ WABT_TOKEN(Throw, "throw")
145145
WABT_TOKEN(Try, "try")
146146
WABT_TOKEN(Unary, "UNARY")
147147
WABT_TOKEN(Unreachable, "unreachable")
148-
WABT_TOKEN(Unwind, "unwind")
149148
WABT_TOKEN_FIRST(Opcode, AtomicFence)
150-
WABT_TOKEN_LAST(Opcode, Unwind)
149+
WABT_TOKEN_LAST(Opcode, Unreachable)
151150

152151
/* Tokens with string data. */
153152
WABT_TOKEN(AlignEqNat, "align=")

src/type-checker.cc

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,10 @@ Result TypeChecker::OnElse() {
589589
}
590590

591591
Result TypeChecker::OnEnd(Label* label,
592-
TypeVector& check_type,
593592
const char* sig_desc,
594593
const char* end_desc) {
595594
Result result = Result::Ok;
596-
result |= PopAndCheckSignature(check_type, sig_desc);
595+
result |= PopAndCheckSignature(label->result_types, sig_desc);
597596
result |= CheckTypeStackEnd(end_desc);
598597
ResetTypeStackToLabel(label);
599598
PushTypes(label->result_types);
@@ -604,8 +603,7 @@ Result TypeChecker::OnEnd(Label* label,
604603
Result TypeChecker::OnEnd() {
605604
Result result = Result::Ok;
606605
static const char* s_label_type_name[] = {
607-
"function", "block", "loop", "if", "if false branch", "try",
608-
"try catch", "try unwind"};
606+
"function", "block", "loop", "if", "if false branch", "try", "try catch"};
609607
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_label_type_name) == kLabelTypeCount);
610608
Label* label;
611609
CHECK_RESULT(TopLabel(&label));
@@ -618,15 +616,7 @@ Result TypeChecker::OnEnd() {
618616
}
619617

620618
const char* desc = s_label_type_name[static_cast<int>(label->label_type)];
621-
if (label->label_type == LabelType::Unwind) {
622-
// Unwind is unusual in that it always unwinds the control stack at the end,
623-
// and therefore the return type of the unwind expressions are not the same
624-
// as the block return type.
625-
TypeVector empty;
626-
result |= OnEnd(label, empty, desc, desc);
627-
} else {
628-
result |= OnEnd(label, label->result_types, desc, desc);
629-
}
619+
result |= OnEnd(label, desc, desc);
630620
return result;
631621
}
632622

@@ -914,25 +904,12 @@ Result TypeChecker::OnUnreachable() {
914904
return SetUnreachable();
915905
}
916906

917-
Result TypeChecker::OnUnwind() {
918-
Result result = Result::Ok;
919-
Label* label;
920-
CHECK_RESULT(TopLabel(&label));
921-
result |= CheckLabelType(label, LabelType::Try);
922-
result |= PopAndCheckSignature(label->result_types, "try block");
923-
result |= CheckTypeStackEnd("try block");
924-
ResetTypeStackToLabel(label);
925-
label->label_type = LabelType::Unwind;
926-
label->unreachable = false;
927-
return result;
928-
}
929-
930907
Result TypeChecker::EndFunction() {
931908
Result result = Result::Ok;
932909
Label* label;
933910
CHECK_RESULT(TopLabel(&label));
934911
result |= CheckLabelType(label, LabelType::Func);
935-
result |= OnEnd(label, label->result_types, "implicit return", "function");
912+
result |= OnEnd(label, "implicit return", "function");
936913
return result;
937914
}
938915

src/type-checker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class TypeChecker {
125125
Result OnTry(const TypeVector& param_types, const TypeVector& result_types);
126126
Result OnUnary(Opcode);
127127
Result OnUnreachable();
128-
Result OnUnwind();
129128
Result EndFunction();
130129

131130
static Result CheckType(Type actual, Type expected);
@@ -169,7 +168,7 @@ class TypeChecker {
169168
const Limits* limits1 = nullptr,
170169
const Limits* limits2 = nullptr,
171170
const Limits* limits3 = nullptr);
172-
Result OnEnd(Label* label, TypeVector& check_type, const char* sig_desc, const char* end_desc);
171+
Result OnEnd(Label* label, const char* sig_desc, const char* end_desc);
173172

174173
template <typename... Args>
175174
void PrintStackIfFailed(Result result, const char* desc, Args... args) {

0 commit comments

Comments
 (0)