Commit 6b6fc8dd authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove Result::MoveErrorFrom

This is the last method which modified the Result after construction.
Turn this into a named constructor instead.

Drive-by: Replace a Result<bool> by VoidResult, since the bool is not
used anywhere.

R=mstarzinger@chromium.org

Bug: v8:8238
Change-Id: I352e0687e99a90e6ad00587d6fdf388f68c9b60a
Reviewed-on: https://chromium-review.googlesource.com/c/1296271
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56897}
parent 9716f689
...@@ -5165,7 +5165,8 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -5165,7 +5165,8 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
StdoutStream{} << "Compilation failed: " StdoutStream{} << "Compilation failed: "
<< graph_construction_result.error_msg() << std::endl; << graph_construction_result.error_msg() << std::endl;
} }
wasm_unit_->result_.MoveErrorFrom(graph_construction_result); wasm_unit_->result_ = wasm::Result<wasm::WasmCode*>::ErrorFrom(
std::move(graph_construction_result));
return nullptr; return nullptr;
} }
......
...@@ -2641,14 +2641,14 @@ AsyncStreamingProcessor::AsyncStreamingProcessor(AsyncCompileJob* job) ...@@ -2641,14 +2641,14 @@ AsyncStreamingProcessor::AsyncStreamingProcessor(AsyncCompileJob* job)
compilation_unit_builder_(nullptr) {} compilation_unit_builder_(nullptr) {}
void AsyncStreamingProcessor::FinishAsyncCompileJobWithError(ResultBase error) { void AsyncStreamingProcessor::FinishAsyncCompileJobWithError(ResultBase error) {
DCHECK(error.failed());
// Make sure all background tasks stopped executing before we change the state // Make sure all background tasks stopped executing before we change the state
// of the AsyncCompileJob to DecodeFail. // of the AsyncCompileJob to DecodeFail.
job_->background_task_manager_.CancelAndWait(); job_->background_task_manager_.CancelAndWait();
// Create a ModuleResult from the result we got as parameter. Since there was // Create a ModuleResult from the result we got as parameter. Since there was
// no error, we don't have to provide a real wasm module to the ModuleResult. // an error, we don't have to provide a real wasm module to the ModuleResult.
ModuleResult result(nullptr); ModuleResult result = ModuleResult::ErrorFrom(std::move(error));
result.MoveErrorFrom(error);
// Check if there is already a CompiledModule, in which case we have to clean // Check if there is already a CompiledModule, in which case we have to clean
// up the CompilationState as well. // up the CompilationState as well.
......
...@@ -906,9 +906,9 @@ class ModuleDecoderImpl : public Decoder { ...@@ -906,9 +906,9 @@ class ModuleDecoderImpl : public Decoder {
CalculateGlobalOffsets(module_.get()); CalculateGlobalOffsets(module_.get());
} }
ModuleResult result = toResult(std::move(module_)); ModuleResult result = toResult(std::move(module_));
if (verify_functions && result.ok()) { if (verify_functions && result.ok() && intermediate_result_.failed()) {
// Copy error code and location. // Copy error code and location.
result.MoveErrorFrom(intermediate_result_); result = ModuleResult::ErrorFrom(std::move(intermediate_result_));
} }
return result; return result;
} }
...@@ -963,10 +963,11 @@ class ModuleDecoderImpl : public Decoder { ...@@ -963,10 +963,11 @@ class ModuleDecoderImpl : public Decoder {
VerifyFunctionBody(zone->allocator(), 0, wire_bytes, module, VerifyFunctionBody(zone->allocator(), 0, wire_bytes, module,
function.get()); function.get());
FunctionResult result(std::move(function)); if (intermediate_result_.failed()) {
// Copy error code and location. return FunctionResult::ErrorFrom(std::move(intermediate_result_));
result.MoveErrorFrom(intermediate_result_); }
return result;
return FunctionResult(std::move(function));
} }
// Decodes a single function signature at {start}. // Decodes a single function signature at {start}.
...@@ -1010,7 +1011,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1010,7 +1011,7 @@ class ModuleDecoderImpl : public Decoder {
sizeof(ModuleDecoderImpl::seen_unordered_sections_) > sizeof(ModuleDecoderImpl::seen_unordered_sections_) >
kLastKnownModuleSection, kLastKnownModuleSection,
"not enough bits"); "not enough bits");
Result<bool> intermediate_result_; VoidResult intermediate_result_;
ModuleOrigin origin_; ModuleOrigin origin_;
uint32_t off(const byte* ptr) { uint32_t off(const byte* ptr) {
...@@ -1128,16 +1129,14 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1128,16 +1129,14 @@ class ModuleDecoderImpl : public Decoder {
&unused_detected_features, body); &unused_detected_features, body);
} }
if (result.failed()) { // If the decode failed and this is the first error, set error code and
// location.
if (result.failed() && intermediate_result_.ok()) {
// Wrap the error message from the function decoder. // Wrap the error message from the function decoder.
std::ostringstream wrapped; std::ostringstream error_msg;
wrapped << "in function " << func_name << ": " << result.error_msg(); error_msg << "in function " << func_name << ": " << result.error_msg();
result = DecodeResult::Error(result.error_offset(), wrapped.str()); intermediate_result_ =
VoidResult::Error(result.error_offset(), error_msg.str());
// Set error code and location, if this is the first error.
if (intermediate_result_.ok()) {
intermediate_result_.MoveErrorFrom(result);
}
} }
} }
......
...@@ -33,19 +33,12 @@ class V8_EXPORT_PRIVATE ResultBase { ...@@ -33,19 +33,12 @@ class V8_EXPORT_PRIVATE ResultBase {
: error_offset_(other.error_offset_), : error_offset_(other.error_offset_),
error_msg_(std::move(other.error_msg_)) {} error_msg_(std::move(other.error_msg_)) {}
void MoveErrorFrom(ResultBase& that) {
error_offset_ = that.error_offset_;
// Use {swap()} + {clear()} instead of move assign, as {that} might still
// be used afterwards.
error_msg_.swap(that.error_msg_);
that.error_msg_.clear();
}
bool ok() const { return error_msg_.empty(); } bool ok() const { return error_msg_.empty(); }
bool failed() const { return !ok(); } bool failed() const { return !ok(); }
uint32_t error_offset() const { return error_offset_; } uint32_t error_offset() const { return error_offset_; }
const std::string& error_msg() const { return error_msg_; } const std::string& error_msg() const & { return error_msg_; }
std::string&& error_msg() && { return std::move(error_msg_); }
protected: protected:
ResultBase(uint32_t error_offset, std::string error_msg) ResultBase(uint32_t error_offset, std::string error_msg)
...@@ -90,6 +83,11 @@ class Result : public ResultBase { ...@@ -90,6 +83,11 @@ class Result : public ResultBase {
return Result<T>{error_offset, std::move(error_msg)}; return Result<T>{error_offset, std::move(error_msg)};
} }
static Result<T> ErrorFrom(ResultBase&& error_result) {
return Error(error_result.error_offset(),
std::move(error_result).error_msg());
}
// Accessor for the value. Returns const reference if {this} is l-value or // 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 // const, and returns r-value reference if {this} is r-value. This allows to
// extract non-copyable values like {std::unique_ptr} by using // extract non-copyable values like {std::unique_ptr} by using
......
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