Commit 7921b73a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Use getter for WasmResult::value

Previously, this was just a field on the WasmResult, which is not
allowed according to the style guide.
A special r-value accessor for the value is needed for the cases where
the contained type is not copyable, e.g. unique_ptr.

R=titzer@chromium.org

Bug: v8:8238
Change-Id: Ia3c14c4c62c3c2e07f1dc4594f1bc9d1da88f91e
Reviewed-on: https://chromium-review.googlesource.com/c/1290974
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56823}
parent f8d6c4c0
...@@ -2429,7 +2429,7 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep { ...@@ -2429,7 +2429,7 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep {
job_->DoSync<DecodeFail>(std::move(result)); job_->DoSync<DecodeFail>(std::move(result));
} else { } else {
// Decode passed. // Decode passed.
job_->DoSync<PrepareAndStartCompile>(std::move(result.val), true); job_->DoSync<PrepareAndStartCompile>(std::move(result).value(), true);
} }
} }
}; };
...@@ -2797,7 +2797,8 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) { ...@@ -2797,7 +2797,8 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) {
// prepare compilation first before we can finish it. // prepare compilation first before we can finish it.
// {PrepareAndStartCompile} will call {FinishCompile} by itself if there // {PrepareAndStartCompile} will call {FinishCompile} by itself if there
// is no code section. // is no code section.
job_->DoSync<AsyncCompileJob::PrepareAndStartCompile>(result.val, true); job_->DoSync<AsyncCompileJob::PrepareAndStartCompile>(
std::move(result).value(), true);
} else { } else {
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
SaveContext saved_context(job_->isolate_); SaveContext saved_context(job_->isolate_);
......
...@@ -1485,7 +1485,7 @@ ModuleResult DecodeWasmModule(const WasmFeatures& enabled, ...@@ -1485,7 +1485,7 @@ ModuleResult DecodeWasmModule(const WasmFeatures& enabled,
auto peak_counter = SELECT_WASM_COUNTER(counters, origin, wasm_decode, auto peak_counter = SELECT_WASM_COUNTER(counters, origin, wasm_decode,
module_peak_memory_bytes); module_peak_memory_bytes);
peak_counter->AddSample( peak_counter->AddSample(
static_cast<int>(result.val->signature_zone->allocation_size())); static_cast<int>(result.value()->signature_zone->allocation_size()));
} }
return result; return result;
} }
......
...@@ -50,7 +50,7 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompileTranslatedAsmJs( ...@@ -50,7 +50,7 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompileTranslatedAsmJs(
// Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated // Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated
// in {CompileToModuleObject}. // in {CompileToModuleObject}.
return CompileToModuleObject(isolate, kAsmjsWasmFeatures, thrower, return CompileToModuleObject(isolate, kAsmjsWasmFeatures, thrower,
std::move(result.val), bytes, asm_js_script, std::move(result).value(), bytes, asm_js_script,
asm_js_offset_table_bytes); asm_js_offset_table_bytes);
} }
...@@ -67,8 +67,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile( ...@@ -67,8 +67,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile(
// Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated // Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated
// in {CompileToModuleObject}. // in {CompileToModuleObject}.
return CompileToModuleObject(isolate, enabled, thrower, std::move(result.val), return CompileToModuleObject(isolate, enabled, thrower,
bytes, Handle<Script>(), Vector<const byte>()); std::move(result).value(), bytes,
Handle<Script>(), Vector<const byte>());
} }
MaybeHandle<WasmInstanceObject> WasmEngine::SyncInstantiate( MaybeHandle<WasmInstanceObject> WasmEngine::SyncInstantiate(
......
...@@ -412,25 +412,24 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( ...@@ -412,25 +412,24 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
DCHECK(table_type == Encoded || table_type == Decoded); DCHECK(table_type == Encoded || table_type == Decoded);
if (table_type == Decoded) return offset_table; if (table_type == Decoded) return offset_table;
wasm::AsmJsOffsetsResult asm_offsets; wasm::AsmJsOffsets asm_offsets;
{ {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
byte* bytes_start = offset_table->GetDataStartAddress(); byte* bytes_start = offset_table->GetDataStartAddress();
byte* bytes_end = reinterpret_cast<byte*>( byte* bytes_end = reinterpret_cast<byte*>(
reinterpret_cast<Address>(bytes_start) + offset_table->length() - 1); reinterpret_cast<Address>(bytes_start) + offset_table->length() - 1);
asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end); asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end).value();
} }
// Wasm bytes must be valid and must contain asm.js offset table. // Wasm bytes must be valid and must contain asm.js offset table.
DCHECK(asm_offsets.ok()); DCHECK_GE(kMaxInt, asm_offsets.size());
DCHECK_GE(kMaxInt, asm_offsets.val.size()); int num_functions = static_cast<int>(asm_offsets.size());
int num_functions = static_cast<int>(asm_offsets.val.size());
int num_imported_functions = int num_imported_functions =
static_cast<int>(module_object->module()->num_imported_functions); static_cast<int>(module_object->module()->num_imported_functions);
DCHECK_EQ(module_object->module()->functions.size(), DCHECK_EQ(module_object->module()->functions.size(),
static_cast<size_t>(num_functions) + num_imported_functions); static_cast<size_t>(num_functions) + num_imported_functions);
int num_entries = 0; int num_entries = 0;
for (int func = 0; func < num_functions; ++func) { for (int func = 0; func < num_functions; ++func) {
size_t new_size = asm_offsets.val[func].size(); size_t new_size = asm_offsets[func].size();
DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - num_entries); DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - num_entries);
num_entries += static_cast<int>(new_size); num_entries += static_cast<int>(new_size);
} }
...@@ -447,8 +446,7 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( ...@@ -447,8 +446,7 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
const std::vector<WasmFunction>& wasm_funs = const std::vector<WasmFunction>& wasm_funs =
module_object->module()->functions; module_object->module()->functions;
for (int func = 0; func < num_functions; ++func) { for (int func = 0; func < num_functions; ++func) {
std::vector<wasm::AsmJsOffsetEntry>& func_asm_offsets = std::vector<wasm::AsmJsOffsetEntry>& func_asm_offsets = asm_offsets[func];
asm_offsets.val[func];
if (func_asm_offsets.empty()) continue; if (func_asm_offsets.empty()) continue;
int func_offset = wasm_funs[num_imported_functions + func].code.offset(); int func_offset = wasm_funs[num_imported_functions + func].code.offset();
for (wasm::AsmJsOffsetEntry& e : func_asm_offsets) { for (wasm::AsmJsOffsetEntry& e : func_asm_offsets) {
......
...@@ -70,11 +70,11 @@ class Result : public ResultBase { ...@@ -70,11 +70,11 @@ class Result : public ResultBase {
Result() = default; Result() = default;
template <typename S> template <typename S>
explicit Result(S&& value) : val(std::forward<S>(value)) {} explicit Result(S&& value) : value_(std::forward<S>(value)) {}
template <typename S> template <typename S>
Result(Result<S>&& other) V8_NOEXCEPT : ResultBase(std::move(other)), Result(Result<S>&& other) V8_NOEXCEPT : ResultBase(std::move(other)),
val(std::move(other.val)) {} value_(std::move(other).value()) {}
Result& operator=(Result&& other) V8_NOEXCEPT = default; Result& operator=(Result&& other) V8_NOEXCEPT = default;
...@@ -87,9 +87,22 @@ class Result : public ResultBase { ...@@ -87,9 +87,22 @@ class Result : public ResultBase {
return result; return result;
} }
T val = T{}; // Accessor for the value. Returns const reference if {this} is l-value or
// const, and returns r-value reference if {this} is r-value. This allows to
// extract non-copyable values like {std::unique_ptr} by using
// {std::move(result).value()}.
const T& value() const & {
DCHECK(ok());
return value_;
}
T&& value() && {
DCHECK(ok());
return std::move(value_);
}
private: private:
T value_ = T{};
DISALLOW_COPY_AND_ASSIGN(Result); DISALLOW_COPY_AND_ASSIGN(Result);
}; };
......
...@@ -549,9 +549,9 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -549,9 +549,9 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
ModuleResult decode_result = DecodeWasmModule( ModuleResult decode_result = DecodeWasmModule(
enabled_features, wire_bytes.start(), wire_bytes.end(), false, enabled_features, wire_bytes.start(), wire_bytes.end(), false,
i::wasm::kWasmOrigin, isolate->counters(), isolate->allocator()); i::wasm::kWasmOrigin, isolate->counters(), isolate->allocator());
if (!decode_result.ok()) return {}; if (decode_result.failed()) return {};
CHECK_NOT_NULL(decode_result.val); CHECK_NOT_NULL(decode_result.value());
WasmModule* module = decode_result.val.get(); WasmModule* module = decode_result.value().get();
Handle<Script> script = Handle<Script> script =
CreateWasmScript(isolate, wire_bytes, module->source_map_url); CreateWasmScript(isolate, wire_bytes, module->source_map_url);
...@@ -565,7 +565,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -565,7 +565,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
OwnedVector<uint8_t> wire_bytes_copy = OwnedVector<uint8_t>::Of(wire_bytes); OwnedVector<uint8_t> wire_bytes_copy = OwnedVector<uint8_t>::Of(wire_bytes);
Handle<WasmModuleObject> module_object = WasmModuleObject::New( Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, enabled_features, std::move(decode_result.val), env, isolate, enabled_features, std::move(decode_result).value(), env,
std::move(wire_bytes_copy), script, Handle<ByteArray>::null()); std::move(wire_bytes_copy), script, Handle<ByteArray>::null());
NativeModule* native_module = module_object->native_module(); NativeModule* native_module = module_object->native_module();
......
...@@ -257,7 +257,7 @@ size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer, ...@@ -257,7 +257,7 @@ size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer,
kAllWasmFeatures, buffer, buffer + size, false, ModuleOrigin::kWasmOrigin, kAllWasmFeatures, buffer, buffer + size, false, ModuleOrigin::kWasmOrigin,
isolate->counters(), isolate->allocator()); isolate->counters(), isolate->allocator());
CHECK(result.ok()); CHECK(result.ok());
const WasmFunction* func = &result.val->functions[1]; const WasmFunction* func = &result.value()->functions[1];
return func->code.offset(); return func->code.offset();
} }
......
...@@ -54,7 +54,7 @@ std::shared_ptr<WasmModule> DecodeWasmModuleForTesting( ...@@ -54,7 +54,7 @@ std::shared_ptr<WasmModule> DecodeWasmModuleForTesting(
decoding_result.error_msg().c_str()); decoding_result.error_msg().c_str());
} }
return std::move(decoding_result.val); return std::move(decoding_result).value();
} }
bool InterpretWasmModuleForTesting(Isolate* isolate, bool InterpretWasmModuleForTesting(Isolate* isolate,
......
...@@ -158,7 +158,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes, ...@@ -158,7 +158,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
enabled_features, wire_bytes.start(), wire_bytes.end(), kVerifyFunctions, enabled_features, wire_bytes.start(), wire_bytes.end(), kVerifyFunctions,
ModuleOrigin::kWasmOrigin, isolate->counters(), isolate->allocator()); ModuleOrigin::kWasmOrigin, isolate->counters(), isolate->allocator());
CHECK(module_res.ok()); CHECK(module_res.ok());
WasmModule* module = module_res.val.get(); WasmModule* module = module_res.value().get();
CHECK_NOT_NULL(module); CHECK_NOT_NULL(module);
StdoutStream os; StdoutStream os;
......
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