Commit 58ca2115 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Introduce base::Optional, cloned from chromium

base::Optional is a replacement for std::optional, until we switch to
C++17 and can use std::optional directly.
The implementation is copied from chromium's base::Optional, but put in
the {v8::base} namespace instead of just {base}. Also, the
specialization of std::hash for base::Optional is omitted, since it's
disallowed in the style guide.

A first use in the AsmJsParser is introduced, if that one sticks, I
will refactor more uses of std::unique_ptr to use base::Optional
instead, avoiding the heap allocation.

R=mstarzinger@chromium.org
BUG=v8:6474

Change-Id: I019599d4bf9ff0105bf592dfb96d6050feba18ae
Reviewed-on: https://chromium-review.googlesource.com/528884
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45810}
parent 4424f5d1
......@@ -2513,6 +2513,7 @@ v8_component("v8_libbase") {
"src/base/macros.h",
"src/base/once.cc",
"src/base/once.h",
"src/base/optional.h",
"src/base/platform/condition-variable.cc",
"src/base/platform/condition-variable.h",
"src/base/platform/elapsed-timer.h",
......
......@@ -11,6 +11,7 @@
#include "src/asmjs/asm-js.h"
#include "src/asmjs/asm-types.h"
#include "src/base/optional.h"
#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker.
#include "src/parsing/scanner.h"
#include "src/wasm/wasm-opcodes.h"
......@@ -2014,8 +2015,7 @@ AsmType* AsmJsParser::ValidateCall() {
// both cases we might be seeing the {function_name} for the first time and
// hence allocate a {VarInfo} here, all subsequent uses of the same name then
// need to match the information stored at this point.
// TODO(mstarzinger): Consider using Chromiums base::Optional instead.
std::unique_ptr<TemporaryVariableScope> tmp;
base::Optional<TemporaryVariableScope> tmp;
if (Check('[')) {
RECURSEn(EqualityExpression());
EXPECT_TOKENn('&');
......@@ -2050,8 +2050,8 @@ AsmType* AsmJsParser::ValidateCall() {
current_function_builder_->EmitI32Const(function_info->index);
current_function_builder_->Emit(kExprI32Add);
// We have to use a temporary for the correct order of evaluation.
tmp.reset(new TemporaryVariableScope(this));
current_function_builder_->EmitSetLocal(tmp.get()->get());
tmp.emplace(this);
current_function_builder_->EmitSetLocal(tmp->get());
// The position of function table calls is after the table lookup.
call_pos = static_cast<int>(scanner_.Position());
} else {
......@@ -2285,7 +2285,7 @@ AsmType* AsmJsParser::ValidateCall() {
}
}
if (function_info->kind == VarKind::kTable) {
current_function_builder_->EmitGetLocal(tmp.get()->get());
current_function_builder_->EmitGetLocal(tmp->get());
current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos);
current_function_builder_->Emit(kExprCallIndirect);
current_function_builder_->EmitU32V(signature_index);
......
This diff is collapsed.
......@@ -2011,6 +2011,7 @@
'base/macros.h',
'base/once.cc',
'base/once.h',
'base/optional.h',
'base/platform/elapsed-timer.h',
'base/platform/time.cc',
'base/platform/time.h',
......
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