Skip to content

Commit 1c77824

Browse files
committed
Bug 1716041 - Remove unwind exception instruction r=rhunt
This instruction was recently removed from the Wasm exception handling proposal spec: WebAssembly/exception-handling#156 Differential Revision: https://phabricator.services.mozilla.com/D118080
1 parent adec90f commit 1c77824

File tree

10 files changed

+4
-372
lines changed

10 files changed

+4
-372
lines changed

js/src/jit-test/lib/wasm-binary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const MozPrefix = 0xff;
152152

153153
const definedOpcodes =
154154
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
155-
...(wasmExceptionsEnabled() ? [0x06, 0x07, 0x08, 0x09, 0x0a] : []),
155+
...(wasmExceptionsEnabled() ? [0x06, 0x07, 0x08, 0x09] : []),
156156
0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
157157
0x10, 0x11,
158158
...(wasmExceptionsEnabled() ? [0x18, 0x19] : []),

js/src/jit-test/tests/wasm/exceptions/instructions.js

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -989,123 +989,3 @@ assertEq(
989989
).exports.f(),
990990
42
991991
);
992-
993-
// Test try-unwind blocks.
994-
assertEq(
995-
wasmEvalText(
996-
`(module
997-
(func (export "f") (result i32)
998-
try (result i32)
999-
i32.const 42
1000-
unwind
1001-
end))`
1002-
).exports.f(),
1003-
42
1004-
);
1005-
1006-
assertEq(
1007-
wasmEvalText(
1008-
`(module
1009-
(func (export "f") (result i32)
1010-
try (result i32)
1011-
i32.const 42
1012-
br 0
1013-
unwind
1014-
end))`
1015-
).exports.f(),
1016-
42
1017-
);
1018-
1019-
assertEq(
1020-
wasmEvalText(
1021-
`(module
1022-
(event $exn)
1023-
(func (export "f") (result i32)
1024-
try (result i32)
1025-
throw $exn
1026-
unwind
1027-
i32.const 42
1028-
br 0
1029-
end))`
1030-
).exports.f(),
1031-
42
1032-
);
1033-
1034-
assertEq(
1035-
wasmEvalText(
1036-
`(module
1037-
(event $exn)
1038-
(func (export "f") (result i32)
1039-
try (result i32)
1040-
throw $exn
1041-
unwind
1042-
i32.const 42
1043-
return
1044-
end))`
1045-
).exports.f(),
1046-
42
1047-
);
1048-
1049-
assertEq(
1050-
wasmEvalText(
1051-
`(module
1052-
(type (func))
1053-
(event $exn (type 0))
1054-
(func (export "f") (result i32) (local i32)
1055-
try
1056-
try
1057-
throw $exn
1058-
unwind
1059-
i32.const 1
1060-
local.set 0
1061-
end
1062-
catch $exn
1063-
end
1064-
local.get 0))`
1065-
).exports.f(),
1066-
1
1067-
);
1068-
1069-
// Test the interaction between delegate and unwind.
1070-
assertEq(
1071-
wasmEvalText(
1072-
`(module
1073-
(event $exn)
1074-
(func (export "f") (result i32) (local i32)
1075-
try
1076-
try
1077-
try
1078-
throw $exn
1079-
delegate 0
1080-
unwind
1081-
i32.const 42
1082-
local.set 0
1083-
end
1084-
catch_all
1085-
end
1086-
local.get 0))`
1087-
).exports.f(),
1088-
42
1089-
);
1090-
1091-
assertEq(
1092-
wasmEvalText(
1093-
`(module
1094-
(type (func))
1095-
(event $exn (type 0))
1096-
(func (export "f") (result i32) (local i32)
1097-
try $l
1098-
try
1099-
try
1100-
throw $exn
1101-
delegate 1
1102-
unwind
1103-
i32.const 27
1104-
local.set 0
1105-
end
1106-
catch_all
1107-
end
1108-
local.get 0))`
1109-
).exports.f(),
1110-
0
1111-
);

