Commit 841b82a4 authored by adamk's avatar adamk Committed by Commit bot

[ast] Make FunctionLiteral delegate to its Scope for FunctionKind

As a side-effect, this lets us remove bit_field_2_ from FunctionLiteral.

R=verwaest@chromium.org
BUG=v8:5209

Review-Url: https://codereview.chromium.org/2369293003
Cr-Commit-Position: refs/heads/master@{#39799}
parent 53b22823
...@@ -313,6 +313,7 @@ LanguageMode FunctionLiteral::language_mode() const { ...@@ -313,6 +313,7 @@ LanguageMode FunctionLiteral::language_mode() const {
return scope()->language_mode(); return scope()->language_mode();
} }
FunctionKind FunctionLiteral::kind() const { return scope()->function_kind(); }
bool FunctionLiteral::NeedsHomeObject(Expression* expr) { bool FunctionLiteral::NeedsHomeObject(Expression* expr) {
if (expr == nullptr || !expr->IsFunctionLiteral()) return false; if (expr == nullptr || !expr->IsFunctionLiteral()) return false;
......
...@@ -2668,7 +2668,7 @@ class FunctionLiteral final : public Expression { ...@@ -2668,7 +2668,7 @@ class FunctionLiteral final : public Expression {
FunctionType function_type() const { FunctionType function_type() const {
return FunctionTypeBits::decode(bit_field_); return FunctionTypeBits::decode(bit_field_);
} }
FunctionKind kind() const { return FunctionKindBits::decode(bit_field_); } FunctionKind kind() const;
int ast_node_count() { return ast_properties_.node_count(); } int ast_node_count() { return ast_properties_.node_count(); }
AstProperties::Flags flags() const { return ast_properties_.flags(); } AstProperties::Flags flags() const { return ast_properties_.flags(); }
...@@ -2680,10 +2680,10 @@ class FunctionLiteral final : public Expression { ...@@ -2680,10 +2680,10 @@ class FunctionLiteral final : public Expression {
} }
bool dont_optimize() { return dont_optimize_reason() != kNoReason; } bool dont_optimize() { return dont_optimize_reason() != kNoReason; }
BailoutReason dont_optimize_reason() { BailoutReason dont_optimize_reason() {
return DontOptimizeReasonField::decode(bit_field_2_); return DontOptimizeReasonField::decode(bit_field_);
} }
void set_dont_optimize_reason(BailoutReason reason) { void set_dont_optimize_reason(BailoutReason reason) {
bit_field_2_ = DontOptimizeReasonField::update(bit_field_2_, reason); bit_field_ = DontOptimizeReasonField::update(bit_field_, reason);
} }
bool IsAnonymousFunctionDefinition() const { bool IsAnonymousFunctionDefinition() const {
...@@ -2701,11 +2701,11 @@ class FunctionLiteral final : public Expression { ...@@ -2701,11 +2701,11 @@ class FunctionLiteral final : public Expression {
RequiresClassFieldInit::update(bit_field_, requires_class_field_init); RequiresClassFieldInit::update(bit_field_, requires_class_field_init);
} }
bool is_class_field_initializer() { bool is_class_field_initializer() {
return IsClassFieldInitializer::decode(bit_field_2_); return IsClassFieldInitializer::decode(bit_field_);
} }
void set_is_class_field_initializer(bool is_class_field_initializer) { void set_is_class_field_initializer(bool is_class_field_initializer) {
bit_field_ = IsClassFieldInitializer::update(bit_field_2_, bit_field_ =
is_class_field_initializer); IsClassFieldInitializer::update(bit_field_, is_class_field_initializer);
} }
private: private:
...@@ -2717,8 +2717,8 @@ class FunctionLiteral final : public Expression { ...@@ -2717,8 +2717,8 @@ class FunctionLiteral final : public Expression {
int expected_property_count, int parameter_count, int expected_property_count, int parameter_count,
FunctionType function_type, FunctionType function_type,
ParameterFlag has_duplicate_parameters, ParameterFlag has_duplicate_parameters,
EagerCompileHint eager_compile_hint, FunctionKind kind, EagerCompileHint eager_compile_hint, int position,
int position, bool is_function) bool is_function)
: Expression(position, kFunctionLiteral), : Expression(position, kFunctionLiteral),
materialized_literal_count_(materialized_literal_count), materialized_literal_count_(materialized_literal_count),
expected_property_count_(expected_property_count), expected_property_count_(expected_property_count),
...@@ -2736,13 +2736,10 @@ class FunctionLiteral final : public Expression { ...@@ -2736,13 +2736,10 @@ class FunctionLiteral final : public Expression {
kHasDuplicateParameters) | kHasDuplicateParameters) |
IsFunction::encode(is_function) | IsFunction::encode(is_function) |
ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) |
FunctionKindBits::encode(kind) | RequiresClassFieldInit::encode(false) | RequiresClassFieldInit::encode(false) |
ShouldNotBeUsedOnceHintField::encode(false); ShouldNotBeUsedOnceHintField::encode(false) |
DontOptimizeReasonField::encode(kNoReason) |
bit_field_2_ = DontOptimizeReasonField::encode(kNoReason) | IsClassFieldInitializer::encode(false);
IsClassFieldInitializer::encode(false);
DCHECK(IsValidFunctionKind(kind));
} }
class FunctionTypeBits class FunctionTypeBits
...@@ -2751,16 +2748,12 @@ class FunctionLiteral final : public Expression { ...@@ -2751,16 +2748,12 @@ class FunctionLiteral final : public Expression {
class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {}; class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {};
class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {}; class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {};
class ShouldEagerCompile : public BitField<bool, IsFunction::kNext, 1> {}; class ShouldEagerCompile : public BitField<bool, IsFunction::kNext, 1> {};
class FunctionKindBits
: public BitField<FunctionKind, ShouldEagerCompile::kNext, 9> {};
class ShouldNotBeUsedOnceHintField class ShouldNotBeUsedOnceHintField
: public BitField<bool, FunctionKindBits::kNext, 1> {}; : public BitField<bool, ShouldEagerCompile::kNext, 1> {};
class RequiresClassFieldInit class RequiresClassFieldInit
: public BitField<bool, ShouldNotBeUsedOnceHintField::kNext, 1> {}; : public BitField<bool, ShouldNotBeUsedOnceHintField::kNext, 1> {};
class IsClassFieldInitializer
uint32_t bit_field_2_; : public BitField<bool, RequiresClassFieldInit::kNext, 1> {};
class IsClassFieldInitializer : public BitField<bool, 0, 1> {};
class DontOptimizeReasonField class DontOptimizeReasonField
: public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {}; : public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {};
...@@ -3469,13 +3462,12 @@ class AstNodeFactory final BASE_EMBEDDED { ...@@ -3469,13 +3462,12 @@ class AstNodeFactory final BASE_EMBEDDED {
int expected_property_count, int parameter_count, int expected_property_count, int parameter_count,
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, FunctionLiteral::EagerCompileHint eager_compile_hint, int position) {
int position) { return new (zone_) FunctionLiteral(zone_, name, ast_value_factory_, scope,
return new (zone_) FunctionLiteral( body, materialized_literal_count,
zone_, name, ast_value_factory_, scope, body, expected_property_count, parameter_count,
materialized_literal_count, expected_property_count, parameter_count, function_type, has_duplicate_parameters,
function_type, has_duplicate_parameters, eager_compile_hint, kind, eager_compile_hint, position, true);
position, true);
} }
// Creates a FunctionLiteral representing a top-level script, the // Creates a FunctionLiteral representing a top-level script, the
...@@ -3490,8 +3482,7 @@ class AstNodeFactory final BASE_EMBEDDED { ...@@ -3490,8 +3482,7 @@ class AstNodeFactory final BASE_EMBEDDED {
body, materialized_literal_count, expected_property_count, body, materialized_literal_count, expected_property_count,
parameter_count, FunctionLiteral::kAnonymousExpression, parameter_count, FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, FunctionLiteral::kShouldLazyCompile, 0, false);
false);
} }
ClassLiteral::Property* NewClassLiteralProperty( ClassLiteral::Property* NewClassLiteralProperty(
......
...@@ -2293,8 +2293,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, ...@@ -2293,8 +2293,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
initializer_state.expected_property_count(), 0, initializer_state.expected_property_count(), 0,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kShouldLazyCompile, kind, FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position());
initializer_scope->start_position());
function_literal->set_is_class_field_initializer(true); function_literal->set_is_class_field_initializer(true);
return function_literal; return function_literal;
} }
...@@ -4039,7 +4038,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4039,7 +4038,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
impl()->EmptyIdentifierString(), formal_parameters.scope, body, impl()->EmptyIdentifierString(), formal_parameters.scope, body,
materialized_literal_count, expected_property_count, num_parameters, materialized_literal_count, expected_property_count, num_parameters,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, eager_compile_hint, kind, FunctionLiteral::kAnonymousExpression, eager_compile_hint,
formal_parameters.scope->start_position()); formal_parameters.scope->start_position());
function_literal->set_function_token_position( function_literal->set_function_token_position(
......
...@@ -283,7 +283,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -283,7 +283,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
expected_property_count, parameter_count, expected_property_count, parameter_count,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kShouldLazyCompile, kind, pos); FunctionLiteral::kShouldLazyCompile, pos);
function_literal->set_requires_class_field_init(requires_class_field_init); function_literal->set_requires_class_field_init(requires_class_field_init);
...@@ -2842,7 +2842,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2842,7 +2842,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
FunctionLiteral* function_literal = factory()->NewFunctionLiteral( FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
function_name, main_scope, body, materialized_literal_count, function_name, main_scope, body, materialized_literal_count,
expected_property_count, arity, duplicate_parameters, function_type, expected_property_count, arity, duplicate_parameters, function_type,
eager_compile_hint, kind, pos); eager_compile_hint, pos);
function_literal->set_function_token_position(function_token_pos); function_literal->set_function_token_position(function_token_pos);
if (should_be_used_once_hint) if (should_be_used_once_hint)
function_literal->set_should_be_used_once_hint(); function_literal->set_should_be_used_once_hint();
...@@ -3512,8 +3512,7 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) { ...@@ -3512,8 +3512,7 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) {
initializer_state.expected_property_count(), 0, initializer_state.expected_property_count(), 0,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kShouldLazyCompile, kind, FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position());
initializer_scope->start_position());
function_literal->set_is_class_field_initializer(true); function_literal->set_is_class_field_initializer(true);
function_literal->scope()->set_arity(count); function_literal->scope()->set_arity(count);
return function_literal; return function_literal;
......
...@@ -596,8 +596,7 @@ class PreParserFactory { ...@@ -596,8 +596,7 @@ class PreParserFactory {
int parameter_count, int parameter_count,
FunctionLiteral::ParameterFlag has_duplicate_parameters, FunctionLiteral::ParameterFlag has_duplicate_parameters,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, FunctionLiteral::EagerCompileHint eager_compile_hint, int position) {
int position) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
......
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