Skip to content

Commit 0a0b14a

Browse files
committed
Remove unwind instruction for exception handling
This instruction was removed from the spec: WebAssembly/exception-handling#156
1 parent 1d95745 commit 0a0b14a

File tree

10 files changed

+13
-65
lines changed

10 files changed

+13
-65
lines changed

crates/wasmparser/src/binary_reader.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ impl<'a> BinaryReader<'a> {
11101110
0x09 => Operator::Rethrow {
11111111
relative_depth: self.read_var_u32()?,
11121112
},
1113-
0x0a => Operator::Unwind,
11141113
0x0b => Operator::End,
11151114
0x0c => Operator::Br {
11161115
relative_depth: self.read_var_u32()?,

crates/wasmparser/src/operators_validator.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ enum FrameKind {
113113
Try,
114114
Catch,
115115
CatchAll,
116-
Unwind,
117116
}
118117

119118
impl OperatorValidator {
@@ -288,12 +287,7 @@ impl OperatorValidator {
288287
// Read the expected type and expected height of the operand stack the
289288
// end of the frame.
290289
let frame = self.control.last().unwrap();
291-
// The end of an `unwind` should check against the empty block type.
292-
let ty = if frame.kind == FrameKind::Unwind {
293-
TypeOrFuncType::Type(Type::EmptyBlockType)
294-
} else {
295-
frame.block_type
296-
};
290+
let ty = frame.block_type;
297291
let height = frame.height;
298292

299293
// Pop all the result types, in reverse order, from the operand stack.
@@ -637,20 +631,6 @@ impl OperatorValidator {
637631
}
638632
self.unreachable();
639633
}
640-
Operator::Unwind => {
641-
self.check_exceptions_enabled()?;
642-
// Switch from `try` to an `unwind` frame.
643-
let frame = self.pop_ctrl(resources)?;
644-
if frame.kind != FrameKind::Try {
645-
bail_op_err!("unwind found outside of an `try` block");
646-
}
647-
self.control.push(Frame {
648-
kind: FrameKind::Unwind,
649-
block_type: frame.block_type,
650-
height: self.operands.len(),
651-
unreachable: false,
652-
});
653-
}
654634
Operator::Delegate { relative_depth } => {
655635
self.check_exceptions_enabled()?;
656636
let frame = self.pop_ctrl(resources)?;

crates/wasmparser/src/primitives.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ pub enum Operator<'a> {
365365
Rethrow {
366366
relative_depth: u32,
367367
},
368-
Unwind,
369368
End,
370369
Br {
371370
relative_depth: u32,

crates/wasmprinter/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ impl Printer {
681681
// `else`/`catch` are special in that it's printed at
682682
// the previous indentation, but it doesn't actually change
683683
// our nesting level.
684-
Operator::Else
685-
| Operator::Catch { .. }
686-
| Operator::CatchAll
687-
| Operator::Unwind => {
684+
Operator::Else | Operator::Catch { .. } | Operator::CatchAll => {
688685
self.nesting -= 1;
689686
self.newline();
690687
self.nesting += 1;
@@ -762,7 +759,6 @@ impl Printer {
762759
label(*relative_depth)
763760
)?;
764761
}
765-
Unwind => self.result.push_str("unwind"),
766762
End => self.result.push_str("end"),
767763
Br { relative_depth } => {
768764
write!(

crates/wast/src/ast/expr.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ enum If<'a> {
8484
enum Try<'a> {
8585
/// Next thing to parse is the `do` block.
8686
Do(Instruction<'a>),
87-
/// Next thing to parse is `catch`/`catch_all`, `unwind`, or `delegate`.
88-
CatchUnwindOrDelegate,
87+
/// Next thing to parse is `catch`/`catch_all`, or `delegate`.
88+
CatchOrDelegate,
8989
/// Next thing to parse is a `catch` block or `catch_all`.
9090
Catch,
9191
/// Finished parsing like the `End` case, but does not push `end` opcode.
@@ -199,9 +199,9 @@ impl<'a> ExpressionParser<'a> {
199199
Level::Try(Try::Do(_)) => {
200200
return Err(parser.error("previous `try` had no `do`"));
201201
}
202-
Level::Try(Try::CatchUnwindOrDelegate) => {
202+
Level::Try(Try::CatchOrDelegate) => {
203203
return Err(parser.error(
204-
"previous `try` had no `catch`, `catch_all`, `unwind`, or `delegate`",
204+
"previous `try` had no `catch`, `catch_all`, or `delegate`",
205205
));
206206
}
207207
Level::Try(Try::Delegate) => {}
@@ -335,7 +335,7 @@ impl<'a> ExpressionParser<'a> {
335335
if parser.parse::<Option<kw::r#do>>()?.is_some() {
336336
// The state is advanced here only if the parse succeeds in
337337
// order to strictly require the keyword.
338-
*i = Try::CatchUnwindOrDelegate;
338+
*i = Try::CatchOrDelegate;
339339
self.stack.push(Level::TryArm);
340340
return Ok(true);
341341
}
@@ -346,7 +346,7 @@ impl<'a> ExpressionParser<'a> {
346346
}
347347

348348
// After a try's `do`, there are several possible kinds of handlers.
349-
if let Try::CatchUnwindOrDelegate = i {
349+
if let Try::CatchOrDelegate = i {
350350
// `catch` may be followed by more `catch`s or `catch_all`.
351351
if parser.parse::<Option<kw::catch>>()?.is_some() {
352352
let evt = parser.parse::<ast::Index<'a>>()?;
@@ -362,13 +362,6 @@ impl<'a> ExpressionParser<'a> {
362362
self.stack.push(Level::TryArm);
363363
return Ok(true);
364364
}
365-
// `unwind` is similar to `catch_all`.
366-
if parser.parse::<Option<kw::unwind>>()?.is_some() {
367-
self.instrs.push(Instruction::Unwind);
368-
*i = Try::End;
369-
self.stack.push(Level::TryArm);
370-
return Ok(true);
371-
}
372365
// `delegate` has an index, and also ends the block like `end`.
373366
if parser.parse::<Option<kw::delegate>>()?.is_some() {
374367
let depth = parser.parse::<ast::Index<'a>>()?;
@@ -1132,7 +1125,6 @@ instructions! {
11321125
Catch(ast::Index<'a>) : [0x07] : "catch",
11331126
Throw(ast::Index<'a>) : [0x08] : "throw",
11341127
Rethrow(ast::Index<'a>) : [0x09] : "rethrow",
1135-
Unwind : [0x0a] : "unwind",
11361128
Delegate(ast::Index<'a>) : [0x18] : "delegate",
11371129
CatchAll : [0x19] : "catch_all",
11381130
}

crates/wast/src/ast/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ pub mod kw {
419419
custom_keyword!(table);
420420
custom_keyword!(then);
421421
custom_keyword!(r#try = "try");
422-
custom_keyword!(unwind);
423422
custom_keyword!(v128);
424423
}
425424

tests/local/exception-handling.wast

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
drop
2424
drop
2525
)
26-
(func $check-unwind (local i32)
27-
try
28-
i32.const 1
29-
local.set 0
30-
call $check-throw
31-
unwind
32-
i32.const 0
33-
local.set 0
34-
end
35-
)
3626
)
3727

3828
(assert_invalid
@@ -51,11 +41,6 @@
5141
(func try catch_all catch 0 end))
5242
"catch found outside of an `try` block")
5343

54-
(assert_invalid
55-
(module
56-
(func try unwind i32.const 1 end))
57-
"type mismatch: values remaining on stack at end of block")
58-
5944
(assert_invalid
6045
(module
6146
(func block try catch_all rethrow 1 end end))

tests/local/try.wast

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
)
3737
"unexpected items after `catch`")
3838

39-
(assert_malformed
40-
(module quote
41-
"(func (try (do) (unwind) (drop)))"
42-
)
43-
"too many payloads inside of `(try)`")
44-
4539
(assert_malformed
4640
(module quote
4741
"(func (try (do) (delegate 0) (drop)))"

tests/local/try.wat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
(func (try (do) (catch $exn rethrow 0)))
88
(func (try (do) (catch_all rethrow 0)))
99
(func (try (do) (catch $exn) (catch_all rethrow 0)))
10-
(func (try (do) (unwind nop)))
1110
(func (try (do (try (do) (delegate 0))) (catch $exn)))
1211
(func (result i32)
1312
(try (result i32)

tests/roundtrip.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ fn skip_test(test: &Path, contents: &[u8]) -> bool {
141141
// Usage of `assert_invalid` which should be `assert_malformed`
142142
"testsuite/proposals/memory64/memory.wast",
143143
"testsuite/proposals/memory64/address.wast",
144+
// Unwind is being removed from the exceptions proposal.
145+
"dump/try-unwind.txt",
146+
"parse/expr/try-unwind.txt",
147+
"roundtrip/try-unwind.txt",
148+
"roundtrip/fold-try-unwind.txt",
144149
];
145150
if broken.iter().any(|x| test.ends_with(x)) {
146151
return true;

0 commit comments

Comments
 (0)