js/src/jit-test/tests/wasm/exceptions/throw-to-js.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,3 @@ assertWasmThrowsExn(() =>
242242
delegate 0))`
243243
).exports.f()
244244
);
245-
246-
// Test unwind rethrowing on exit.
247-
assertWasmThrowsExn(() =>
248-
wasmEvalText(
249-
`(module
250-
(event $exn (param))
251-
(func (export "f") (result i32)
252-
try (result i32)
253-
throw $exn
254-
unwind
255-
end))`
256-
).exports.f()
257-
);

js/src/jit-test/tests/wasm/exceptions/validation.js

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function testValidateDecode() {
9797
}),
9898
]),
9999
]),
100-
/try without catch or unwind not allowed/
100+
/try without catch or catch_all not allowed/
101101
);
102102

103103
// Rethrow must have a depth argument.
@@ -641,66 +641,6 @@ function testValidateDelegate() {
641641
);
642642
}
643643

644-
function testValidateUnwind() {
645-
wasmValidateText(
646-
`(module
647-
(event $exn (param))
648-
(func (local i32)
649-
try
650-
throw $exn
651-
unwind
652-
i32.const 1
653-
local.set 0
654-
end))`
655-
);
656-
657-
wasmValidateText(
658-
`(module
659-
(event $exn (param))
660-
(func (result i32)
661-
try (result i32)
662-
i32.const 1
663-
br 0
664-
unwind
665-
i32.const 2
666-
br 0
667-
end))`
668-
);
669-
670-
wasmFailValidateText(
671-
`(module
672-
(event $exn (param))
673-
(func (export "f")
674-
try (result i32)
675-
(i32.const 1)
676-
unwind
677-
end))`,
678-
/unused values not explicitly dropped by end of block/
679-
);
680-
681-
wasmFailValidateText(
682-
`(module
683-
(event $exn (param))
684-
(func (local i32)
685-
try
686-
throw $exn
687-
unwind
688-
(i32.const 1)
689-
end))`,
690-
/unused values not explicitly dropped by end of block/
691-
);
692-
693-
wasmFailValidateText(
694-
`(module (func unwind))`,
695-
/unwind can only be used within a try/
696-
);
697-
698-
wasmFailValidateText(
699-
`(module (func try unwind rethrow 0 end))`,
700-
/rethrow target was not a catch block/
701-
);
702-
}
703-
704644
testValidateDecode();
705645
testValidateThrow();
706646
testValidateTryCatch();
@@ -709,4 +649,3 @@ testValidateCatchAll();
709649
testValidateExnPayload();
710650
testValidateRethrow();
711651
testValidateDelegate();
712-
testValidateUnwind();

js/src/wasm/WasmBaselineCompile.cpp

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,7 +8385,6 @@ class BaseCompiler final : public BaseCompilerInterface {
83858385
[[nodiscard]] bool emitCatch();
83868386
[[nodiscard]] bool emitCatchAll();
83878387
[[nodiscard]] bool emitDelegate();
8388-
[[nodiscard]] bool emitUnwind();
83898388
[[nodiscard]] bool emitThrow();
83908389
[[nodiscard]] bool emitRethrow();
83918390
#endif
@@ -8440,7 +8439,6 @@ class BaseCompiler final : public BaseCompilerInterface {
84408439
[[nodiscard]] bool endIfThenElse(ResultType type);
84418440
#ifdef ENABLE_WASM_EXCEPTIONS
84428441
[[nodiscard]] bool endTryCatch(ResultType type);
8443-
[[nodiscard]] bool endTryUnwind(ResultType type);
84448442
#endif
84458443

84468444
void doReturn(ContinuationKind kind);
@@ -10273,11 +10271,6 @@ bool BaseCompiler::emitEnd() {
1027310271
return false;
1027410272
}
1027510273
break;
10276-
case LabelKind::Unwind:
10277-
if (!endTryUnwind(type)) {
10278-
return false;
10279-
}
10280-
break;
1028110274
#endif
1028210275
}
1028310276

@@ -10786,57 +10779,6 @@ bool BaseCompiler::emitDelegate() {
1078610779
return pushBlockResults(resultType);
1078710780
}
1078810781

10789-
bool BaseCompiler::emitUnwind() {
10790-
ResultType resultType;
10791-
NothingVector unused_tryValues;
10792-
10793-
if (!iter_.readUnwind(&resultType, &unused_tryValues)) {
10794-
return false;
10795-
}
10796-
10797-
Control& tryUnwind = controlItem();
10798-
10799-
// End the try branch like the first catch block in a try-catch.
10800-
if (deadCode_) {
10801-
fr.resetStackHeight(tryUnwind.stackHeight, resultType);
10802-
popValueStackTo(tryUnwind.stackSize);
10803-
} else {
10804-
MOZ_ASSERT(stk_.length() == tryUnwind.stackSize + resultType.length());
10805-
popBlockResults(resultType, tryUnwind.stackHeight, ContinuationKind::Jump);
10806-
freeResultRegisters(resultType);
10807-
masm.jump(&tryUnwind.label);
10808-
MOZ_ASSERT(!tryUnwind.bceSafeOnExit);
10809-
MOZ_ASSERT(!tryUnwind.deadOnArrival);
10810-
}
10811-
10812-
deadCode_ = tryUnwind.deadOnArrival;
10813-
10814-
if (deadCode_) {
10815-
return true;
10816-
}
10817-
10818-
bceSafe_ = 0;
10819-
10820-
// Create an exception landing pad for the unwind instructions.
10821-
//
10822-
// We bind otherLabel so that `delegate` can jump here as well.
10823-
masm.bind(&tryUnwind.otherLabel);
10824-
fr.setStackHeight(tryUnwind.stackHeight);
10825-
10826-
// Push the exception reference so that the end of the `unwind` can throw.
10827-
RegRef exn = RegRef(WasmExceptionReg);
10828-
needRef(exn);
10829-
pushRef(exn);
10830-
10831-
WasmTryNoteVector& tryNotes = masm.tryNotes();
10832-
WasmTryNote& tryNote = tryNotes[tryUnwind.tryNoteIndex];
10833-
tryNote.end = masm.currentOffset();
10834-
tryNote.entryPoint = tryNote.end;
10835-
tryNote.framePushed = masm.framePushed();
10836-
10837-
return true;
10838-
}
10839-
1084010782
bool BaseCompiler::endTryCatch(ResultType type) {
1084110783
uint32_t lineOrBytecode = readCallSiteLineOrBytecode();
1084210784

@@ -10945,45 +10887,6 @@ bool BaseCompiler::endTryCatch(ResultType type) {
1094510887
return pushBlockResults(type);
1094610888
}
1094710889

10948-
bool BaseCompiler::endTryUnwind(ResultType type) {
10949-
uint32_t lineOrBytecode = readCallSiteLineOrBytecode();
10950-
Control& tryUnwind = controlItem();
10951-
10952-
if (deadCode_) {
10953-
fr.resetStackHeight(tryUnwind.stackHeight, type);
10954-
popValueStackTo(tryUnwind.stackSize);
10955-
} else {
10956-
// An unwind should have no results so only the exception reference will
10957-
// remain here on top of the original stack.
10958-
MOZ_ASSERT(stk_.length() == tryUnwind.stackSize + 1);
10959-
10960-
RegRef exn = popRef();
10961-
10962-
if (!throwFrom(exn, lineOrBytecode)) {
10963-
return false;
10964-
}
10965-
MOZ_ASSERT(stk_.length() == tryUnwind.stackSize);
10966-
MOZ_ASSERT(!tryUnwind.bceSafeOnExit);
10967-
MOZ_ASSERT(!tryUnwind.deadOnArrival);
10968-
}
10969-
10970-
deadCode_ = tryUnwind.deadOnArrival;
10971-
10972-
if (deadCode_) {
10973-
return true;
10974-
}
10975-
10976-
// The try branch may jump here.
10977-
if (tryUnwind.label.used()) {
10978-
masm.bind(&tryUnwind.label);
10979-
}
10980-
10981-
captureResultRegisters(type);
10982-
bceSafe_ = tryUnwind.bceSafeOnExit;
10983-
10984-
return pushBlockResults(type);
10985-
}
10986-
1098710890
bool BaseCompiler::emitThrow() {
1098810891
uint32_t lineOrBytecode = readCallSiteLineOrBytecode();
1098910892
uint32_t exnIndex;
@@ -15746,11 +15649,6 @@ bool BaseCompiler::emitBody() {
1574615649
CHECK(emitDelegate());
1574715650
iter_.popDelegate();
1574815651
NEXT();
15749-
case uint16_t(Op::Unwind):
15750-
if (!moduleEnv_.exceptionsEnabled()) {
15751-
return iter_.unrecognizedOpcode(&op);
15752-
}
15753-
CHECK_NEXT(emitUnwind());
1575415652
case uint16_t(Op::Throw):
1575515653
if (!moduleEnv_.exceptionsEnabled()) {
1575615654
return iter_.unrecognizedOpcode(&op);

js/src/wasm/WasmConstants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ enum class Op {
222222
Catch = 0x07,
223223
Throw = 0x08,
224224
Rethrow = 0x09,
225-
Unwind = 0x0a,
226225
#endif
227226
End = 0x0b,
228227
Br = 0x0c,

0 commit comments

Comments
 (0)