Skip to content

Commit 759c485

Browse files
tlivelykripken
authored andcommitted
Remove FunctionType (#2510)
Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
1 parent acd786d commit 759c485

528 files changed

Lines changed: 15189 additions & 15717 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Current Trunk
2727
- Replace BinaryenSIMDBitselect* with BinaryenSIMDTernary* in the C API and add
2828
qfma/qfms instructions.
2929
- Added `offset` parameter to BinaryenSetFunctionTable.
30+
- Add the ability to create multivalue Types in the C and JS APIs.
31+
- Remove named function types. They are replaced by `params` and `results` types
32+
local to each function.
3033

3134
v88
3235
---

scripts/clean_c_api_trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
trace = open(sys.argv[1]).read()
2323

2424
start = trace.find('// beginning a Binaryen API trace')
25+
end = trace.rfind('// ending a Binaryen API trace')
2526
if start >= 0:
26-
trace = trace[start:]
27+
trace = trace[start:end]
2728

2829
while 1:
2930
start = trace.find('\n(')

src/abi/js.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,20 @@ extern cashew::IString SCRATCH_STORE_F64;
5252
inline void
5353
ensureScratchMemoryHelpers(Module* wasm,
5454
cashew::IString specific = cashew::IString()) {
55-
auto ensureImport =
56-
[&](Name name, const std::vector<Type> params, Type result) {
57-
if (wasm->getFunctionOrNull(name)) {
58-
return;
59-
}
60-
if (specific.is() && name != specific) {
61-
return;
62-
}
63-
auto func = make_unique<Function>();
64-
func->name = name;
65-
func->params = params;
66-
func->result = result;
67-
func->module = ENV;
68-
func->base = name;
69-
wasm->addFunction(std::move(func));
70-
};
55+
auto ensureImport = [&](Name name, Type params, Type results) {
56+
if (wasm->getFunctionOrNull(name)) {
57+
return;
58+
}
59+
if (specific.is() && name != specific) {
60+
return;
61+
}
62+
auto func = make_unique<Function>();
63+
func->name = name;
64+
func->sig = Signature(params, results);
65+
func->module = ENV;
66+
func->base = name;
67+
wasm->addFunction(std::move(func));
68+
};
7169

7270
ensureImport(SCRATCH_LOAD_I32, {i32}, i32);
7371
ensureImport(SCRATCH_STORE_I32, {i32, i32}, none);

src/abi/stack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
128128
// no need to restore the old stack value, we're gone anyhow
129129
} else {
130130
// save the return value
131-
auto temp = builder.addVar(func, func->result);
131+
auto temp = builder.addVar(func, func->sig.results);
132132
block->list.push_back(builder.makeLocalSet(temp, func->body));
133133
block->list.push_back(makeStackRestore());
134-
block->list.push_back(builder.makeLocalGet(temp, func->result));
134+
block->list.push_back(builder.makeLocalGet(temp, func->sig.results));
135135
}
136136
block->finalize();
137137
func->body = block;

0 commit comments

Comments
 (0)