Commit 85363049 authored by whesse@chromium.org's avatar whesse@chromium.org

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
parent 95c76ed4
...@@ -245,7 +245,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { ...@@ -245,7 +245,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
} }
{ Comment cmnt(masm_, "[ Stack check"); { Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS); PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
Label ok; Label ok;
__ LoadRoot(ip, Heap::kStackLimitRootIndex); __ LoadRoot(ip, Heap::kStackLimitRootIndex);
__ cmp(sp, Operand(ip)); __ cmp(sp, Operand(ip));
......
...@@ -132,6 +132,7 @@ class AstNode: public ZoneObject { ...@@ -132,6 +132,7 @@ class AstNode: public ZoneObject {
#undef DECLARE_TYPE_ENUM #undef DECLARE_TYPE_ENUM
static const int kNoNumber = -1; static const int kNoNumber = -1;
static const int kFunctionEntryId = 2; // Using 0 could disguise errors.
AstNode() : id_(GetNextId()) { AstNode() : id_(GetNextId()) {
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
...@@ -1661,8 +1662,7 @@ class FunctionLiteral: public Expression { ...@@ -1661,8 +1662,7 @@ class FunctionLiteral: public Expression {
int num_parameters, int num_parameters,
int start_position, int start_position,
int end_position, int end_position,
bool is_expression, bool is_expression)
bool contains_loops)
: name_(name), : name_(name),
scope_(scope), scope_(scope),
body_(body), body_(body),
...@@ -1675,7 +1675,6 @@ class FunctionLiteral: public Expression { ...@@ -1675,7 +1675,6 @@ class FunctionLiteral: public Expression {
start_position_(start_position), start_position_(start_position),
end_position_(end_position), end_position_(end_position),
is_expression_(is_expression), is_expression_(is_expression),
contains_loops_(contains_loops),
function_token_position_(RelocInfo::kNoPosition), function_token_position_(RelocInfo::kNoPosition),
inferred_name_(HEAP->empty_string()), inferred_name_(HEAP->empty_string()),
pretenure_(false) { } pretenure_(false) { }
...@@ -1690,7 +1689,6 @@ class FunctionLiteral: public Expression { ...@@ -1690,7 +1689,6 @@ class FunctionLiteral: public Expression {
int start_position() const { return start_position_; } int start_position() const { return start_position_; }
int end_position() const { return end_position_; } int end_position() const { return end_position_; }
bool is_expression() const { return is_expression_; } bool is_expression() const { return is_expression_; }
bool contains_loops() const { return contains_loops_; }
bool strict_mode() const; bool strict_mode() const;
int materialized_literal_count() { return materialized_literal_count_; } int materialized_literal_count() { return materialized_literal_count_; }
...@@ -1730,7 +1728,6 @@ class FunctionLiteral: public Expression { ...@@ -1730,7 +1728,6 @@ class FunctionLiteral: public Expression {
int start_position_; int start_position_;
int end_position_; int end_position_;
bool is_expression_; bool is_expression_;
bool contains_loops_;
bool strict_mode_; bool strict_mode_;
int function_token_position_; int function_token_position_;
Handle<String> inferred_name_; Handle<String> inferred_name_;
......
...@@ -582,7 +582,7 @@ HGraph::HGraph(CompilationInfo* info) ...@@ -582,7 +582,7 @@ HGraph::HGraph(CompilationInfo* info)
phi_list_(NULL) { phi_list_(NULL) {
start_environment_ = start_environment_ =
new(zone()) HEnvironment(NULL, info->scope(), info->closure()); 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_ = CreateBasicBlock();
entry_block_->SetInitialEnvironment(start_environment_); entry_block_->SetInitialEnvironment(start_environment_);
} }
...@@ -2203,7 +2203,7 @@ HGraph* HGraphBuilder::CreateGraph() { ...@@ -2203,7 +2203,7 @@ HGraph* HGraphBuilder::CreateGraph() {
HEnvironment* initial_env = environment()->CopyWithoutHistory(); HEnvironment* initial_env = environment()->CopyWithoutHistory();
HBasicBlock* body_entry = CreateBasicBlock(initial_env); HBasicBlock* body_entry = CreateBasicBlock(initial_env);
current_block()->Goto(body_entry); current_block()->Goto(body_entry);
body_entry->SetJoinId(info()->function()->id()); body_entry->SetJoinId(AstNode::kFunctionEntryId);
set_current_block(body_entry); set_current_block(body_entry);
VisitStatements(info()->function()->body()); VisitStatements(info()->function()->body());
if (HasStackOverflow()) return NULL; if (HasStackOverflow()) return NULL;
...@@ -5663,7 +5663,7 @@ HEnvironment* HEnvironment::CopyForInlining(Handle<JSFunction> target, ...@@ -5663,7 +5663,7 @@ HEnvironment* HEnvironment::CopyForInlining(Handle<JSFunction> target,
inner->SetValueAt(local_base + i, undefined); inner->SetValueAt(local_base + i, undefined);
} }
inner->set_ast_id(function->id()); inner->set_ast_id(AstNode::kFunctionEntryId);
return inner; return inner;
} }
......
...@@ -231,7 +231,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { ...@@ -231,7 +231,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
} }
{ Comment cmnt(masm_, "[ Stack check"); { Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS); PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
NearLabel ok; NearLabel ok;
ExternalReference stack_limit = ExternalReference stack_limit =
ExternalReference::address_of_stack_limit(isolate()); ExternalReference::address_of_stack_limit(isolate());
......
...@@ -462,7 +462,7 @@ class TargetScope BASE_EMBEDDED { ...@@ -462,7 +462,7 @@ class TargetScope BASE_EMBEDDED {
// Parser's scope stack. The constructor sets the parser's top scope // Parser's scope stack. The constructor sets the parser's top scope
// to the incoming scope, and the destructor resets it. // 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 // 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. // trees so they can be stack-allocated and hence used by the pre-parser.
...@@ -496,9 +496,6 @@ class LexicalScope BASE_EMBEDDED { ...@@ -496,9 +496,6 @@ class LexicalScope BASE_EMBEDDED {
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_; }
void AddLoop() { loop_count_++; }
bool ContainsLoops() const { return loop_count_ > 0; }
private: private:
// Captures the number of literals that need materialization in the // Captures the number of literals that need materialization in the
// function. Includes regexp literals, and boilerplate for object // function. Includes regexp literals, and boilerplate for object
...@@ -513,15 +510,13 @@ class LexicalScope BASE_EMBEDDED { ...@@ -513,15 +510,13 @@ class LexicalScope BASE_EMBEDDED {
bool only_simple_this_property_assignments_; bool only_simple_this_property_assignments_;
Handle<FixedArray> this_property_assignments_; Handle<FixedArray> this_property_assignments_;
// Captures the number of loops inside the scope.
int loop_count_;
// Bookkeeping // Bookkeeping
Parser* parser_; Parser* parser_;
// Previous values // Previous values
LexicalScope* lexical_scope_parent_; LexicalScope* lexical_scope_parent_;
Scope* previous_scope_; Scope* previous_scope_;
int previous_with_nesting_level_; int previous_with_nesting_level_;
unsigned previous_ast_node_id_;
}; };
...@@ -530,14 +525,15 @@ LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate) ...@@ -530,14 +525,15 @@ LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate)
expected_property_count_(0), expected_property_count_(0),
only_simple_this_property_assignments_(false), only_simple_this_property_assignments_(false),
this_property_assignments_(isolate->factory()->empty_fixed_array()), this_property_assignments_(isolate->factory()->empty_fixed_array()),
loop_count_(0),
parser_(parser), parser_(parser),
lexical_scope_parent_(parser->lexical_scope_), lexical_scope_parent_(parser->lexical_scope_),
previous_scope_(parser->top_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->top_scope_ = scope;
parser->lexical_scope_ = this; parser->lexical_scope_ = this;
parser->with_nesting_level_ = 0; parser->with_nesting_level_ = 0;
isolate->set_ast_node_id(AstNode::kRootAstId + 1);
} }
...@@ -546,6 +542,7 @@ LexicalScope::~LexicalScope() { ...@@ -546,6 +542,7 @@ LexicalScope::~LexicalScope() {
parser_->top_scope_ = previous_scope_; parser_->top_scope_ = previous_scope_;
parser_->lexical_scope_ = lexical_scope_parent_; parser_->lexical_scope_ = lexical_scope_parent_;
parser_->with_nesting_level_ = previous_with_nesting_level_; 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<String> source, ...@@ -663,8 +660,7 @@ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
0, 0,
0, 0,
source->length(), source->length(),
false, false);
lexical_scope.ContainsLoops());
} else if (stack_overflow_) { } else if (stack_overflow_) {
isolate()->StackOverflow(); isolate()->StackOverflow();
} }
...@@ -2162,7 +2158,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, ...@@ -2162,7 +2158,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
// DoStatement :: // DoStatement ::
// 'do' Statement 'while' '(' Expression ')' ';' // 'do' Statement 'while' '(' Expression ')' ';'
lexical_scope_->AddLoop();
DoWhileStatement* loop = new(zone()) DoWhileStatement(labels); DoWhileStatement* loop = new(zone()) DoWhileStatement(labels);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
...@@ -2194,7 +2189,6 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { ...@@ -2194,7 +2189,6 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
// WhileStatement :: // WhileStatement ::
// 'while' '(' Expression ')' Statement // 'while' '(' Expression ')' Statement
lexical_scope_->AddLoop();
WhileStatement* loop = new(zone()) WhileStatement(labels); WhileStatement* loop = new(zone()) WhileStatement(labels);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
...@@ -2213,7 +2207,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2213,7 +2207,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// ForStatement :: // ForStatement ::
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
lexical_scope_->AddLoop();
Statement* init = NULL; Statement* init = NULL;
Expect(Token::FOR, CHECK_OK); Expect(Token::FOR, CHECK_OK);
...@@ -3530,16 +3523,22 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, ...@@ -3530,16 +3523,22 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
} }
int num_parameters = 0; int num_parameters = 0;
Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
int materialized_literal_count;
int expected_property_count;
int start_pos;
int end_pos;
bool only_simple_this_property_assignments;
Handle<FixedArray> this_property_assignments;
// Parse function body. // Parse function body.
{ Scope* scope = { LexicalScope lexical_scope(this, scope, isolate());
NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
LexicalScope lexical_scope(this, scope, isolate());
top_scope_->SetScopeName(name); top_scope_->SetScopeName(name);
// FormalParameterList :: // FormalParameterList ::
// '(' (Identifier)*[','] ')' // '(' (Identifier)*[','] ')'
Expect(Token::LPAREN, CHECK_OK); 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 name_loc = Scanner::NoLocation();
Scanner::Location dupe_loc = Scanner::NoLocation(); Scanner::Location dupe_loc = Scanner::NoLocation();
Scanner::Location reserved_loc = Scanner::NoLocation(); Scanner::Location reserved_loc = Scanner::NoLocation();
...@@ -3576,7 +3575,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, ...@@ -3576,7 +3575,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
// If we have a named function expression, we add a local variable // If we have a named function expression, we add a local variable
// declaration to the body of the function with the name of the // declaration to the body of the function with the name of the
...@@ -3604,11 +3602,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, ...@@ -3604,11 +3602,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
parenthesized_function_ = false; // The bit was set for this function only. parenthesized_function_ = false; // The bit was set for this function only.
int function_block_pos = scanner().location().beg_pos; 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<FixedArray> this_property_assignments;
if (is_lazily_compiled && pre_data() != NULL) { if (is_lazily_compiled && pre_data() != NULL) {
FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos);
if (!entry.is_valid()) { if (!entry.is_valid()) {
...@@ -3683,25 +3676,24 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, ...@@ -3683,25 +3676,24 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
} }
CheckOctalLiteral(start_pos, end_pos, CHECK_OK); 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;
} }
......
...@@ -232,7 +232,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { ...@@ -232,7 +232,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
} }
{ Comment cmnt(masm_, "[ Stack check"); { Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS); PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
NearLabel ok; NearLabel ok;
__ CompareRoot(rsp, Heap::kStackLimitRootIndex); __ CompareRoot(rsp, Heap::kStackLimitRootIndex);
__ j(above_equal, &ok); __ j(above_equal, &ok);
......
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