Reviewers: marja, Dmitry Lomov (chromium),
Description:
Lolcode candidate: Both Expression and FunctionLiteral define an accessor
is_parenthesized(), which access different flags. FunctionLiteral derives
from
Expression.
Given
FunctionLiteral* a; a->is_parenthesized()
const FunctionLiteral* b; b->is_parenthesized()
the first accesses FunctionLiteral::IsParenthesized, the second accesses
Expression::IsParenthesizedField.
Since these are distinct uses, we could rename them based on their use:
- Expression::is_parenthesized -> is_single_parenthesized
Count # of parenthesis, for parsing & error handling:
no parenthesis -> single parenthesis -> multi parenthesis
- FunctionLiteral::eager_compile_hint()
Hint from parser to compiler about whether the parser suggests this
function
for eager compilation.
BUG=
Please review this at https://codereview.chromium.org/1097723005/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+39, -40 lines):
M src/ast.h
M src/compiler.cc
M src/parser.cc
M src/preparser.h
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index
18d19af67fb216e9952b5630f35d536bba7ce43e..7c6d40d5c716bac7f5cab7614ac659f061c3927e
100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -372,16 +372,16 @@ class Expression : public AstNode {
void set_bounds(Bounds bounds) { bounds_ = bounds; }
// Whether the expression is parenthesized
- bool is_parenthesized() const {
- return IsParenthesizedField::decode(bit_field_);
+ bool is_single_parenthesized() const {
+ return IsSingleParenthesizedField::decode(bit_field_);
}
bool is_multi_parenthesized() const {
return IsMultiParenthesizedField::decode(bit_field_);
}
void increase_parenthesization_level() {
- bit_field_ =
- IsMultiParenthesizedField::update(bit_field_, is_parenthesized());
- bit_field_ = IsParenthesizedField::update(bit_field_, true);
+ bit_field_ = IsMultiParenthesizedField::update(bit_field_,
+
is_single_parenthesized());
+ bit_field_ = IsSingleParenthesizedField::update(bit_field_, true);
}
// Type feedback information for assignments and properties.
@@ -435,7 +435,7 @@ class Expression : public AstNode {
int base_id_;
Bounds bounds_;
class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
- class IsParenthesizedField : public BitField16<bool, 8, 1> {};
+ class IsSingleParenthesizedField : public BitField16<bool, 8, 1> {};
class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {};
uint16_t bit_field_;
// Ends with 16-bit field; deriving classes in turn begin with
@@ -2491,10 +2491,7 @@ class FunctionLiteral final : public Expression {
kIsFunction
};
- enum IsParenthesizedFlag {
- kIsParenthesized,
- kNotParenthesized
- };
+ enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
enum ArityRestriction {
NORMAL_ARITY,
@@ -2584,11 +2581,11 @@ class FunctionLiteral final : public Expression {
// function will be called immediately:
// - (function() { ... })();
// - var x = function() { ... }();
- bool is_parenthesized() {
- return IsParenthesized::decode(bitfield_) == kIsParenthesized;
+ bool should_eager_compile() const {
+ return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile;
}
- void set_parenthesized() {
- bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
+ void set_should_eager_compile() {
+ bitfield_ = EagerCompileHintBit::update(bitfield_,
kShouldEagerCompile);
}
FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
@@ -2615,7 +2612,7 @@ class FunctionLiteral final : public Expression {
int parameter_count, FunctionType function_type,
ParameterFlag has_duplicate_parameters,
IsFunctionFlag is_function,
- IsParenthesizedFlag is_parenthesized, FunctionKind kind,
+ EagerCompileHint eager_compile_hint, FunctionKind kind,
int position)
: Expression(zone, position),
raw_name_(name),
@@ -2634,7 +2631,7 @@ class FunctionLiteral final : public Expression {
Pretenure::encode(false) |
HasDuplicateParameters::encode(has_duplicate_parameters) |
IsFunction::encode(is_function) |
- IsParenthesized::encode(is_parenthesized) |
+ EagerCompileHintBit::encode(eager_compile_hint) |
FunctionKindBits::encode(kind);
DCHECK(IsValidFunctionKind(kind));
}
@@ -2662,7 +2659,7 @@ class FunctionLiteral final : public Expression {
class Pretenure : public BitField<bool, 2, 1> {};
class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
- class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
+ class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
};
@@ -3545,12 +3542,12 @@ class AstNodeFactory final BASE_EMBEDDED {
FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function,
- FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind
kind,
+ FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind
kind,
int position) {
return new (zone_) FunctionLiteral(
zone_, name, ast_value_factory, scope, body,
materialized_literal_count,
expected_property_count, handler_count, parameter_count,
function_type,
- has_duplicate_parameters, is_function, is_parenthesized, kind,
+ has_duplicate_parameters, is_function, eager_compile_hint, kind,
position);
}
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
ea5660d1e34e1224cee370833ecd2d2669ac6392..5c6c0f26f78c85f3c9f1445b0f50a05d52fe8d93
100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1347,7 +1347,7 @@ Handle<SharedFunctionInfo>
Compiler::BuildFunctionInfo(
// Generate code
Handle<ScopeInfo> scope_info;
- if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) {
+ if (FLAG_lazy && allow_lazy && !literal->should_eager_compile()) {
Handle<Code> code = isolate->builtins()->CompileLazy();
info.SetCode(code);
// There's no need in theory for a lazy-compiled function to have a
type
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
fb52eef56382155d70889fa53efcc74ba8f5a700..86b55f448338b94f71958443d7346f8abb4c624b
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -378,7 +378,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool
call_super, Scope* scope,
materialized_literal_count, expected_property_count, handler_count,
parameter_count, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
- FunctionLiteral::kNotParenthesized, kind, pos);
+ FunctionLiteral::kShouldLazyCompile, kind, pos);
return function_literal;
}
@@ -1048,7 +1048,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo*
info) {
function_state.handler_count(), 0,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION,
FunctionLiteral::kGlobalOrEval,
- FunctionLiteral::kNotParenthesized,
FunctionKind::kNormalFunction, 0);
+ FunctionLiteral::kShouldLazyCompile,
FunctionKind::kNormalFunction,
+ 0);
}
}
@@ -3777,8 +3778,9 @@ bool CheckAndDeclareArrowParameter(ParserTraits*
traits, Expression* expression,
// (foo, bar [, ...]) => ...
if (expression->IsBinaryOperation()) {
BinaryOperation* binop = expression->AsBinaryOperation();
- if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() ||
- binop->right()->is_parenthesized())
+ if (binop->op() != Token::COMMA ||
+ binop->left()->is_single_parenthesized() ||
+ binop->right()->is_single_parenthesized())
return false;
return CheckAndDeclareArrowParameter(traits, binop->left(), scope,
@@ -3877,9 +3879,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
int handler_count = 0;
FunctionLiteral::ParameterFlag duplicate_parameters =
FunctionLiteral::kNoDuplicateParameters;
- FunctionLiteral::IsParenthesizedFlag parenthesized =
parenthesized_function_
- ? FunctionLiteral::kIsParenthesized
- : FunctionLiteral::kNotParenthesized;
+ FunctionLiteral::EagerCompileHint eager_compile_hint =
+ parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
+ : FunctionLiteral::kShouldLazyCompile;
// Parse function body.
{
AstNodeFactory function_factory(ast_value_factory());
@@ -4079,7 +4081,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name, ast_value_factory(), scope, body,
materialized_literal_count, expected_property_count, handler_count,
num_parameters, duplicate_parameters, function_type,
- FunctionLiteral::kIsFunction, parenthesized, kind, pos);
+ FunctionLiteral::kIsFunction, eager_compile_hint, kind, pos);
function_literal->set_function_token_position(function_token_pos);
if (scope->has_rest_parameter()) {
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
33c737f8633e970cb3c63ea85a0efb3b5cc65be9..41512c5e4ed4ae3efaecbeed6dfb50e5978cc4fe
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -806,10 +806,10 @@ class PreParserExpression {
Token::Value op,
PreParserExpression right) {
ValidArrowParam valid_arrow_param_list =
- (op == Token::COMMA && !left.is_parenthesized() &&
- !right.is_parenthesized()) ?
- std::min(left.ValidateArrowParams(),
right.ValidateArrowParams())
- : kInvalidArrowParam;
+ (op == Token::COMMA && !left.is_single_parenthesized() &&
+ !right.is_single_parenthesized())
+ ? std::min(left.ValidateArrowParams(),
right.ValidateArrowParams())
+ : kInvalidArrowParam;
return PreParserExpression(
TypeField::encode(kBinaryOperationExpression) |
IsValidArrowParamListField::encode(valid_arrow_param_list));
@@ -947,14 +947,14 @@ class PreParserExpression {
return TypeField::decode(code_) == kBinaryOperationExpression;
}
- bool is_parenthesized() const {
+ bool is_single_parenthesized() const {
return ParenthesizationField::decode(code_) != kNotParenthesized;
}
void increase_parenthesization_level() {
code_ = ParenthesizationField::update(
- code_, is_parenthesized() ? kMultiParenthesizedExpression
- : kParanthesizedExpression);
+ code_, is_single_parenthesized() ? kMultiParenthesizedExpression
+ : kParanthesizedExpression);
}
// Dummy implementation for making expression->somefunc() work in both
Parser
@@ -963,7 +963,7 @@ class PreParserExpression {
// More dummy implementations of things PreParser doesn't need to track:
void set_index(int index) {} // For YieldExpressions
- void set_parenthesized() {}
+ void set_should_eager_compile() {}
int position() const { return RelocInfo::kNoPosition; }
void set_function_token_position(int position) {}
@@ -1249,7 +1249,7 @@ class PreParserFactory {
FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function,
- FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind
kind,
+ FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind
kind,
int position) {
return PreParserExpression::Default();
}
@@ -2797,7 +2797,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(bool*
ok) {
// be called immediately. If we happen to have parsed a preceding
// function literal eagerly, we can also compile it eagerly.
if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
- result->AsFunctionLiteral()->set_parenthesized();
+ result->AsFunctionLiteral()->set_should_eager_compile();
}
}
Scanner::Location spread_pos;
@@ -3025,7 +3025,7 @@
ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT
expression,
if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
// If the tag function looks like an IIFE, set_parenthesized()
to
// force eager compilation.
- expression->AsFunctionLiteral()->set_parenthesized();
+ expression->AsFunctionLiteral()->set_should_eager_compile();
}
}
expression = ParseTemplateLiteral(expression, pos, CHECK_OK);
@@ -3150,7 +3150,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int
start_pos,
materialized_literal_count, expected_property_count, handler_count,
num_parameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
- FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction,
+ FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction,
start_pos);
function_literal->set_function_token_position(start_pos);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.