Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: src/parser.cc

Issue 6311005: Don't lazily compile functions that are immediately receded by '('. (Closed)
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 script_(script), 593 script_(script),
594 scanner_(), 594 scanner_(),
595 top_scope_(NULL), 595 top_scope_(NULL),
596 with_nesting_level_(0), 596 with_nesting_level_(0),
597 temp_scope_(NULL), 597 temp_scope_(NULL),
598 target_stack_(NULL), 598 target_stack_(NULL),
599 allow_natives_syntax_(allow_natives_syntax), 599 allow_natives_syntax_(allow_natives_syntax),
600 extension_(extension), 600 extension_(extension),
601 pre_data_(pre_data), 601 pre_data_(pre_data),
602 fni_(NULL), 602 fni_(NULL),
603 stack_overflow_(false) { 603 stack_overflow_(false),
604 parenthesized_function_(false) {
604 AstNode::ResetIds(); 605 AstNode::ResetIds();
605 } 606 }
606 607
607 608
608 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 609 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
609 bool in_global_context) { 610 bool in_global_context) {
610 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 611 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
611 612
612 HistogramTimerScope timer(&Counters::parse); 613 HistogramTimerScope timer(&Counters::parse);
613 Counters::total_parse_size.Increment(source->length()); 614 Counters::total_parse_size.Increment(source->length());
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2476
2476 case Token::LPAREN: { 2477 case Token::LPAREN: {
2477 int pos = scanner().location().beg_pos; 2478 int pos = scanner().location().beg_pos;
2478 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2479 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2479 2480
2480 // Keep track of eval() calls since they disable all local variable 2481 // Keep track of eval() calls since they disable all local variable
2481 // optimizations. 2482 // optimizations.
2482 // The calls that need special treatment are the 2483 // The calls that need special treatment are the
2483 // direct (i.e. not aliased) eval calls. These calls are all of the 2484 // direct (i.e. not aliased) eval calls. These calls are all of the
2484 // form eval(...) with no explicit receiver object where eval is not 2485 // form eval(...) with no explicit receiver object where eval is not
2485 // declared in the current scope chain. These calls are marked as 2486 // declared in the current scope chain.
2486 // potentially direct eval calls. Whether they are actually direct calls 2487 // These calls are marked as potentially direct eval calls. Whether
2487 // to eval is determined at run time. 2488 // they are actually direct calls to eval is determined at run time.
2489 // TODO(994): In ES5, it doesn't matter if the "eval" var is declared
2490 // in the local scope chain. It only matters that it's called "eval",
2491 // is called without a receiver and it refers to the original eval
2492 // function.
2488 VariableProxy* callee = result->AsVariableProxy(); 2493 VariableProxy* callee = result->AsVariableProxy();
2489 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) { 2494 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
2490 Handle<String> name = callee->name(); 2495 Handle<String> name = callee->name();
2491 Variable* var = top_scope_->Lookup(name); 2496 Variable* var = top_scope_->Lookup(name);
2492 if (var == NULL) { 2497 if (var == NULL) {
2493 top_scope_->RecordEvalCall(); 2498 top_scope_->RecordEvalCall();
2494 } 2499 }
2495 } 2500 }
2496 result = NewCall(result, args, pos); 2501 result = NewCall(result, args, pos);
2497 break; 2502 break;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 case Token::LBRACK: 2732 case Token::LBRACK:
2728 result = ParseArrayLiteral(CHECK_OK); 2733 result = ParseArrayLiteral(CHECK_OK);
2729 break; 2734 break;
2730 2735
2731 case Token::LBRACE: 2736 case Token::LBRACE:
2732 result = ParseObjectLiteral(CHECK_OK); 2737 result = ParseObjectLiteral(CHECK_OK);
2733 break; 2738 break;
2734 2739
2735 case Token::LPAREN: 2740 case Token::LPAREN:
2736 Consume(Token::LPAREN); 2741 Consume(Token::LPAREN);
2742 // Heuristically try to detect immediately called functions before
2743 // seeing the call parentheses.
2744 parenthesized_function_ = (peek() == Token::FUNCTION);
2737 result = ParseExpression(true, CHECK_OK); 2745 result = ParseExpression(true, CHECK_OK);
2738 Expect(Token::RPAREN, CHECK_OK); 2746 Expect(Token::RPAREN, CHECK_OK);
2739 break; 2747 break;
2740 2748
2741 case Token::MOD: 2749 case Token::MOD:
2742 if (allow_natives_syntax_ || extension_ != NULL) { 2750 if (allow_natives_syntax_ || extension_ != NULL) {
2743 result = ParseV8Intrinsic(CHECK_OK); 2751 result = ParseV8Intrinsic(CHECK_OK);
2744 break; 2752 break;
2745 } 2753 }
2746 // If we're not allowing special syntax we fall-through to the 2754 // If we're not allowing special syntax we fall-through to the
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 top_scope_->NewUnresolved(function_name, inside_with()); 3226 top_scope_->NewUnresolved(function_name, inside_with());
3219 fproxy->BindTo(fvar); 3227 fproxy->BindTo(fvar);
3220 body->Add(new ExpressionStatement( 3228 body->Add(new ExpressionStatement(
3221 new Assignment(Token::INIT_CONST, fproxy, 3229 new Assignment(Token::INIT_CONST, fproxy,
3222 new ThisFunction(), 3230 new ThisFunction(),
3223 RelocInfo::kNoPosition))); 3231 RelocInfo::kNoPosition)));
3224 } 3232 }
3225 3233
3226 // Determine if the function will be lazily compiled. The mode can 3234 // Determine if the function will be lazily compiled. The mode can
3227 // only be PARSE_LAZILY if the --lazy flag is true. 3235 // only be PARSE_LAZILY if the --lazy flag is true.
3228 bool is_lazily_compiled = 3236 bool is_lazily_compiled = (mode() == PARSE_LAZILY &&
3229 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext(); 3237 top_scope_->outer_scope()->is_global_scope() &&
3238 top_scope_->HasTrivialOuterContext() &&
3239 !parenthesized_function_);
3240 parenthesized_function_ = false; // The bit was set for this function only.
3230 3241
3231 int function_block_pos = scanner().location().beg_pos; 3242 int function_block_pos = scanner().location().beg_pos;
3232 int materialized_literal_count; 3243 int materialized_literal_count;
3233 int expected_property_count; 3244 int expected_property_count;
3234 int end_pos; 3245 int end_pos;
3235 bool only_simple_this_property_assignments; 3246 bool only_simple_this_property_assignments;
3236 Handle<FixedArray> this_property_assignments; 3247 Handle<FixedArray> this_property_assignments;
3237 if (is_lazily_compiled && pre_data() != NULL) { 3248 if (is_lazily_compiled && pre_data() != NULL) {
3238 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); 3249 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos);
3239 if (!entry.is_valid()) { 3250 if (!entry.is_valid()) {
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
4695 Handle<String> source = Handle<String>(String::cast(script->source())); 4706 Handle<String> source = Handle<String>(String::cast(script->source()));
4696 result = parser.ParseProgram(source, info->is_global()); 4707 result = parser.ParseProgram(source, info->is_global());
4697 } 4708 }
4698 } 4709 }
4699 4710
4700 info->SetFunction(result); 4711 info->SetFunction(result);
4701 return (result != NULL); 4712 return (result != NULL);
4702 } 4713 }
4703 4714
4704 } } // namespace v8::internal 4715 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698