Commit e7e61ce6 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][anyref] Introduce anyfunc locals

R=titzer@chromium.org

Bug: v8:7581
Change-Id: I153b09ac1676c75590f37c4b7d1f8659c37bbe96
Reviewed-on: https://chromium-review.googlesource.com/c/1421837
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59029}
parent 0b69b05a
......@@ -762,6 +762,15 @@ class WasmDecoder : public Decoder {
}
decoder->error(decoder->pc() - 1, "invalid local type");
return false;
case kLocalAnyFunc:
if (enabled.anyref) {
type = kWasmAnyFunc;
break;
}
decoder->error(decoder->pc() - 1,
"local type 'anyfunc' is not enabled with "
"--experimental-wasm-anyref");
return false;
case kLocalExceptRef:
if (enabled.eh) {
type = kWasmExceptRef;
......
......@@ -644,6 +644,7 @@ class WasmGraphBuildingInterface {
case kWasmS128:
return builder_->S128Zero();
case kWasmAnyRef:
case kWasmAnyFunc:
case kWasmExceptRef:
return builder_->RefNull();
default:
......
......@@ -41,3 +41,85 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
main(main);
})();
(function testPassAnyRefWithGCWithLocals() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
const ref_sig = builder.addType(kSig_v_a);
const void_sig = builder.addType(kSig_v_v);
const imp_index = builder.addImport("q", "func", ref_sig);
const gc_index = builder.addImport("q", "gc", void_sig);
// First call the gc, then check if the object still exists.
builder.addFunction('main', ref_sig)
.addLocals({anyfunc_count: 10})
.addBody([
kExprGetLocal, 0, kExprSetLocal, 1, // Set local
kExprGetLocal, 0, kExprSetLocal, 2, // Set local
kExprGetLocal, 0, kExprSetLocal, 3, // Set local
kExprGetLocal, 0, kExprSetLocal, 4, // Set local
kExprGetLocal, 0, kExprSetLocal, 5, // Set local
kExprGetLocal, 0, kExprSetLocal, 6, // Set local
kExprGetLocal, 0, kExprSetLocal, 7, // Set local
kExprGetLocal, 0, kExprSetLocal, 8, // Set local
kExprGetLocal, 0, kExprSetLocal, 9, // Set local
kExprGetLocal, 0, kExprSetLocal, 10, // Set local
kExprCallFunction, gc_index, // call gc
kExprGetLocal, 9, kExprCallFunction, imp_index // call import
])
.exportFunc();
const main =
builder.instantiate({q: {func: checkFunction, gc: gc}}).exports.main;
function checkFunction(value) {
assertSame(main, value);
}
main(main);
})();
(function testPassAnyRefWithGC() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
const ref_sig = builder.addType(kSig_v_a);
const void_sig = builder.addType(kSig_v_v);
const imp_index = builder.addImport("q", "func", ref_sig);
const gc_index = builder.addImport("q", "gc", void_sig);
// First call the gc, then check if the object still exists.
builder.addFunction('main', ref_sig)
.addBody([
kExprCallFunction, gc_index, // call gc
kExprGetLocal, 0, kExprCallFunction, imp_index // call import
])
.exportFunc();
function checkFunction(value) {
assertSame(main, value);
}
const main = builder.instantiate({q: {func: checkFunction, gc: gc}}).exports.main;
main(main);
})();
(function testPassAnyRefWithGCInWrapper() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
const kSig_a_iai = makeSig([kWasmI32, kWasmAnyFunc, kWasmI32], [kWasmAnyFunc]);
const sig_index = builder.addType(kSig_a_iai);
builder.addFunction('main', sig_index)
.addBody([kExprGetLocal, 1])
.exportFunc();
const main = builder.instantiate().exports.main;
const triggerGCParam = {
valueOf: () => {
gc();
return 17;
}
};
const result = main(triggerGCParam, main, triggerGCParam);
assertSame(main, result);
})();
......@@ -617,6 +617,9 @@ class WasmModuleBuilder {
if (l.anyref_count > 0) {
local_decls.push({count: l.anyref_count, type: kWasmAnyRef});
}
if (l.anyfunc_count > 0) {
local_decls.push({count: l.anyfunc_count, type: kWasmAnyFunc});
}
if (l.except_count > 0) {
local_decls.push({count: l.except_count, type: kWasmExceptRef});
}
......
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