From f9e9a016611b3ed2206ff3b025d069dc5108709e Mon Sep 17 00:00:00 2001 From: neis Date: Fri, 23 Sep 2016 12:35:46 -0700 Subject: [PATCH] [modules] Simplify treatment of empty imports. There's no reason (anymore) to have empty imports in special_imports. Remove them from there and rename special_imports to namespace_imports to be more precise. R=adamk@chromium.org BUG=v8:1569 Review-Url: https://codereview.chromium.org/2368613002 Cr-Commit-Position: refs/heads/master@{#39693} --- src/ast/modules.cc | 11 +++-------- src/ast/modules.h | 20 ++++++++++---------- src/ast/scopeinfo.cc | 12 ++++++------ src/ast/scopes.cc | 11 ++++++----- src/objects-inl.h | 6 +++--- src/objects.h | 4 ++-- src/parsing/parser.cc | 7 +++---- test/cctest/test-parsing.cc | 8 ++++---- 8 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/ast/modules.cc b/src/ast/modules.cc index 6a0f26a895..2d28d5564b 100644 --- a/src/ast/modules.cc +++ b/src/ast/modules.cc @@ -23,19 +23,14 @@ void ModuleDescriptor::AddImport( void ModuleDescriptor::AddStarImport( const AstRawString* local_name, const AstRawString* module_request, Scanner::Location loc, Zone* zone) { - DCHECK_NOT_NULL(local_name); Entry* entry = new (zone) Entry(loc); entry->local_name = local_name; entry->module_request = AddModuleRequest(module_request); - AddSpecialImport(entry, zone); + AddNamespaceImport(entry, zone); } - -void ModuleDescriptor::AddEmptyImport( - const AstRawString* module_request, Scanner::Location loc, Zone* zone) { - Entry* entry = new (zone) Entry(loc); - entry->module_request = AddModuleRequest(module_request); - AddSpecialImport(entry, zone); +void ModuleDescriptor::AddEmptyImport(const AstRawString* module_request) { + AddModuleRequest(module_request); } diff --git a/src/ast/modules.h b/src/ast/modules.h index a7d674144b..4d36735fa8 100644 --- a/src/ast/modules.h +++ b/src/ast/modules.h @@ -21,7 +21,7 @@ class ModuleDescriptor : public ZoneObject { explicit ModuleDescriptor(Zone* zone) : module_requests_(zone), special_exports_(1, zone), - special_imports_(1, zone), + namespace_imports_(1, zone), regular_exports_(zone), regular_imports_(zone) {} @@ -44,9 +44,7 @@ class ModuleDescriptor : public ZoneObject { // import "foo.js"; // import {} from "foo.js"; // export {} from "foo.js"; (sic!) - void AddEmptyImport( - const AstRawString* module_request, const Scanner::Location loc, - Zone* zone); + void AddEmptyImport(const AstRawString* module_request); // export {x}; // export {x as y}; @@ -106,9 +104,9 @@ class ModuleDescriptor : public ZoneObject { return module_requests_; } - // Empty imports and namespace imports. - const ZoneList& special_imports() const { - return special_imports_; + // Namespace imports. + const ZoneList& namespace_imports() const { + return namespace_imports_; } // All the remaining imports, indexed by local name. @@ -151,10 +149,12 @@ class ModuleDescriptor : public ZoneObject { // case we will report an error when declaring the variable. } - void AddSpecialImport(const Entry* entry, Zone* zone) { + void AddNamespaceImport(const Entry* entry, Zone* zone) { + DCHECK_NULL(entry->import_name); DCHECK_NULL(entry->export_name); + DCHECK_NOT_NULL(entry->local_name); DCHECK_LE(0, entry->module_request); - special_imports_.Add(entry, zone); + namespace_imports_.Add(entry, zone); } Handle SerializeRegularExports(Isolate* isolate, @@ -166,7 +166,7 @@ class ModuleDescriptor : public ZoneObject { // TODO(neis): Use STL datastructure instead of ZoneList? ZoneMap module_requests_; ZoneList special_exports_; - ZoneList special_imports_; + ZoneList namespace_imports_; ZoneMultimap regular_exports_; ZoneMap regular_imports_; diff --git a/src/ast/scopeinfo.cc b/src/ast/scopeinfo.cc index c2ed3aeb53..5354b8d737 100644 --- a/src/ast/scopeinfo.cc +++ b/src/ast/scopeinfo.cc @@ -871,13 +871,13 @@ Handle ModuleInfo::New(Isolate* isolate, Zone* zone, } } - // Serialize special imports. - Handle special_imports = - isolate->factory()->NewFixedArray(descr->special_imports().length()); + // Serialize namespace imports. + Handle namespace_imports = + isolate->factory()->NewFixedArray(descr->namespace_imports().length()); { int i = 0; - for (auto entry : descr->special_imports()) { - special_imports->set(i++, *entry->Serialize(isolate)); + for (auto entry : descr->namespace_imports()) { + namespace_imports->set(i++, *entry->Serialize(isolate)); } } @@ -899,7 +899,7 @@ Handle ModuleInfo::New(Isolate* isolate, Zone* zone, result->set(kModuleRequestsIndex, *module_requests); result->set(kSpecialExportsIndex, *special_exports); result->set(kRegularExportsIndex, *regular_exports); - result->set(kSpecialImportsIndex, *special_imports); + result->set(kNamespaceImportsIndex, *namespace_imports); result->set(kRegularImportsIndex, *regular_imports); return result; } diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index cd0c1eacd4..b6ae337877 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -185,12 +185,13 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle scope_info, module_descriptor_->DeserializeRegularExports(isolate, avfactory, regular_exports); - // Deserialize special imports. - Handle special_imports(module_info->special_imports(), isolate); - for (int i = 0, n = special_imports->length(); i < n; ++i) { + // Deserialize namespace imports. + Handle namespace_imports(module_info->namespace_imports(), + isolate); + for (int i = 0, n = namespace_imports->length(); i < n; ++i) { Handle serialized_entry( - ModuleInfoEntry::cast(special_imports->get(i)), isolate); - module_descriptor_->AddSpecialImport( + ModuleInfoEntry::cast(namespace_imports->get(i)), isolate); + module_descriptor_->AddNamespaceImport( ModuleDescriptor::Entry::Deserialize(isolate, avfactory, serialized_entry), avfactory->zone()); diff --git a/src/objects-inl.h b/src/objects-inl.h index 534d8a5541..b1cfceea77 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -7985,8 +7985,8 @@ FixedArray* ModuleInfo::regular_imports() const { return FixedArray::cast(get(kRegularImportsIndex)); } -FixedArray* ModuleInfo::special_imports() const { - return FixedArray::cast(get(kSpecialImportsIndex)); +FixedArray* ModuleInfo::namespace_imports() const { + return FixedArray::cast(get(kNamespaceImportsIndex)); } #ifdef DEBUG @@ -7994,7 +7994,7 @@ bool ModuleInfo::Equals(ModuleInfo* other) const { return regular_exports() == other->regular_exports() && regular_imports() == other->regular_imports() && special_exports() == other->special_exports() && - special_imports() == other->special_imports(); + namespace_imports() == other->namespace_imports(); } #endif diff --git a/src/objects.h b/src/objects.h index 3acd8ff2b0..ca3c8f89b7 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4587,7 +4587,7 @@ class ModuleInfo : public FixedArray { inline FixedArray* module_requests() const; inline FixedArray* special_exports() const; inline FixedArray* regular_exports() const; - inline FixedArray* special_imports() const; + inline FixedArray* namespace_imports() const; inline FixedArray* regular_imports() const; #ifdef DEBUG @@ -4600,7 +4600,7 @@ class ModuleInfo : public FixedArray { kModuleRequestsIndex, kSpecialExportsIndex, kRegularExportsIndex, - kSpecialImportsIndex, + kNamespaceImportsIndex, kRegularImportsIndex, kLength }; diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 29b26055c3..6c0b58e2b2 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -1208,7 +1208,7 @@ void Parser::ParseImportDeclaration(bool* ok) { if (tok == Token::STRING) { const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); ExpectSemicolon(CHECK_OK_VOID); - module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); + module()->AddEmptyImport(module_specifier); return; } @@ -1276,7 +1276,7 @@ void Parser::ParseImportDeclaration(bool* ok) { if (named_imports != nullptr) { if (named_imports->length() == 0) { - module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); + module()->AddEmptyImport(module_specifier); } else { for (int i = 0; i < named_imports->length(); ++i) { const NamedImport* import = named_imports->at(i); @@ -1415,8 +1415,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { export_locations[i], zone()); } } else if (length == 0) { - module()->AddEmptyImport(module_specifier, scanner()->location(), - zone()); + module()->AddEmptyImport(module_specifier); } else { for (int i = 0; i < length; ++i) { module()->AddExport(original_names[i], export_names[i], diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index f3fd6af7af..b53fc4d758 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -6169,10 +6169,10 @@ TEST(ModuleParsingInternals) { CheckEntry(entry, "y", "x", nullptr, -1); } - CHECK_EQ(3, descriptor->special_imports().length()); - CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr, 3); - CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr, 4); - CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr, 4); + CHECK_EQ(2, descriptor->namespace_imports().length()); + CheckEntry(descriptor->namespace_imports().at(0), nullptr, "loo", nullptr, 4); + CheckEntry(descriptor->namespace_imports().at(1), nullptr, "foob", nullptr, + 4); CHECK_EQ(4, descriptor->regular_imports().size()); entry = descriptor->regular_imports().find(