Commit 1c758066 authored by verwaest's avatar verwaest Committed by Commit bot

Don't track function-kind through FunctionState, always read from underlying scope

BUG=

Review-Url: https://codereview.chromium.org/2367383002
Cr-Commit-Position: refs/heads/master@{#39763}
parent c176b26f
...@@ -381,8 +381,7 @@ class ParserBase { ...@@ -381,8 +381,7 @@ class ParserBase {
class FunctionState final : public ScopeState { class FunctionState final : public ScopeState {
public: public:
FunctionState(FunctionState** function_state_stack, FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, DeclarationScope* scope, ScopeState** scope_stack, DeclarationScope* scope);
FunctionKind kind);
~FunctionState(); ~FunctionState();
DeclarationScope* scope() const { DeclarationScope* scope() const {
...@@ -403,11 +402,11 @@ class ParserBase { ...@@ -403,11 +402,11 @@ class ParserBase {
void AddProperty() { expected_property_count_++; } void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; } int expected_property_count() { return expected_property_count_; }
bool is_generator() const { return IsGeneratorFunction(kind_); } bool is_generator() const { return IsGeneratorFunction(kind()); }
bool is_async_function() const { return IsAsyncFunction(kind_); } bool is_async_function() const { return IsAsyncFunction(kind()); }
bool is_resumable() const { return is_generator() || is_async_function(); } bool is_resumable() const { return is_generator() || is_async_function(); }
FunctionKind kind() const { return kind_; } FunctionKind kind() const { return scope()->function_kind(); }
FunctionState* outer() const { return outer_function_state_; } FunctionState* outer() const { return outer_function_state_; }
void set_generator_object_variable(typename Types::Variable* variable) { void set_generator_object_variable(typename Types::Variable* variable) {
...@@ -498,7 +497,6 @@ class ParserBase { ...@@ -498,7 +497,6 @@ class ParserBase {
// Properties count estimation. // Properties count estimation.
int expected_property_count_; int expected_property_count_;
FunctionKind kind_;
// For generators, this variable may hold the generator object. It variable // For generators, this variable may hold the generator object. It variable
// is used by yield expressions and return statements. It is not necessary // is used by yield expressions and return statements. It is not necessary
// for generator functions to have this variable set. // for generator functions to have this variable set.
...@@ -1192,7 +1190,6 @@ class ParserBase { ...@@ -1192,7 +1190,6 @@ class ParserBase {
bool* is_async, bool* ok); bool* is_async, bool* ok);
ExpressionT ParseArrowFunctionLiteral(bool accept_IN, ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
const FormalParametersT& parameters, const FormalParametersT& parameters,
bool is_async,
bool* ok); bool* ok);
ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
ExpressionT ParseSuperExpression(bool is_new, bool* ok); ExpressionT ParseSuperExpression(bool is_new, bool* ok);
...@@ -1454,11 +1451,10 @@ class ParserBase { ...@@ -1454,11 +1451,10 @@ class ParserBase {
template <typename Impl> template <typename Impl>
ParserBase<Impl>::FunctionState::FunctionState( ParserBase<Impl>::FunctionState::FunctionState(
FunctionState** function_state_stack, ScopeState** scope_stack, FunctionState** function_state_stack, ScopeState** scope_stack,
DeclarationScope* scope, FunctionKind kind) DeclarationScope* scope)
: ScopeState(scope_stack, scope), : ScopeState(scope_stack, scope),
next_materialized_literal_index_(0), next_materialized_literal_index_(0),
expected_property_count_(0), expected_property_count_(0),
kind_(kind),
generator_object_variable_(nullptr), generator_object_variable_(nullptr),
promise_variable_(nullptr), promise_variable_(nullptr),
function_state_stack_(function_state_stack), function_state_stack_(function_state_stack),
...@@ -2265,7 +2261,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, ...@@ -2265,7 +2261,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
DeclarationScope* initializer_scope = NewFunctionScope(kind); DeclarationScope* initializer_scope = NewFunctionScope(kind);
initializer_scope->set_start_position(scanner()->location().end_pos); initializer_scope->set_start_position(scanner()->location().end_pos);
FunctionState initializer_state(&function_state_, &scope_state_, FunctionState initializer_state(&function_state_, &scope_state_,
initializer_scope, kind); initializer_scope);
DCHECK(scope() == initializer_scope); DCHECK(scope() == initializer_scope);
scope()->SetLanguageMode(STRICT); scope()->SetLanguageMode(STRICT);
ExpressionClassifier expression_classifier(this); ExpressionClassifier expression_classifier(this);
...@@ -2686,8 +2682,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) { ...@@ -2686,8 +2682,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) {
if (duplicate_loc.IsValid()) { if (duplicate_loc.IsValid()) {
classifier()->RecordDuplicateFormalParameterError(duplicate_loc); classifier()->RecordDuplicateFormalParameterError(duplicate_loc);
} }
expression = expression = ParseArrowFunctionLiteral(accept_IN, parameters, CHECK_OK);
ParseArrowFunctionLiteral(accept_IN, parameters, is_async, CHECK_OK);
impl()->Discard(); impl()->Discard();
classifier()->RecordPatternError(arrow_loc, classifier()->RecordPatternError(arrow_loc,
MessageTemplate::kUnexpectedToken, MessageTemplate::kUnexpectedToken,
...@@ -3885,8 +3880,7 @@ bool ParserBase<Impl>::IsTrivialExpression() { ...@@ -3885,8 +3880,7 @@ bool ParserBase<Impl>::IsTrivialExpression() {
template <typename Impl> template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseArrowFunctionLiteral( ParserBase<Impl>::ParseArrowFunctionLiteral(
bool accept_IN, const FormalParametersT& formal_parameters, bool is_async, bool accept_IN, const FormalParametersT& formal_parameters, bool* ok) {
bool* ok) {
if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
// ASI inserts `;` after arrow parameters if a line terminator is found. // ASI inserts `;` after arrow parameters if a line terminator is found.
// `=> ...` is never a valid expression, so report as syntax error. // `=> ...` is never a valid expression, so report as syntax error.
...@@ -3901,13 +3895,13 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3901,13 +3895,13 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
int materialized_literal_count = -1; int materialized_literal_count = -1;
int expected_property_count = -1; int expected_property_count = -1;
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; FunctionKind kind = formal_parameters.scope->function_kind();
FunctionLiteral::EagerCompileHint eager_compile_hint = FunctionLiteral::EagerCompileHint eager_compile_hint =
FunctionLiteral::kShouldLazyCompile; FunctionLiteral::kShouldLazyCompile;
bool should_be_used_once_hint = false; bool should_be_used_once_hint = false;
{ {
FunctionState function_state(&function_state_, &scope_state_, FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind); formal_parameters.scope);
function_state.SkipMaterializedLiterals( function_state.SkipMaterializedLiterals(
formal_parameters.materialized_literals_count); formal_parameters.materialized_literals_count);
...@@ -3953,7 +3947,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3953,7 +3947,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
if (!is_lazily_parsed) { if (!is_lazily_parsed) {
body = impl()->ParseEagerFunctionBody( body = impl()->ParseEagerFunctionBody(
impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters, impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK); kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count = materialized_literal_count =
function_state.materialized_literal_count(); function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count(); expected_property_count = function_state.expected_property_count();
...@@ -3966,10 +3960,10 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3966,10 +3960,10 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
ReturnExprScope allow_tail_calls( ReturnExprScope allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement); function_state_, ReturnExprContext::kInsideValidReturnStatement);
body = impl()->NewStatementList(1); body = impl()->NewStatementList(1);
impl()->AddParameterInitializationBlock(formal_parameters, body, is_async, impl()->AddParameterInitializationBlock(
CHECK_OK); formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK);
ExpressionClassifier classifier(this); ExpressionClassifier classifier(this);
if (is_async) { if (kind == kAsyncArrowFunction) {
impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN, pos, impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN, pos,
CHECK_OK); CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK); impl()->RewriteNonPattern(CHECK_OK);
...@@ -4011,7 +4005,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -4011,7 +4005,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, arrow_kind, FunctionLiteral::kAnonymousExpression, eager_compile_hint, kind,
formal_parameters.scope->start_position()); formal_parameters.scope->start_position());
function_literal->set_function_token_position( function_literal->set_function_token_position(
......
...@@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
{ {
FunctionState function_state(&function_state_, &scope_state_, FunctionState function_state(&function_state_, &scope_state_,
function_scope, kind); function_scope);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) { if (call_super) {
...@@ -786,8 +786,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -786,8 +786,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Enter 'scope' with the given parsing mode. // Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode); ParsingModeScope parsing_mode_scope(this, parsing_mode);
FunctionState function_state(&function_state_, &scope_state_, scope, FunctionState function_state(&function_state_, &scope_state_, scope);
kNormalFunction);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true; bool ok = true;
...@@ -936,8 +935,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info, ...@@ -936,8 +935,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
DeclarationScope* outer_function = outer->GetClosureScope(); DeclarationScope* outer_function = outer->GetClosureScope();
DCHECK(outer); DCHECK(outer);
FunctionState function_state(&function_state_, &scope_state_, FunctionState function_state(&function_state_, &scope_state_,
outer_function, outer_function);
outer_function->function_kind());
BlockState block_state(&scope_state_, outer); BlockState block_state(&scope_state_, outer);
DCHECK(is_sloppy(outer->language_mode()) || DCHECK(is_sloppy(outer->language_mode()) ||
is_strict(info->language_mode())); is_strict(info->language_mode()));
...@@ -959,7 +957,8 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info, ...@@ -959,7 +957,8 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
} }
// TODO(adamk): We should construct this scope from the ScopeInfo. // TODO(adamk): We should construct this scope from the ScopeInfo.
DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction); FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
DeclarationScope* scope = NewFunctionScope(arrow_kind);
// These two bits only need to be explicitly set because we're // These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor. // not passing the ScopeInfo to the Scope constructor.
...@@ -994,8 +993,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info, ...@@ -994,8 +993,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
checkpoint.Restore(&formals.materialized_literals_count); checkpoint.Restore(&formals.materialized_literals_count);
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed. // not be observable, or else the preparser would have failed.
Expression* expression = Expression* expression = ParseArrowFunctionLiteral(true, formals, &ok);
ParseArrowFunctionLiteral(true, formals, is_async, &ok);
if (ok) { if (ok) {
// Scanning must end at the same position that was recorded // Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack // previously. If not, parsing has been interrupted due to a stack
...@@ -2783,7 +2781,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2783,7 +2781,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
DCHECK(main_scope->zone() != scope->zone()); DCHECK(main_scope->zone() != scope->zone());
} }
FunctionState function_state(&function_state_, &scope_state_, scope, kind); FunctionState function_state(&function_state_, &scope_state_, scope);
#ifdef DEBUG #ifdef DEBUG
scope->SetScopeName(function_name); scope->SetScopeName(function_name);
#endif #endif
...@@ -3552,7 +3550,7 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) { ...@@ -3552,7 +3550,7 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) {
initializer_scope->set_start_position(scanner()->location().end_pos); initializer_scope->set_start_position(scanner()->location().end_pos);
initializer_scope->set_end_position(scanner()->location().end_pos); initializer_scope->set_end_position(scanner()->location().end_pos);
FunctionState initializer_state(&function_state_, &scope_state_, FunctionState initializer_state(&function_state_, &scope_state_,
initializer_scope, kind); initializer_scope);
ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(count, zone()); ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(count, zone());
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
const AstRawString* name = const AstRawString* name =
......
...@@ -97,8 +97,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction( ...@@ -97,8 +97,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// scope_state_. All scopes above the function_scope are ignored by the // scope_state_. All scopes above the function_scope are ignored by the
// PreParser. // PreParser.
DCHECK_NULL(scope_state_); DCHECK_NULL(scope_state_);
FunctionState function_state(&function_state_, &scope_state_, function_scope, FunctionState function_state(&function_state_, &scope_state_, function_scope);
function_scope->function_kind());
DCHECK_EQ(Token::LBRACE, scanner()->current_token()); DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true; bool ok = true;
int start_position = peek_position(); int start_position = peek_position();
...@@ -196,8 +195,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -196,8 +195,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
bool outer_is_script_scope = scope()->is_script_scope(); bool outer_is_script_scope = scope()->is_script_scope();
DeclarationScope* function_scope = NewFunctionScope(kind); DeclarationScope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode); function_scope->SetLanguageMode(language_mode);
FunctionState function_state(&function_state_, &scope_state_, function_scope, FunctionState function_state(&function_state_, &scope_state_, function_scope);
kind);
DuplicateFinder duplicate_finder(scanner()->unicode_cache()); DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder); ExpressionClassifier formals_classifier(this, &duplicate_finder);
......
...@@ -793,8 +793,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -793,8 +793,7 @@ class PreParser : public ParserBase<PreParser> {
// the global scope. // the global scope.
if (is_module) scope = NewModuleScope(scope); if (is_module) scope = NewModuleScope(scope);
FunctionState top_scope(&function_state_, &scope_state_, scope, FunctionState top_scope(&function_state_, &scope_state_, scope);
kNormalFunction);
bool ok = true; bool ok = true;
int start_position = scanner()->peek_location().beg_pos; int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module; parsing_module_ = is_module;
......
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