Commit bf83f84a authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Make {IsJSCompatibleSignature} flag independent.

This makes sure that the above predicate is independent of any global
process-wide state. The state of enabled features is now passed in
explicitly.

R=thibaudm@chromium.org

Change-Id: I5d44e2b0c0843d2e4f26aaf0d58d23afd5943726
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1751348Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63188}
parent fb698cec
......@@ -5552,7 +5552,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
instance_node_.set(
BuildLoadInstanceFromExportedFunctionData(function_data));
if (!wasm::IsJSCompatibleSignature(sig_, enabled_features_.bigint)) {
if (!wasm::IsJSCompatibleSignature(sig_, enabled_features_)) {
// Throw a TypeError. Use the js_context of the calling javascript
// function (passed as a parameter), such that the generated code is
// js_context independent.
......@@ -6007,7 +6007,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
undefined_value_node_ = jsgraph()->UndefinedConstant();
// Throw a TypeError if the signature is incompatible with JavaScript.
if (!wasm::IsJSCompatibleSignature(sig_, enabled_features_.bigint)) {
if (!wasm::IsJSCompatibleSignature(sig_, enabled_features_)) {
BuildCallToRuntimeWithContext(Runtime::kWasmThrowTypeError, context,
nullptr, 0, effect_, Control());
Return(jsgraph()->SmiConstant(0));
......@@ -6222,7 +6222,7 @@ std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
Handle<JSReceiver> callable, wasm::FunctionSig* expected_sig,
bool has_bigint_feature) {
const wasm::WasmFeatures& enabled_features) {
if (WasmExportedFunction::IsWasmExportedFunction(*callable)) {
auto imported_function = Handle<WasmExportedFunction>::cast(callable);
auto func_index = imported_function->function_index();
......@@ -6257,7 +6257,7 @@ std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
return std::make_pair(WasmImportCallKind::kWasmToCapi, callable);
}
// Assuming we are calling to JS, check whether this would be a runtime error.
if (!wasm::IsJSCompatibleSignature(expected_sig, has_bigint_feature)) {
if (!wasm::IsJSCompatibleSignature(expected_sig, enabled_features)) {
return std::make_pair(WasmImportCallKind::kRuntimeTypeError, callable);
}
// For JavaScript calls, determine whether the target has an arity match
......
......@@ -117,7 +117,7 @@ constexpr WasmImportCallKind kDefaultImportCallKind =
// another target, which is why the ultimate target is returned as well.
V8_EXPORT_PRIVATE std::pair<WasmImportCallKind, Handle<JSReceiver>>
ResolveWasmImportCall(Handle<JSReceiver> callable, wasm::FunctionSig* sig,
bool has_bigint_feature);
const wasm::WasmFeatures& enabled_features);
// Compiles an import call wrapper, which allows WASM to call imports.
V8_EXPORT_PRIVATE wasm::WasmCompilationResult CompileWasmImportCallWrapper(
......
......@@ -1151,8 +1151,7 @@ int AddImportWrapperUnits(NativeModule* native_module,
int num_imported_functions = native_module->num_imported_functions();
for (int func_index = 0; func_index < num_imported_functions; func_index++) {
FunctionSig* sig = native_module->module()->functions[func_index].sig;
bool has_bigint_feature = native_module->enabled_features().bigint;
if (!IsJSCompatibleSignature(sig, has_bigint_feature)) {
if (!IsJSCompatibleSignature(sig, native_module->enabled_features())) {
continue;
}
WasmImportWrapperCache::CacheKey key(compiler::kDefaultImportCallKind, sig);
......
......@@ -837,8 +837,8 @@ bool InstanceBuilder::ProcessImportedFunction(
}
auto js_receiver = Handle<JSReceiver>::cast(value);
FunctionSig* expected_sig = module_->functions[func_index].sig;
auto resolved = compiler::ResolveWasmImportCall(js_receiver, expected_sig,
enabled_.bigint);
auto resolved =
compiler::ResolveWasmImportCall(js_receiver, expected_sig, enabled_);
compiler::WasmImportCallKind kind = resolved.first;
js_receiver = resolved.second;
switch (kind) {
......@@ -1219,8 +1219,7 @@ void InstanceBuilder::CompileImportWrappers(
auto js_receiver = Handle<JSReceiver>::cast(value);
uint32_t func_index = module_->import_table[index].index;
FunctionSig* sig = module_->functions[func_index].sig;
auto resolved =
compiler::ResolveWasmImportCall(js_receiver, sig, enabled_.bigint);
auto resolved = compiler::ResolveWasmImportCall(js_receiver, sig, enabled_);
compiler::WasmImportCallKind kind = resolved.first;
if (kind == compiler::WasmImportCallKind::kWasmToWasm ||
kind == compiler::WasmImportCallKind::kLinkError ||
......
......@@ -3682,7 +3682,7 @@ class ThreadImpl {
WasmFeatures enabled_features = WasmFeaturesFromIsolate(isolate);
if (code->kind() == WasmCode::kWasmToJsWrapper &&
!IsJSCompatibleSignature(sig, enabled_features.bigint)) {
!IsJSCompatibleSignature(sig, enabled_features)) {
Drop(num_args); // Pop arguments before throwing.
isolate->Throw(*isolate->factory()->NewTypeError(
MessageTemplate::kWasmTrapTypeError));
......
......@@ -1948,8 +1948,7 @@ void WasmInstanceObject::ImportWasmJSFunctionIntoTable(
instance->module_object().native_module();
// TODO(mstarzinger): Cache and reuse wrapper code.
const wasm::WasmFeatures enabled = native_module->enabled_features();
auto resolved =
compiler::ResolveWasmImportCall(callable, sig, enabled.bigint);
auto resolved = compiler::ResolveWasmImportCall(callable, sig, enabled);
compiler::WasmImportCallKind kind = resolved.first;
callable = resolved.second; // Update to ultimate target.
DCHECK_NE(compiler::WasmImportCallKind::kLinkError, kind);
......
......@@ -10,6 +10,7 @@
#include "src/codegen/signature.h"
#include "src/execution/messages.h"
#include "src/runtime/runtime.h"
#include "src/wasm/wasm-features.h"
namespace v8 {
namespace internal {
......@@ -446,12 +447,13 @@ std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
return os;
}
bool IsJSCompatibleSignature(const FunctionSig* sig, bool has_bigint_feature) {
if (!FLAG_experimental_wasm_mv && sig->return_count() > 1) {
bool IsJSCompatibleSignature(const FunctionSig* sig,
const WasmFeatures& enabled_features) {
if (!enabled_features.mv && sig->return_count() > 1) {
return false;
}
for (auto type : sig->all()) {
if (!has_bigint_feature && type == kWasmI64) {
if (!enabled_features.bigint && type == kWasmI64) {
return false;
}
......
......@@ -15,8 +15,10 @@ namespace internal {
namespace wasm {
struct WasmFeatures;
std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
bool IsJSCompatibleSignature(const FunctionSig* sig, bool hasBigIntFeature);
bool IsJSCompatibleSignature(const FunctionSig* sig, const WasmFeatures&);
// Control expressions and blocks.
#define FOREACH_CONTROL_OPCODE(V) \
......
......@@ -47,8 +47,8 @@ TestingModuleBuilder::TestingModuleBuilder(
if (maybe_import) {
// Manually compile an import wrapper and insert it into the instance.
CodeSpaceMemoryModificationScope modification_scope(isolate_->heap());
auto resolved = compiler::ResolveWasmImportCall(maybe_import->js_function,
maybe_import->sig, false);
auto resolved = compiler::ResolveWasmImportCall(
maybe_import->js_function, maybe_import->sig, enabled_features_);
compiler::WasmImportCallKind kind = resolved.first;
Handle<JSReceiver> callable = resolved.second;
WasmImportWrapperCache::ModificationScope cache_scope(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment