Commit 8d0c71d7 authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm][lazy] Fix error message of async compilation

Async compilation with lazy compilation generated an error message that
did not include the function name. With this CL the function name now
gets included.

R=clemensb@chromium.org

Bug: v8:12852
Change-Id: Ia8aed83a2114a2c9da1367045404b20fa8554c8a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3804863
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82172}
parent 5c7e3230
......@@ -1063,23 +1063,29 @@ class CompilationUnitBuilder {
js_to_wasm_wrapper_units_;
};
void SetCompileError(ErrorThrower* thrower, ModuleWireBytes wire_bytes,
const WasmFunction* func, const WasmModule* module,
WasmError error) {
WasmError GetWasmErrorWithName(ModuleWireBytes wire_bytes,
const WasmFunction* func,
const WasmModule* module, WasmError error) {
WasmName name = wire_bytes.GetNameOrNull(func, module);
if (name.begin() == nullptr) {
thrower->CompileError("Compiling function #%d failed: %s @+%u",
func->func_index, error.message().c_str(),
error.offset());
return WasmError(error.offset(), "Compiling function #%d failed: %s",
func->func_index, error.message().c_str());
} else {
TruncatedUserString<> truncated_name(name);
thrower->CompileError("Compiling function #%d:\"%.*s\" failed: %s @+%u",
func->func_index, truncated_name.length(),
truncated_name.start(), error.message().c_str(),
error.offset());
return WasmError(error.offset(),
"Compiling function #%d:\"%.*s\" failed: %s",
func->func_index, truncated_name.length(),
truncated_name.start(), error.message().c_str());
}
}
void SetCompileError(ErrorThrower* thrower, ModuleWireBytes wire_bytes,
const WasmFunction* func, const WasmModule* module,
WasmError error) {
thrower->CompileFailed(GetWasmErrorWithName(std::move(wire_bytes), func,
module, std::move(error)));
}
DecodeResult ValidateSingleFunction(const WasmModule* module, int func_index,
base::Vector<const uint8_t> code,
AccountingAllocator* allocator,
......@@ -2547,7 +2553,10 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep {
DecodeResult function_result = ValidateSingleFunction(
module, func_index, code, allocator, enabled_features);
if (function_result.failed()) {
result = ModuleResult(function_result.error());
WasmError error = function_result.error();
WasmError error_with_name = GetWasmErrorWithName(
job->wire_bytes_, func, module, std::move(error));
result = ModuleResult(std::move(error_with_name));
break;
}
}
......
......@@ -10,19 +10,22 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("some", kSig_i_ii)
assertPromiseResult(WebAssembly.compile(builder.toBuffer())
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): function body must " +
"end with \"end\" opcode @+26",
error.message)));
assertPromiseResult(
WebAssembly.compile(builder.toBuffer())
.then(
assertUnreachable,
error => assertEquals(
'WebAssembly.compile(): Compiling function #0:"some" ' +
'failed: function body must end with "end" opcode @+26',
error.message)));
})();
(function testLazyModuleSyncCompilation() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("some", kSig_i_ii)
assertThrows(() => builder.toModule(),
WebAssembly.CompileError,
"WebAssembly.Module(): Compiling function #0:\"some\" failed: " +
"function body must end with \"end\" opcode @+26");
assertThrows(
() => builder.toModule(), WebAssembly.CompileError,
'WebAssembly.Module(): Compiling function #0:"some" failed: function ' +
'body must end with "end" opcode @+26');
})();
......@@ -32,10 +32,12 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
kCompilationHintTierDefault)
.exportFunc();
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compile(bytes)
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): type error in " +
"fallthru[0] (expected i32, got i64) @+56", error.message)));
assertPromiseResult(WebAssembly.compile(bytes).then(
assertUnreachable,
error => assertEquals(
'WebAssembly.compile(): Compiling function #0:"id" failed: type ' +
'error in fallthru[0] (expected i32, got i64) @+56',
error.message)));
})();
(function testCompileEmptyModule() {
......
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