Commit ae5c2ea8 authored by Sven Sauleau's avatar Sven Sauleau Committed by Commit Bot

[wasm] support calling an imported func that returns a i64

It removes the assertion that caused the bug report by introducing a new
trampoline (WasmBigIntToI64) for the conversion code stub between a Bigint
object and a Wasm i64 BigIntToI64).

The tests were updated to cover calling the stub from a Wasm callsite.

Bug: v8:8625
Change-Id: I55891001cfa72f6f2849792293b43bbb54147f1a
Reviewed-on: https://chromium-review.googlesource.com/c/1405028
Commit-Queue: Sven Sauleau <ssauleau@igalia.com>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58767}
parent 9eb278b8
...@@ -1260,6 +1260,7 @@ namespace internal { ...@@ -1260,6 +1260,7 @@ namespace internal {
TFS(ThrowWasmTrapFuncSigMismatch) \ TFS(ThrowWasmTrapFuncSigMismatch) \
TFS(ThrowWasmTrapDataSegmentDropped) \ TFS(ThrowWasmTrapDataSegmentDropped) \
TFC(BigIntToWasmI64, BigIntToWasmI64, 1) \ TFC(BigIntToWasmI64, BigIntToWasmI64, 1) \
TFC(WasmBigIntToI64, BigIntToI64, 1) \
\ \
/* WeakMap */ \ /* WeakMap */ \
TFJ(WeakMapConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(WeakMapConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
...@@ -1551,7 +1552,8 @@ namespace internal { ...@@ -1551,7 +1552,8 @@ namespace internal {
V(WasmToNumber) \ V(WasmToNumber) \
V(WasmThrow) \ V(WasmThrow) \
V(DoubleToI) \ V(DoubleToI) \
V(BigIntToWasmI64) V(BigIntToWasmI64) \
V(WasmBigIntToI64)
// The exception thrown in the following builtins are caught internally and will // The exception thrown in the following builtins are caught internally and will
// not be propagated further or re-thrown // not be propagated further or re-thrown
......
...@@ -233,6 +233,21 @@ TF_BUILTIN(BigIntToWasmI64, WasmBuiltinsAssembler) { ...@@ -233,6 +233,21 @@ TF_BUILTIN(BigIntToWasmI64, WasmBuiltinsAssembler) {
argument); argument);
} }
TF_BUILTIN(WasmBigIntToI64, WasmBuiltinsAssembler) {
if (!Is64()) {
Unreachable();
return;
}
TNode<Object> context =
UncheckedCast<Object>(Parameter(Descriptor::kContext));
TNode<Code> target = LoadBuiltinFromFrame(Builtins::kBigIntToI64);
TNode<IntPtrT> argument =
UncheckedCast<IntPtrT>(Parameter(Descriptor::kArgument));
TailCallStub(BigIntToI64Descriptor(), target, context, argument);
}
#define DECLARE_ENUM(name) \ #define DECLARE_ENUM(name) \
TF_BUILTIN(ThrowWasm##name, WasmBuiltinsAssembler) { \ TF_BUILTIN(ThrowWasm##name, WasmBuiltinsAssembler) { \
TNode<Object> instance = LoadInstanceFromFrame(); \ TNode<Object> instance = LoadInstanceFromFrame(); \
......
...@@ -4710,8 +4710,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4710,8 +4710,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
Node* BuildChangeBigIntToInt64(Node* input, Node* context) { Node* BuildChangeBigIntToInt64(Node* input, Node* context) {
DCHECK_EQ(stub_mode_, StubCallMode::kCallCodeObject);
BigIntToI64Descriptor interface_descriptor; BigIntToI64Descriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor( auto call_descriptor = Linkage::GetStubCallDescriptor(
...@@ -4720,9 +4718,13 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4720,9 +4718,13 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
interface_descriptor.GetStackParameterCount(), // stack parameter count interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties Operator::kNoProperties, // properties
StubCallMode::kCallCodeObject); // stub call mode stub_mode_); // stub call mode
Node* target = jsgraph()->HeapConstant(BUILTIN_CODE(isolate_, BigIntToI64)); Node* target =
(stub_mode_ == StubCallMode::kCallWasmRuntimeStub)
? mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmBigIntToI64, RelocInfo::WASM_STUB_CALL)
: jsgraph()->HeapConstant(BUILTIN_CODE(isolate_, BigIntToI64));
return SetEffect(SetControl( return SetEffect(SetControl(
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), target, graph()->NewNode(mcgraph()->common()->Call(call_descriptor), target,
......
...@@ -27,12 +27,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -27,12 +27,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var a_index = builder var a_index = builder
.addImport("a", "a", kSig_v_l) // i64 -> () .addImport("a", "a", kSig_l_l) // i64 -> i64
builder builder
.addFunction("fn", kSig_v_v) // () -> () .addFunction("fn", kSig_l_v) // () -> i64
.addBody([ .addBody([
kExprI64Const, 0x1, kExprI64Const, 0x7,
kExprCallFunction, a_index kExprCallFunction, a_index
]) ])
.exportFunc(); .exportFunc();
...@@ -43,13 +43,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -43,13 +43,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
a: { a: {
a(param) { a(param) {
assertEquals(typeof param, "bigint"); assertEquals(typeof param, "bigint");
assertEquals(param, 1n); assertEquals(param, 7n);
a_was_called = true; a_was_called = true;
return 12n;
}, },
} }
}); });
module.exports.fn(); assertEquals(module.exports.fn(), 12n);
assertTrue(a_was_called); assertTrue(a_was_called);
})(); })();
......
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