From 759c485a9f35bd859d43b86b02e1397a669fa469 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Wed, 11 Dec 2019 17:12:37 -0800 Subject: 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. --- src/wasm-interpreter.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 1a90fdf71..caf8a9a3d 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1449,20 +1449,21 @@ private: FunctionScope(Function* function, const LiteralList& arguments) : function(function) { - if (function->params.size() != arguments.size()) { + if (function->sig.params.size() != arguments.size()) { std::cerr << "Function `" << function->name << "` expects " - << function->params.size() << " parameters, got " + << function->sig.params.size() << " parameters, got " << arguments.size() << " arguments." << std::endl; WASM_UNREACHABLE("invalid param count"); } locals.resize(function->getNumLocals()); + const std::vector& params = function->sig.params.expand(); for (size_t i = 0; i < function->getNumLocals(); i++) { if (i < arguments.size()) { - assert(function->isParam(i)); - if (function->params[i] != arguments[i].type) { + assert(i < params.size()); + if (params[i] != arguments[i].type) { std::cerr << "Function `" << function->name << "` expects type " - << function->params[i] << " for parameter " << i - << ", got " << arguments[i].type << "." << std::endl; + << params[i] << " for parameter " << i << ", got " + << arguments[i].type << "." << std::endl; WASM_UNREACHABLE("invalid param count"); } locals[i] = arguments[i]; @@ -1544,7 +1545,7 @@ private: return target; } Index index = target.value.geti32(); - Type type = curr->isReturn ? scope.function->result : curr->type; + Type type = curr->isReturn ? scope.function->sig.results : curr->type; Flow ret = instance.externalInterface->callTable( index, arguments, type, *instance.self()); // TODO: make this a proper tail call (return first) @@ -2053,9 +2054,10 @@ public: // cannot still be breaking, it means we missed our stop assert(!flow.breaking() || flow.breakTo == RETURN_FLOW); Literal ret = flow.value; - if (function->result != ret.type) { + if (function->sig.results != ret.type) { std::cerr << "calling " << function->name << " resulted in " << ret - << " but the function type is " << function->result << '\n'; + << " but the function type is " << function->sig.results + << '\n'; WASM_UNREACHABLE("unexpect result type"); } // may decrease more than one, if we jumped up the stack -- cgit v1.2.3