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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 2669163002: [parser] Skipping inner funcs: produce the same scopes / variables for (some) loops. (Closed)
Patch Set: code review (vogelheim@) Created 3 years, 10 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/parsing/preparser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 8817 matching lines...) Expand 10 before | Expand all | Expand 10 after
8828 8828
8829 namespace v8 { 8829 namespace v8 {
8830 namespace internal { 8830 namespace internal {
8831 8831
8832 class ScopeTestHelper { 8832 class ScopeTestHelper {
8833 public: 8833 public:
8834 static bool MustAllocateInContext(Variable* var) { 8834 static bool MustAllocateInContext(Variable* var) {
8835 return var->scope()->MustAllocateInContext(var); 8835 return var->scope()->MustAllocateInContext(var);
8836 } 8836 }
8837 8837
8838 // True if the scope is and its entire subscope tree are hidden.
8839 static bool ScopeTreeIsHidden(Scope* scope) {
8840 if (!scope->is_hidden()) {
8841 return false;
8842 }
8843 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8844 inner = inner->sibling()) {
8845 if (!ScopeTreeIsHidden(inner)) {
8846 return false;
8847 }
8848 }
8849 return true;
8850 }
8851
8838 static void CompareScopeToData(Scope* scope, const PreParsedScopeData* data, 8852 static void CompareScopeToData(Scope* scope, const PreParsedScopeData* data,
8839 size_t& index) { 8853 size_t& index) {
8840 CHECK_EQ(data->backing_store_[index++], scope->scope_type()); 8854 CHECK_EQ(data->backing_store_[index++], scope->scope_type());
8841 CHECK_EQ(data->backing_store_[index++], scope->start_position()); 8855 CHECK_EQ(data->backing_store_[index++], scope->start_position());
8842 CHECK_EQ(data->backing_store_[index++], scope->end_position()); 8856 CHECK_EQ(data->backing_store_[index++], scope->end_position());
8843 8857
8844 int inner_scope_count = 0; 8858 int inner_scope_count = 0;
8845 for (Scope* inner = scope->inner_scope(); inner != nullptr; 8859 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8846 inner = inner->sibling()) { 8860 inner = inner->sibling()) {
8847 if (!inner->is_hidden()) { 8861 // FIXME(marja): This is probably not the right condition for knowing what
8862 // scopes are present in the preparse data.
8863 if (!ScopeTreeIsHidden(inner)) {
8848 ++inner_scope_count; 8864 ++inner_scope_count;
8849 } 8865 }
8850 } 8866 }
8851 CHECK_EQ(data->backing_store_[index++], inner_scope_count); 8867 CHECK_EQ(data->backing_store_[index++], inner_scope_count);
8852 8868
8853 int variable_count = 0; 8869 int variable_count = 0;
8854 for (Variable* local : scope->locals_) { 8870 for (Variable* local : scope->locals_) {
8855 if (local->mode() == VAR || local->mode() == LET || 8871 if (local->mode() == VAR || local->mode() == LET ||
8856 local->mode() == CONST) { 8872 local->mode() == CONST) {
8857 ++variable_count; 8873 ++variable_count;
(...skipping 13 matching lines...) Expand all
8871 CHECK_EQ(data->backing_store_[index++], local_name->raw_data()[i]); 8887 CHECK_EQ(data->backing_store_[index++], local_name->raw_data()[i]);
8872 } 8888 }
8873 #endif 8889 #endif
8874 CHECK_EQ(data->backing_store_[index++], local->location()); 8890 CHECK_EQ(data->backing_store_[index++], local->location());
8875 CHECK_EQ(data->backing_store_[index++], local->maybe_assigned()); 8891 CHECK_EQ(data->backing_store_[index++], local->maybe_assigned());
8876 } 8892 }
8877 } 8893 }
8878 8894
8879 for (Scope* inner = scope->inner_scope(); inner != nullptr; 8895 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8880 inner = inner->sibling()) { 8896 inner = inner->sibling()) {
8881 if (!inner->is_hidden()) { 8897 if (!ScopeTreeIsHidden(inner)) {
8882 CompareScopeToData(inner, data, index); 8898 CompareScopeToData(inner, data, index);
8883 } 8899 }
8884 } 8900 }
8885 } 8901 }
8886 }; 8902 };
8887 } // namespace internal 8903 } // namespace internal
8888 } // namespace v8 8904 } // namespace v8
8889 8905
8890 // Test that lazily parsed inner functions don't result in overly pessimistic 8906 // Test that lazily parsed inner functions don't result in overly pessimistic
8891 // context allocations. 8907 // context allocations.
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9304 {"", "function f1() { f1; } f1 = 3;"}, 9320 {"", "function f1() { f1; } f1 = 3;"},
9305 {"", "function arguments() {} arguments = 8"}, 9321 {"", "function arguments() {} arguments = 8"},
9306 {"", "function f1() {} f1 = 3; function f1() {}"}, 9322 {"", "function f1() {} f1 = 3; function f1() {}"},
9307 9323
9308 {"", "var var1; eval('');"}, 9324 {"", "var var1; eval('');"},
9309 {"", "var var1; function f1() { eval(''); }"}, 9325 {"", "var var1; function f1() { eval(''); }"},
9310 {"", "let var1; eval('');"}, 9326 {"", "let var1; eval('');"},
9311 {"", "let var1; function f1() { eval(''); }"}, 9327 {"", "let var1; function f1() { eval(''); }"},
9312 {"", "const var1 = 10; eval('');"}, 9328 {"", "const var1 = 10; eval('');"},
9313 {"", "const var1 = 10; function f1() { eval(''); }"}, 9329 {"", "const var1 = 10; function f1() { eval(''); }"},
9330
9331 {"", "for (var var1 = 0; var1 < 10; ++var1) { }"},
9332 {"", "for (let var1 = 0; var1 < 10; ++var1) { }"},
9333 {"", "for (const var1 = 0; var1 < 10; ++var1) { }"},
9334
9335 // FIXME(marja): make the corresponding cases work when foo is a sloppy
9336 // block function.
9337 {"",
9338 "'use strict'; for (var var1 = 0; var1 < 10; ++var1) { function foo() { "
9339 "var1; } }"},
9340 {"",
9341 "'use strict'; for (let var1 = 0; var1 < 10; ++var1) { function foo() { "
9342 "var1; } }"},
9343 {"",
9344 "'use strict'; for (const var1 = 0; var1 < 10; ++var1) { function foo() "
9345 "{ var1; } }"},
9314 }; 9346 };
9315 9347
9316 for (unsigned i = 0; i < arraysize(inners); ++i) { 9348 for (unsigned i = 0; i < arraysize(inners); ++i) {
9317 // First compile with the lazy inner function and extract the scope data. 9349 // First compile with the lazy inner function and extract the scope data.
9318 const char* inner_function = lazy_inner; 9350 const char* inner_function = lazy_inner;
9319 int inner_function_len = Utf8LengthHelper(inner_function) - 4; 9351 int inner_function_len = Utf8LengthHelper(inner_function) - 4;
9320 9352
9321 int params_len = Utf8LengthHelper(inners[i].params); 9353 int params_len = Utf8LengthHelper(inners[i].params);
9322 int source_len = Utf8LengthHelper(inners[i].source); 9354 int source_len = Utf8LengthHelper(inners[i].source);
9323 int len = 9355 int len =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
9373 eager_info.literal()->scope()->inner_scope()->inner_scope(); 9405 eager_info.literal()->scope()->inner_scope()->inner_scope();
9374 DCHECK_NOT_NULL(scope); 9406 DCHECK_NOT_NULL(scope);
9375 DCHECK_NULL(scope->sibling()); 9407 DCHECK_NULL(scope->sibling());
9376 DCHECK(scope->is_function_scope()); 9408 DCHECK(scope->is_function_scope());
9377 9409
9378 size_t index = 0; 9410 size_t index = 0;
9379 i::ScopeTestHelper::CompareScopeToData( 9411 i::ScopeTestHelper::CompareScopeToData(
9380 scope, lazy_info.preparsed_scope_data(), index); 9412 scope, lazy_info.preparsed_scope_data(), index);
9381 } 9413 }
9382 } 9414 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698