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

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: 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 hidden and all scopes in its subscope tree are hidden
vogelheim 2017/02/02 18:28:56 super nitpick: // True if this scope and its enti
marja 2017/02/03 06:48:58 Done.
8839 // too.
8840 static bool IsHiddenLeafScope(Scope* scope) {
vogelheim 2017/02/02 18:28:56 naming nitpick: I'm not super happy with the name,
marja 2017/02/03 06:48:58 Done.
8841 if (!scope->is_hidden()) {
8842 return false;
8843 }
8844 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8845 inner = inner->sibling()) {
8846 if (!IsHiddenLeafScope(inner)) {
8847 return false;
8848 }
8849 }
8850 return true;
8851 }
8852
8838 static void CompareScopeToData(Scope* scope, const PreParsedScopeData* data, 8853 static void CompareScopeToData(Scope* scope, const PreParsedScopeData* data,
8839 size_t& index) { 8854 size_t& index) {
8840 CHECK_EQ(data->backing_store_[index++], scope->scope_type()); 8855 CHECK_EQ(data->backing_store_[index++], scope->scope_type());
8841 CHECK_EQ(data->backing_store_[index++], scope->start_position()); 8856 CHECK_EQ(data->backing_store_[index++], scope->start_position());
8842 CHECK_EQ(data->backing_store_[index++], scope->end_position()); 8857 CHECK_EQ(data->backing_store_[index++], scope->end_position());
8843 8858
8844 int inner_scope_count = 0; 8859 int inner_scope_count = 0;
8845 for (Scope* inner = scope->inner_scope(); inner != nullptr; 8860 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8846 inner = inner->sibling()) { 8861 inner = inner->sibling()) {
8847 if (!inner->is_hidden()) { 8862 // FIXME(marja): This is probably not the right condition for knowing what
8863 // scopes are present in the preparse data.
8864 if (!IsHiddenLeafScope(inner)) {
8848 ++inner_scope_count; 8865 ++inner_scope_count;
8849 } 8866 }
8850 } 8867 }
8851 CHECK_EQ(data->backing_store_[index++], inner_scope_count); 8868 CHECK_EQ(data->backing_store_[index++], inner_scope_count);
8852 8869
8853 int variable_count = 0; 8870 int variable_count = 0;
8854 for (Variable* local : scope->locals_) { 8871 for (Variable* local : scope->locals_) {
8855 if (local->mode() == VAR || local->mode() == LET || 8872 if (local->mode() == VAR || local->mode() == LET ||
8856 local->mode() == CONST) { 8873 local->mode() == CONST) {
8857 ++variable_count; 8874 ++variable_count;
(...skipping 13 matching lines...) Expand all
8871 CHECK_EQ(data->backing_store_[index++], local_name->raw_data()[i]); 8888 CHECK_EQ(data->backing_store_[index++], local_name->raw_data()[i]);
8872 } 8889 }
8873 #endif 8890 #endif
8874 CHECK_EQ(data->backing_store_[index++], local->location()); 8891 CHECK_EQ(data->backing_store_[index++], local->location());
8875 CHECK_EQ(data->backing_store_[index++], local->maybe_assigned()); 8892 CHECK_EQ(data->backing_store_[index++], local->maybe_assigned());
8876 } 8893 }
8877 } 8894 }
8878 8895
8879 for (Scope* inner = scope->inner_scope(); inner != nullptr; 8896 for (Scope* inner = scope->inner_scope(); inner != nullptr;
8880 inner = inner->sibling()) { 8897 inner = inner->sibling()) {
8881 if (!inner->is_hidden()) { 8898 if (!IsHiddenLeafScope(inner)) {
8882 CompareScopeToData(inner, data, index); 8899 CompareScopeToData(inner, data, index);
8883 } 8900 }
8884 } 8901 }
8885 } 8902 }
8886 }; 8903 };
8887 } // namespace internal 8904 } // namespace internal
8888 } // namespace v8 8905 } // namespace v8
8889 8906
8890 // Test that lazily parsed inner functions don't result in overly pessimistic 8907 // Test that lazily parsed inner functions don't result in overly pessimistic
8891 // context allocations. 8908 // context allocations.
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9304 {"", "function f1() { f1; } f1 = 3;"}, 9321 {"", "function f1() { f1; } f1 = 3;"},
9305 {"", "function arguments() {} arguments = 8"}, 9322 {"", "function arguments() {} arguments = 8"},
9306 {"", "function f1() {} f1 = 3; function f1() {}"}, 9323 {"", "function f1() {} f1 = 3; function f1() {}"},
9307 9324
9308 {"", "var var1; eval('');"}, 9325 {"", "var var1; eval('');"},
9309 {"", "var var1; function f1() { eval(''); }"}, 9326 {"", "var var1; function f1() { eval(''); }"},
9310 {"", "let var1; eval('');"}, 9327 {"", "let var1; eval('');"},
9311 {"", "let var1; function f1() { eval(''); }"}, 9328 {"", "let var1; function f1() { eval(''); }"},
9312 {"", "const var1 = 10; eval('');"}, 9329 {"", "const var1 = 10; eval('');"},
9313 {"", "const var1 = 10; function f1() { eval(''); }"}, 9330 {"", "const var1 = 10; function f1() { eval(''); }"},
9331
9332 {"", "for (var var1 = 0; var1 < 10; ++var1) { }"},
9333 {"", "for (let var1 = 0; var1 < 10; ++var1) { }"},
9334 {"", "for (const var1 = 0; var1 < 10; ++var1) { }"},
9335
9336 // FIXME(marja): make the corresponding cases work when foo is a sloppy
9337 // block function.
9338 {"",
9339 "'use strict'; for (var var1 = 0; var1 < 10; ++var1) { function foo() { "
9340 "var1; } }"},
9341 {"",
9342 "'use strict'; for (let var1 = 0; var1 < 10; ++var1) { function foo() { "
9343 "var1; } }"},
9344 {"",
9345 "'use strict'; for (const var1 = 0; var1 < 10; ++var1) { function foo() "
9346 "{ var1; } }"},
9314 }; 9347 };
9315 9348
9316 for (unsigned i = 0; i < arraysize(inners); ++i) { 9349 for (unsigned i = 0; i < arraysize(inners); ++i) {
9317 // First compile with the lazy inner function and extract the scope data. 9350 // First compile with the lazy inner function and extract the scope data.
9318 const char* inner_function = lazy_inner; 9351 const char* inner_function = lazy_inner;
9319 int inner_function_len = Utf8LengthHelper(inner_function) - 4; 9352 int inner_function_len = Utf8LengthHelper(inner_function) - 4;
9320 9353
9321 int params_len = Utf8LengthHelper(inners[i].params); 9354 int params_len = Utf8LengthHelper(inners[i].params);
9322 int source_len = Utf8LengthHelper(inners[i].source); 9355 int source_len = Utf8LengthHelper(inners[i].source);
9323 int len = 9356 int len =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
9373 eager_info.literal()->scope()->inner_scope()->inner_scope(); 9406 eager_info.literal()->scope()->inner_scope()->inner_scope();
9374 DCHECK_NOT_NULL(scope); 9407 DCHECK_NOT_NULL(scope);
9375 DCHECK_NULL(scope->sibling()); 9408 DCHECK_NULL(scope->sibling());
9376 DCHECK(scope->is_function_scope()); 9409 DCHECK(scope->is_function_scope());
9377 9410
9378 size_t index = 0; 9411 size_t index = 0;
9379 i::ScopeTestHelper::CompareScopeToData( 9412 i::ScopeTestHelper::CompareScopeToData(
9380 scope, lazy_info.preparsed_scope_data(), index); 9413 scope, lazy_info.preparsed_scope_data(), index);
9381 } 9414 }
9382 } 9415 }
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