summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/wasm-binary.h26
-rw-r--r--src/wasm/wasm-binary.cpp66
-rw-r--r--test/let.txt42
-rw-r--r--test/let.wasmbin128 -> 0 bytes
-rw-r--r--test/let.wasm.fromBinary80
6 files changed, 4 insertions, 212 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1728b4dac..608d1359f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@ Current Trunk
- `BinaryenModulePrintStackIR`, `BinaryenModuleWriteStackIR` and
`BinaryenModuleAllocateAndWriteStackIR` now have an extra boolean
argument `optimize`. (#4832)
+- Remove support for the `let` instruction that has been removed from the typed
+ function references spec.
v109
----
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index a866881f5..200252da7 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1085,7 +1085,6 @@ enum ASTNodes {
CallRef = 0x14,
RetCallRef = 0x15,
- Let = 0x17,
// gc opcodes
@@ -1585,29 +1584,6 @@ public:
std::vector<Expression*> expressionStack;
- // Each let block in the binary adds new locals to the bottom of the index
- // space. That is, all previously-existing indexes are bumped to higher
- // indexes. getAbsoluteLocalIndex does this computation.
- // Note that we must track not just the number of locals added in each let,
- // but also the absolute index from which they were allocated, as binaryen
- // will add new locals as it goes for things like stacky code and tuples (so
- // there isn't a simple way to get to the absolute index from a relative one).
- // Hence each entry here is a pair of the number of items, and the absolute
- // index they begin at.
- struct LetData {
- // How many items are defined in this let.
- Index num;
- // The absolute index from which they are allocated from. That is, if num is
- // 5 and absoluteStart is 10, then we use indexes 10-14.
- Index absoluteStart;
- };
- std::vector<LetData> letStack;
-
- // Given a relative index of a local (the one used in the wasm binary), get
- // the absolute one which takes into account lets, and is the one used in
- // Binaryen IR.
- Index getAbsoluteLocalIndex(Index index);
-
// Control flow structure parsing: these have not just the normal binary
// data for an instruction, but also some bytes later on like "end" or "else".
// We must be aware of the connection between those things, for debug info.
@@ -1774,8 +1750,6 @@ public:
void visitRethrow(Rethrow* curr);
void visitCallRef(CallRef* curr);
void visitRefAs(RefAs* curr, uint8_t code);
- // Let is lowered into a block.
- void visitLet(Block* curr);
[[noreturn]] void throwError(std::string text);
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 2f2eb5e39..4e8e3f0d7 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2443,7 +2443,6 @@ void WasmBinaryBuilder::readFunctions() {
assert(exceptionTargetNames.empty());
assert(expressionStack.empty());
assert(controlFlowStack.empty());
- assert(letStack.empty());
assert(depth == 0);
// Even if we are skipping function bodies we need to not skip the start
// function. That contains important code for wasm-emscripten-finalize in
@@ -2471,7 +2470,6 @@ void WasmBinaryBuilder::readFunctions() {
throwError("stack not empty on function exit");
}
assert(controlFlowStack.empty());
- assert(letStack.empty());
if (pos != endOfFunction) {
throwError("binary offset at function exit not at expected location");
}
@@ -3770,10 +3768,6 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
visitCallRef(call);
break;
}
- case BinaryConsts::Let: {
- visitLet((curr = allocator.alloc<Block>())->cast<Block>());
- break;
- }
case BinaryConsts::AtomicPrefix: {
code = static_cast<uint8_t>(getU32LEB());
if (maybeVisitLoad(curr, code, /*isAtomic=*/true)) {
@@ -4004,36 +3998,6 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
return BinaryConsts::ASTNodes(code);
}
-Index WasmBinaryBuilder::getAbsoluteLocalIndex(Index index) {
- // Wasm binaries put each let at the bottom of the index space, which may be
- // good for binary size as often the uses of the let variables are close to
- // the let itself. However, in Binaryen IR we just have a simple flat index
- // space of absolute values, which we add to as we parse, and we depend on
- // later optimizations to reorder locals for size.
- //
- // For example, if we have $x, then we add a let with $y, the binary would map
- // 0 => y, 1 => x, while in Binaryen IR $x always stays at 0, and $y is added
- // at 1.
- //
- // Compute the relative index in the let we were added. We start by looking at
- // the last let added, and if we belong to it, we are already relative to it.
- // We will continue relativizing as we go down, til we find our let.
- int64_t relative = index;
- for (auto i = int64_t(letStack.size()) - 1; i >= 0; i--) {
- auto& info = letStack[i];
- int64_t currNum = info.num;
- // There were |currNum| let items added in this let. Check if we were one of
- // them.
- if (relative < currNum) {
- return info.absoluteStart + relative;
- }
- relative -= currNum;
- }
- // We were not a let, but a normal var from the beginning. In that case, after
- // we subtracted the let items, we have the proper absolute index.
- return relative;
-}
-
void WasmBinaryBuilder::startControlFlow(Expression* curr) {
if (DWARF && currFunction) {
controlFlowStack.push_back(curr);
@@ -4314,7 +4278,7 @@ void WasmBinaryBuilder::visitCallIndirect(CallIndirect* curr) {
void WasmBinaryBuilder::visitLocalGet(LocalGet* curr) {
BYN_TRACE("zz node: LocalGet " << pos << std::endl);
requireFunctionContext("local.get");
- curr->index = getAbsoluteLocalIndex(getU32LEB());
+ curr->index = getU32LEB();
if (curr->index >= currFunction->getNumLocals()) {
throwError("bad local.get index");
}
@@ -4325,7 +4289,7 @@ void WasmBinaryBuilder::visitLocalGet(LocalGet* curr) {
void WasmBinaryBuilder::visitLocalSet(LocalSet* curr, uint8_t code) {
BYN_TRACE("zz node: Set|LocalTee\n");
requireFunctionContext("local.set outside of function");
- curr->index = getAbsoluteLocalIndex(getU32LEB());
+ curr->index = getU32LEB();
if (curr->index >= currFunction->getNumLocals()) {
throwError("bad local.set index");
}
@@ -6797,32 +6761,6 @@ void WasmBinaryBuilder::visitCallRef(CallRef* curr) {
curr->finalize(sig.results);
}
-void WasmBinaryBuilder::visitLet(Block* curr) {
- // A let is lowered into a block that contains the value, and we allocate
- // locals as needed, which works as we remove non-nullability.
-
- startControlFlow(curr);
- // Get the output type.
- curr->type = getType();
- // Get the new local types. First, get the absolute index from which we will
- // start to allocate them.
- requireFunctionContext("let");
- Index absoluteStart = currFunction->vars.size();
- readVars();
- Index numNewVars = currFunction->vars.size() - absoluteStart;
- // Assign the values into locals.
- Builder builder(wasm);
- for (Index i = 0; i < numNewVars; i++) {
- auto* value = popNonVoidExpression();
- curr->list.push_back(builder.makeLocalSet(absoluteStart + i, value));
- }
- // Read the body, with adjusted local indexes.
- letStack.emplace_back(LetData{numNewVars, absoluteStart});
- curr->list.push_back(getBlockOrSingleton(curr->type));
- letStack.pop_back();
- curr->finalize(curr->type);
-}
-
bool WasmBinaryBuilder::maybeVisitI31New(Expression*& out, uint32_t code) {
if (code != BinaryConsts::I31New) {
return false;
diff --git a/test/let.txt b/test/let.txt
deleted file mode 100644
index 9901aaad8..000000000
--- a/test/let.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-;; source code for let.wasm, which was created by wasp
-(module
- (type $vector (array (mut f64)))
- (func $main
- (local $x i32)
- (local $y i32)
- (drop (local.get $x)) ;; 0 is the index appearing in the binary
- ;; first let
- (array.new_with_rtt $vector
- (f64.const 3.14159)
- (i32.const 1)
- (rtt.canon $vector)
- )
- (let (local $v (ref $vector))
- (drop (local.get $v)) ;; 0
- (drop (local.get $x)) ;; 1
- ;; another one, nested
- (array.new_with_rtt $vector
- (f64.const 1234)
- (i32.const 2)
- (rtt.canon $vector)
- )
- (let (local $w (ref $vector))
- (drop (local.get $v)) ;; 1
- (drop (local.get $w)) ;; 0
- (drop (local.get $x)) ;; 2
- )
- )
- ;; another one, later
- (array.new_with_rtt $vector
- (f64.const 2.1828)
- (i32.const 3)
- (rtt.canon $vector)
- )
- (let (local $v (ref $vector))
- (drop (local.get $v)) ;; 0
- (drop (local.get $x)) ;; 1
- )
- (drop (local.get $x)) ;; 0
- )
-)
-
diff --git a/test/let.wasm b/test/let.wasm
deleted file mode 100644
index 8a24b7d35..000000000
--- a/test/let.wasm
+++ /dev/null
Binary files differ
diff --git a/test/let.wasm.fromBinary b/test/let.wasm.fromBinary
deleted file mode 100644
index de51c1045..000000000
--- a/test/let.wasm.fromBinary
+++ /dev/null
@@ -1,80 +0,0 @@
-(module
- (type $[mut:f64] (array (mut f64)))
- (type $none_=>_none (func))
- (func $0
- (local $0 i32)
- (local $1 i32)
- (local $2 (ref null $[mut:f64]))
- (local $3 (ref null $[mut:f64]))
- (local $4 (ref null $[mut:f64]))
- (drop
- (local.get $0)
- )
- (block
- (local.set $2
- (array.new_with_rtt $[mut:f64]
- (f64.const 3.14159)
- (i32.const 1)
- (rtt.canon $[mut:f64])
- )
- )
- (block
- (drop
- (ref.as_non_null
- (local.get $2)
- )
- )
- (drop
- (local.get $0)
- )
- (block
- (local.set $3
- (array.new_with_rtt $[mut:f64]
- (f64.const 1234)
- (i32.const 2)
- (rtt.canon $[mut:f64])
- )
- )
- (block
- (drop
- (ref.as_non_null
- (local.get $2)
- )
- )
- (drop
- (ref.as_non_null
- (local.get $3)
- )
- )
- (drop
- (local.get $0)
- )
- )
- )
- )
- )
- (block
- (local.set $4
- (array.new_with_rtt $[mut:f64]
- (f64.const 2.1828)
- (i32.const 3)
- (rtt.canon $[mut:f64])
- )
- )
- (block
- (drop
- (ref.as_non_null
- (local.get $4)
- )
- )
- (drop
- (local.get $0)
- )
- )
- )
- (drop
- (local.get $0)
- )
- )
-)
-