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

Revert "[wasm] Store signature with {WebAssembly.Function} objects."

This reverts commit 8092acbe.

Reason for revert: Causes UBSan warnings:
https://ci.chromium.org/p/v8/builders/ci/V8%20Linux64%20UBSan/6436

Original change's description:
> [wasm] Store signature with {WebAssembly.Function} objects.
> 
> This adds simple serialization and deserialization of the signature
> provided when a {WebAssembly.Function} object is constructed. For now
> this signature is only used by the {WebAssembly.Function.type} method,
> but will soon be used when importing such functions as well.
> 
> R=​jkummerow@chromium.org
> TEST=mjsunit/wasm/type-reflection
> BUG=v8:7742
> 
> Change-Id: If4a687ea537d8c12f4f01a7d3ac5a795ceb999c6
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1632211
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61898}

TBR=jkummerow@chromium.org,mstarzinger@chromium.org

Change-Id: I56ea9df5db3f95c05068186097e298cb73a3675d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7742
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1632218Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61899}
parent 8092acbe
...@@ -878,12 +878,7 @@ extern class WasmExportedFunctionData extends Struct { ...@@ -878,12 +878,7 @@ extern class WasmExportedFunctionData extends Struct {
function_index: Smi; function_index: Smi;
} }
extern class WasmJSFunctionData extends Struct { extern class WasmJSFunctionData extends Struct { wrapper_code: Code; }
wrapper_code: Code;
serialized_return_count: Smi;
serialized_parameter_count: Smi;
serialized_signature: ByteArray; // PodArray<wasm::ValueType>
}
extern class WasmCapiFunctionData extends Struct { extern class WasmCapiFunctionData extends Struct {
call_target: RawPtr; call_target: RawPtr;
......
...@@ -552,9 +552,9 @@ class PodArray : public ByteArray { ...@@ -552,9 +552,9 @@ class PodArray : public ByteArray {
static Handle<PodArray<T>> New( static Handle<PodArray<T>> New(
Isolate* isolate, int length, Isolate* isolate, int length,
AllocationType allocation = AllocationType::kYoung); AllocationType allocation = AllocationType::kYoung);
void copy_out(int index, T* result, int length) { void copy_out(int index, T* result) {
ByteArray::copy_out(index * sizeof(T), reinterpret_cast<byte*>(result), ByteArray::copy_out(index * sizeof(T), reinterpret_cast<byte*>(result),
length * sizeof(T)); sizeof(T));
} }
void copy_in(int index, const T* buffer, int length) { void copy_in(int index, const T* buffer, int length) {
...@@ -564,7 +564,7 @@ class PodArray : public ByteArray { ...@@ -564,7 +564,7 @@ class PodArray : public ByteArray {
T get(int index) { T get(int index) {
T result; T result;
copy_out(index, &result, 1); copy_out(index, &result);
return result; return result;
} }
......
...@@ -1437,7 +1437,7 @@ void WebAssemblyFunction(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1437,7 +1437,7 @@ void WebAssemblyFunction(const v8::FunctionCallbackInfo<v8::Value>& args) {
// Decode the function type and construct a signature. // Decode the function type and construct a signature.
i::Zone zone(i_isolate->allocator(), ZONE_NAME); i::Zone zone(i_isolate->allocator(), ZONE_NAME);
i::wasm::FunctionSig::Builder builder(&zone, results_len, parameters_len); i::wasm::FunctionSig::Builder builder(&zone, parameters_len, results_len);
for (uint32_t i = 0; i < parameters_len; ++i) { for (uint32_t i = 0; i < parameters_len; ++i) {
i::wasm::ValueType type; i::wasm::ValueType type;
MaybeLocal<Value> maybe = parameters->Get(context, i); MaybeLocal<Value> maybe = parameters->Get(context, i);
...@@ -1513,12 +1513,13 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1513,12 +1513,13 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) {
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Function.type()"); ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Function.type()");
i::wasm::FunctionSig* sig; i::wasm::FunctionSig* sig;
i::Zone zone(i_isolate->allocator(), ZONE_NAME);
i::Handle<i::Object> arg0 = Utils::OpenHandle(*args[0]); i::Handle<i::Object> arg0 = Utils::OpenHandle(*args[0]);
if (i::WasmExportedFunction::IsWasmExportedFunction(*arg0)) { if (i::WasmExportedFunction::IsWasmExportedFunction(*arg0)) {
sig = i::Handle<i::WasmExportedFunction>::cast(arg0)->sig(); sig = i::Handle<i::WasmExportedFunction>::cast(arg0)->sig();
} else if (i::WasmJSFunction::IsWasmJSFunction(*arg0)) { } else if (i::WasmJSFunction::IsWasmJSFunction(*arg0)) {
sig = i::Handle<i::WasmJSFunction>::cast(arg0)->GetSignature(&zone); // TODO(7742): Implement deserialization of signature.
sig = nullptr;
UNIMPLEMENTED();
} else { } else {
thrower.TypeError("Argument 0 must be a WebAssembly.Function"); thrower.TypeError("Argument 0 must be a WebAssembly.Function");
return; return;
......
...@@ -317,12 +317,6 @@ CAST_ACCESSOR(WasmJSFunction) ...@@ -317,12 +317,6 @@ CAST_ACCESSOR(WasmJSFunction)
// WasmJSFunctionData // WasmJSFunctionData
OBJECT_CONSTRUCTORS_IMPL(WasmJSFunctionData, Struct) OBJECT_CONSTRUCTORS_IMPL(WasmJSFunctionData, Struct)
CAST_ACCESSOR(WasmJSFunctionData) CAST_ACCESSOR(WasmJSFunctionData)
SMI_ACCESSORS(WasmJSFunctionData, serialized_return_count,
kSerializedReturnCountOffset)
SMI_ACCESSORS(WasmJSFunctionData, serialized_parameter_count,
kSerializedParameterCountOffset)
ACCESSORS(WasmJSFunctionData, serialized_signature, PodArray<wasm::ValueType>,
kSerializedSignatureOffset)
ACCESSORS(WasmJSFunctionData, wrapper_code, Code, kWrapperCodeOffset) ACCESSORS(WasmJSFunctionData, wrapper_code, Code, kWrapperCodeOffset)
// WasmCapiFunction // WasmCapiFunction
......
...@@ -2143,19 +2143,9 @@ bool WasmJSFunction::IsWasmJSFunction(Object object) { ...@@ -2143,19 +2143,9 @@ bool WasmJSFunction::IsWasmJSFunction(Object object) {
Handle<WasmJSFunction> WasmJSFunction::New(Isolate* isolate, Handle<WasmJSFunction> WasmJSFunction::New(Isolate* isolate,
wasm::FunctionSig* sig, wasm::FunctionSig* sig,
Handle<JSReceiver> callable) { Handle<JSReceiver> callable) {
DCHECK_LE(sig->all().size(), kMaxInt);
int sig_size = static_cast<int>(sig->all().size());
int return_count = static_cast<int>(sig->return_count());
int parameter_count = static_cast<int>(sig->parameter_count());
Handle<PodArray<wasm::ValueType>> serialized_sig =
PodArray<wasm::ValueType>::New(isolate, sig_size, AllocationType::kOld);
serialized_sig->copy_in(0, sig->all().begin(), sig_size);
Handle<WasmJSFunctionData> function_data = Handle<WasmJSFunctionData> function_data =
Handle<WasmJSFunctionData>::cast(isolate->factory()->NewStruct( Handle<WasmJSFunctionData>::cast(isolate->factory()->NewStruct(
WASM_JS_FUNCTION_DATA_TYPE, AllocationType::kOld)); WASM_JS_FUNCTION_DATA_TYPE, AllocationType::kOld));
function_data->set_serialized_return_count(return_count);
function_data->set_serialized_parameter_count(parameter_count);
function_data->set_serialized_signature(*serialized_sig);
// TODO(7742): Make this callable by using a proper wrapper code. // TODO(7742): Make this callable by using a proper wrapper code.
function_data->set_wrapper_code( function_data->set_wrapper_code(
isolate->builtins()->builtin(Builtins::kIllegal)); isolate->builtins()->builtin(Builtins::kIllegal));
...@@ -2170,16 +2160,6 @@ Handle<WasmJSFunction> WasmJSFunction::New(Isolate* isolate, ...@@ -2170,16 +2160,6 @@ Handle<WasmJSFunction> WasmJSFunction::New(Isolate* isolate,
return Handle<WasmJSFunction>::cast(js_function); return Handle<WasmJSFunction>::cast(js_function);
} }
wasm::FunctionSig* WasmJSFunction::GetSignature(Zone* zone) {
WasmJSFunctionData function_data = shared().wasm_js_function_data();
int sig_size = function_data.serialized_signature().length();
wasm::ValueType* types = zone->NewArray<wasm::ValueType>(sig_size);
function_data.serialized_signature().copy_out(0, types, sig_size);
int return_count = function_data.serialized_return_count();
int parameter_count = function_data.serialized_parameter_count();
return new (zone) wasm::FunctionSig(return_count, parameter_count, types);
}
Address WasmCapiFunction::GetHostCallTarget() const { Address WasmCapiFunction::GetHostCallTarget() const {
return shared().wasm_capi_function_data().call_target(); return shared().wasm_capi_function_data().call_target();
} }
......
...@@ -681,10 +681,6 @@ class WasmJSFunction : public JSFunction { ...@@ -681,10 +681,6 @@ class WasmJSFunction : public JSFunction {
static Handle<WasmJSFunction> New(Isolate* isolate, wasm::FunctionSig* sig, static Handle<WasmJSFunction> New(Isolate* isolate, wasm::FunctionSig* sig,
Handle<JSReceiver> callable); Handle<JSReceiver> callable);
// Deserializes the signature of this function using the provided zone. Note
// that lifetime of the signature is hence directly coupled to the zone.
wasm::FunctionSig* GetSignature(Zone* zone);
DECL_CAST(WasmJSFunction) DECL_CAST(WasmJSFunction)
OBJECT_CONSTRUCTORS(WasmJSFunction, JSFunction); OBJECT_CONSTRUCTORS(WasmJSFunction, JSFunction);
}; };
...@@ -758,9 +754,6 @@ class WasmExportedFunctionData : public Struct { ...@@ -758,9 +754,6 @@ class WasmExportedFunctionData : public Struct {
// {SharedFunctionInfo::HasWasmJSFunctionData} predicate. // {SharedFunctionInfo::HasWasmJSFunctionData} predicate.
class WasmJSFunctionData : public Struct { class WasmJSFunctionData : public Struct {
public: public:
DECL_INT_ACCESSORS(serialized_return_count)
DECL_INT_ACCESSORS(serialized_parameter_count)
DECL_ACCESSORS(serialized_signature, PodArray<wasm::ValueType>)
DECL_ACCESSORS(wrapper_code, Code) DECL_ACCESSORS(wrapper_code, Code)
DECL_CAST(WasmJSFunctionData) DECL_CAST(WasmJSFunctionData)
......
...@@ -239,21 +239,6 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -239,21 +239,6 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertDoesNotThrow(() => fun()); assertDoesNotThrow(() => fun());
})(); })();
(function TestFunctionTypeOfConstructedFunction() {
let testcases = [
{parameters:[], results:[]},
{parameters:["i32"], results:[]},
{parameters:["i64"], results:["i32"]},
{parameters:["f64", "f64", "i32"], results:[]},
{parameters:["f32"], results:["f32"]},
];
testcases.forEach(function(expected) {
let fun = new WebAssembly.Function(expected, _ => 0);
let type = WebAssembly.Function.type(fun);
assertEquals(expected, type)
});
})();
(function TestFunctionTypeOfExportedFunction() { (function TestFunctionTypeOfExportedFunction() {
let testcases = [ let testcases = [
[kSig_v_v, {parameters:[], results:[]}], [kSig_v_v, {parameters:[], results:[]}],
......
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