From 85363049ac75b3365e329d070280ff6a2fc8b30e Mon Sep 17 00:00:00 2001 From: "whesse@chromium.org" Date: Thu, 7 Apr 2011 14:45:34 +0000 Subject: [PATCH] Restart AST node numbering when we enter a function. BUG= TEST= Review URL: http://codereview.chromium.org/6691058 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7543 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/full-codegen-arm.cc | 2 +- src/ast.h | 7 +--- src/hydrogen.cc | 6 +-- src/ia32/full-codegen-ia32.cc | 2 +- src/parser.cc | 76 ++++++++++++++++------------------- src/x64/full-codegen-x64.cc | 2 +- 6 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 563e7af1a5..d1356fa74e 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -245,7 +245,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { } { Comment cmnt(masm_, "[ Stack check"); - PrepareForBailout(info->function(), NO_REGISTERS); + PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); Label ok; __ LoadRoot(ip, Heap::kStackLimitRootIndex); __ cmp(sp, Operand(ip)); diff --git a/src/ast.h b/src/ast.h index 9108e6d527..8946071704 100644 --- a/src/ast.h +++ b/src/ast.h @@ -132,6 +132,7 @@ class AstNode: public ZoneObject { #undef DECLARE_TYPE_ENUM static const int kNoNumber = -1; + static const int kFunctionEntryId = 2; // Using 0 could disguise errors. AstNode() : id_(GetNextId()) { Isolate* isolate = Isolate::Current(); @@ -1661,8 +1662,7 @@ class FunctionLiteral: public Expression { int num_parameters, int start_position, int end_position, - bool is_expression, - bool contains_loops) + bool is_expression) : name_(name), scope_(scope), body_(body), @@ -1675,7 +1675,6 @@ class FunctionLiteral: public Expression { start_position_(start_position), end_position_(end_position), is_expression_(is_expression), - contains_loops_(contains_loops), function_token_position_(RelocInfo::kNoPosition), inferred_name_(HEAP->empty_string()), pretenure_(false) { } @@ -1690,7 +1689,6 @@ class FunctionLiteral: public Expression { int start_position() const { return start_position_; } int end_position() const { return end_position_; } bool is_expression() const { return is_expression_; } - bool contains_loops() const { return contains_loops_; } bool strict_mode() const; int materialized_literal_count() { return materialized_literal_count_; } @@ -1730,7 +1728,6 @@ class FunctionLiteral: public Expression { int start_position_; int end_position_; bool is_expression_; - bool contains_loops_; bool strict_mode_; int function_token_position_; Handle inferred_name_; diff --git a/src/hydrogen.cc b/src/hydrogen.cc index fb2a287c9b..189e326f0d 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -582,7 +582,7 @@ HGraph::HGraph(CompilationInfo* info) phi_list_(NULL) { start_environment_ = new(zone()) HEnvironment(NULL, info->scope(), info->closure()); - start_environment_->set_ast_id(info->function()->id()); + start_environment_->set_ast_id(AstNode::kFunctionEntryId); entry_block_ = CreateBasicBlock(); entry_block_->SetInitialEnvironment(start_environment_); } @@ -2203,7 +2203,7 @@ HGraph* HGraphBuilder::CreateGraph() { HEnvironment* initial_env = environment()->CopyWithoutHistory(); HBasicBlock* body_entry = CreateBasicBlock(initial_env); current_block()->Goto(body_entry); - body_entry->SetJoinId(info()->function()->id()); + body_entry->SetJoinId(AstNode::kFunctionEntryId); set_current_block(body_entry); VisitStatements(info()->function()->body()); if (HasStackOverflow()) return NULL; @@ -5663,7 +5663,7 @@ HEnvironment* HEnvironment::CopyForInlining(Handle target, inner->SetValueAt(local_base + i, undefined); } - inner->set_ast_id(function->id()); + inner->set_ast_id(AstNode::kFunctionEntryId); return inner; } diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index 0f4cd541bc..aeee584a1d 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -231,7 +231,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { } { Comment cmnt(masm_, "[ Stack check"); - PrepareForBailout(info->function(), NO_REGISTERS); + PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); NearLabel ok; ExternalReference stack_limit = ExternalReference::address_of_stack_limit(isolate()); diff --git a/src/parser.cc b/src/parser.cc index 13d255ccc1..69ecfe4666 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -462,7 +462,7 @@ class TargetScope BASE_EMBEDDED { // Parser's scope stack. The constructor sets the parser's top scope // to the incoming scope, and the destructor resets it. // -// Additionlaly, it stores transient information used during parsing. +// Additionally, it stores transient information used during parsing. // These scopes are not kept around after parsing or referenced by syntax // trees so they can be stack-allocated and hence used by the pre-parser. @@ -496,9 +496,6 @@ class LexicalScope BASE_EMBEDDED { void AddProperty() { expected_property_count_++; } int expected_property_count() { return expected_property_count_; } - void AddLoop() { loop_count_++; } - bool ContainsLoops() const { return loop_count_ > 0; } - private: // Captures the number of literals that need materialization in the // function. Includes regexp literals, and boilerplate for object @@ -513,15 +510,13 @@ class LexicalScope BASE_EMBEDDED { bool only_simple_this_property_assignments_; Handle this_property_assignments_; - // Captures the number of loops inside the scope. - int loop_count_; - // Bookkeeping Parser* parser_; // Previous values LexicalScope* lexical_scope_parent_; Scope* previous_scope_; int previous_with_nesting_level_; + unsigned previous_ast_node_id_; }; @@ -530,14 +525,15 @@ LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate) expected_property_count_(0), only_simple_this_property_assignments_(false), this_property_assignments_(isolate->factory()->empty_fixed_array()), - loop_count_(0), parser_(parser), lexical_scope_parent_(parser->lexical_scope_), previous_scope_(parser->top_scope_), - previous_with_nesting_level_(parser->with_nesting_level_) { + previous_with_nesting_level_(parser->with_nesting_level_), + previous_ast_node_id_(isolate->ast_node_id()) { parser->top_scope_ = scope; parser->lexical_scope_ = this; parser->with_nesting_level_ = 0; + isolate->set_ast_node_id(AstNode::kRootAstId + 1); } @@ -546,6 +542,7 @@ LexicalScope::~LexicalScope() { parser_->top_scope_ = previous_scope_; parser_->lexical_scope_ = lexical_scope_parent_; parser_->with_nesting_level_ = previous_with_nesting_level_; + parser_->isolate()->set_ast_node_id(previous_ast_node_id_); } @@ -663,8 +660,7 @@ FunctionLiteral* Parser::DoParseProgram(Handle source, 0, 0, source->length(), - false, - lexical_scope.ContainsLoops()); + false); } else if (stack_overflow_) { isolate()->StackOverflow(); } @@ -2162,7 +2158,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, // DoStatement :: // 'do' Statement 'while' '(' Expression ')' ';' - lexical_scope_->AddLoop(); DoWhileStatement* loop = new(zone()) DoWhileStatement(labels); Target target(&this->target_stack_, loop); @@ -2194,7 +2189,6 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { // WhileStatement :: // 'while' '(' Expression ')' Statement - lexical_scope_->AddLoop(); WhileStatement* loop = new(zone()) WhileStatement(labels); Target target(&this->target_stack_, loop); @@ -2213,7 +2207,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { // ForStatement :: // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement - lexical_scope_->AddLoop(); Statement* init = NULL; Expect(Token::FOR, CHECK_OK); @@ -3530,16 +3523,22 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle var_name, } int num_parameters = 0; + Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); + ZoneList* body = new ZoneList(8); + int materialized_literal_count; + int expected_property_count; + int start_pos; + int end_pos; + bool only_simple_this_property_assignments; + Handle this_property_assignments; // Parse function body. - { Scope* scope = - NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); - LexicalScope lexical_scope(this, scope, isolate()); + { LexicalScope lexical_scope(this, scope, isolate()); top_scope_->SetScopeName(name); // FormalParameterList :: // '(' (Identifier)*[','] ')' Expect(Token::LPAREN, CHECK_OK); - int start_pos = scanner().location().beg_pos; + start_pos = scanner().location().beg_pos; Scanner::Location name_loc = Scanner::NoLocation(); Scanner::Location dupe_loc = Scanner::NoLocation(); Scanner::Location reserved_loc = Scanner::NoLocation(); @@ -3576,7 +3575,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle var_name, Expect(Token::RPAREN, CHECK_OK); Expect(Token::LBRACE, CHECK_OK); - ZoneList* body = new ZoneList(8); // If we have a named function expression, we add a local variable // declaration to the body of the function with the name of the @@ -3604,11 +3602,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle var_name, parenthesized_function_ = false; // The bit was set for this function only. int function_block_pos = scanner().location().beg_pos; - int materialized_literal_count; - int expected_property_count; - int end_pos; - bool only_simple_this_property_assignments; - Handle this_property_assignments; if (is_lazily_compiled && pre_data() != NULL) { FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); if (!entry.is_valid()) { @@ -3683,25 +3676,24 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle var_name, } CheckOctalLiteral(start_pos, end_pos, CHECK_OK); } - - FunctionLiteral* function_literal = - new(zone()) FunctionLiteral(name, - top_scope_, - body, - materialized_literal_count, - expected_property_count, - only_simple_this_property_assignments, - this_property_assignments, - num_parameters, - start_pos, - end_pos, - function_name->length() > 0, - lexical_scope.ContainsLoops()); - function_literal->set_function_token_position(function_token_position); - - if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal); - return function_literal; } + + FunctionLiteral* function_literal = + new(zone()) FunctionLiteral(name, + scope, + body, + materialized_literal_count, + expected_property_count, + only_simple_this_property_assignments, + this_property_assignments, + num_parameters, + start_pos, + end_pos, + (function_name->length() > 0)); + function_literal->set_function_token_position(function_token_position); + + if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal); + return function_literal; } diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 8449a2596f..97168cdce4 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -232,7 +232,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { } { Comment cmnt(masm_, "[ Stack check"); - PrepareForBailout(info->function(), NO_REGISTERS); + PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); NearLabel ok; __ CompareRoot(rsp, Heap::kStackLimitRootIndex); __ j(above_equal, &ok);