Commit f9e9a016 authored by neis's avatar neis Committed by Commit bot

[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}
parent ee158e6c
...@@ -23,19 +23,14 @@ void ModuleDescriptor::AddImport( ...@@ -23,19 +23,14 @@ void ModuleDescriptor::AddImport(
void ModuleDescriptor::AddStarImport( void ModuleDescriptor::AddStarImport(
const AstRawString* local_name, const AstRawString* module_request, const AstRawString* local_name, const AstRawString* module_request,
Scanner::Location loc, Zone* zone) { Scanner::Location loc, Zone* zone) {
DCHECK_NOT_NULL(local_name);
Entry* entry = new (zone) Entry(loc); Entry* entry = new (zone) Entry(loc);
entry->local_name = local_name; entry->local_name = local_name;
entry->module_request = AddModuleRequest(module_request); entry->module_request = AddModuleRequest(module_request);
AddSpecialImport(entry, zone); AddNamespaceImport(entry, zone);
} }
void ModuleDescriptor::AddEmptyImport(const AstRawString* module_request) {
void ModuleDescriptor::AddEmptyImport( AddModuleRequest(module_request);
const AstRawString* module_request, Scanner::Location loc, Zone* zone) {
Entry* entry = new (zone) Entry(loc);
entry->module_request = AddModuleRequest(module_request);
AddSpecialImport(entry, zone);
} }
......
...@@ -21,7 +21,7 @@ class ModuleDescriptor : public ZoneObject { ...@@ -21,7 +21,7 @@ class ModuleDescriptor : public ZoneObject {
explicit ModuleDescriptor(Zone* zone) explicit ModuleDescriptor(Zone* zone)
: module_requests_(zone), : module_requests_(zone),
special_exports_(1, zone), special_exports_(1, zone),
special_imports_(1, zone), namespace_imports_(1, zone),
regular_exports_(zone), regular_exports_(zone),
regular_imports_(zone) {} regular_imports_(zone) {}
...@@ -44,9 +44,7 @@ class ModuleDescriptor : public ZoneObject { ...@@ -44,9 +44,7 @@ class ModuleDescriptor : public ZoneObject {
// import "foo.js"; // import "foo.js";
// import {} from "foo.js"; // import {} from "foo.js";
// export {} from "foo.js"; (sic!) // export {} from "foo.js"; (sic!)
void AddEmptyImport( void AddEmptyImport(const AstRawString* module_request);
const AstRawString* module_request, const Scanner::Location loc,
Zone* zone);
// export {x}; // export {x};
// export {x as y}; // export {x as y};
...@@ -106,9 +104,9 @@ class ModuleDescriptor : public ZoneObject { ...@@ -106,9 +104,9 @@ class ModuleDescriptor : public ZoneObject {
return module_requests_; return module_requests_;
} }
// Empty imports and namespace imports. // Namespace imports.
const ZoneList<const Entry*>& special_imports() const { const ZoneList<const Entry*>& namespace_imports() const {
return special_imports_; return namespace_imports_;
} }
// All the remaining imports, indexed by local name. // All the remaining imports, indexed by local name.
...@@ -151,10 +149,12 @@ class ModuleDescriptor : public ZoneObject { ...@@ -151,10 +149,12 @@ class ModuleDescriptor : public ZoneObject {
// case we will report an error when declaring the variable. // 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_NULL(entry->export_name);
DCHECK_NOT_NULL(entry->local_name);
DCHECK_LE(0, entry->module_request); DCHECK_LE(0, entry->module_request);
special_imports_.Add(entry, zone); namespace_imports_.Add(entry, zone);
} }
Handle<FixedArray> SerializeRegularExports(Isolate* isolate, Handle<FixedArray> SerializeRegularExports(Isolate* isolate,
...@@ -166,7 +166,7 @@ class ModuleDescriptor : public ZoneObject { ...@@ -166,7 +166,7 @@ class ModuleDescriptor : public ZoneObject {
// TODO(neis): Use STL datastructure instead of ZoneList? // TODO(neis): Use STL datastructure instead of ZoneList?
ZoneMap<const AstRawString*, int> module_requests_; ZoneMap<const AstRawString*, int> module_requests_;
ZoneList<const Entry*> special_exports_; ZoneList<const Entry*> special_exports_;
ZoneList<const Entry*> special_imports_; ZoneList<const Entry*> namespace_imports_;
ZoneMultimap<const AstRawString*, Entry*> regular_exports_; ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
ZoneMap<const AstRawString*, const Entry*> regular_imports_; ZoneMap<const AstRawString*, const Entry*> regular_imports_;
......
...@@ -871,13 +871,13 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, Zone* zone, ...@@ -871,13 +871,13 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, Zone* zone,
} }
} }
// Serialize special imports. // Serialize namespace imports.
Handle<FixedArray> special_imports = Handle<FixedArray> namespace_imports =
isolate->factory()->NewFixedArray(descr->special_imports().length()); isolate->factory()->NewFixedArray(descr->namespace_imports().length());
{ {
int i = 0; int i = 0;
for (auto entry : descr->special_imports()) { for (auto entry : descr->namespace_imports()) {
special_imports->set(i++, *entry->Serialize(isolate)); namespace_imports->set(i++, *entry->Serialize(isolate));
} }
} }
...@@ -899,7 +899,7 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, Zone* zone, ...@@ -899,7 +899,7 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, Zone* zone,
result->set(kModuleRequestsIndex, *module_requests); result->set(kModuleRequestsIndex, *module_requests);
result->set(kSpecialExportsIndex, *special_exports); result->set(kSpecialExportsIndex, *special_exports);
result->set(kRegularExportsIndex, *regular_exports); result->set(kRegularExportsIndex, *regular_exports);
result->set(kSpecialImportsIndex, *special_imports); result->set(kNamespaceImportsIndex, *namespace_imports);
result->set(kRegularImportsIndex, *regular_imports); result->set(kRegularImportsIndex, *regular_imports);
return result; return result;
} }
......
...@@ -185,12 +185,13 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info, ...@@ -185,12 +185,13 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
module_descriptor_->DeserializeRegularExports(isolate, avfactory, module_descriptor_->DeserializeRegularExports(isolate, avfactory,
regular_exports); regular_exports);
// Deserialize special imports. // Deserialize namespace imports.
Handle<FixedArray> special_imports(module_info->special_imports(), isolate); Handle<FixedArray> namespace_imports(module_info->namespace_imports(),
for (int i = 0, n = special_imports->length(); i < n; ++i) { isolate);
for (int i = 0, n = namespace_imports->length(); i < n; ++i) {
Handle<ModuleInfoEntry> serialized_entry( Handle<ModuleInfoEntry> serialized_entry(
ModuleInfoEntry::cast(special_imports->get(i)), isolate); ModuleInfoEntry::cast(namespace_imports->get(i)), isolate);
module_descriptor_->AddSpecialImport( module_descriptor_->AddNamespaceImport(
ModuleDescriptor::Entry::Deserialize(isolate, avfactory, ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
serialized_entry), serialized_entry),
avfactory->zone()); avfactory->zone());
......
...@@ -7985,8 +7985,8 @@ FixedArray* ModuleInfo::regular_imports() const { ...@@ -7985,8 +7985,8 @@ FixedArray* ModuleInfo::regular_imports() const {
return FixedArray::cast(get(kRegularImportsIndex)); return FixedArray::cast(get(kRegularImportsIndex));
} }
FixedArray* ModuleInfo::special_imports() const { FixedArray* ModuleInfo::namespace_imports() const {
return FixedArray::cast(get(kSpecialImportsIndex)); return FixedArray::cast(get(kNamespaceImportsIndex));
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -7994,7 +7994,7 @@ bool ModuleInfo::Equals(ModuleInfo* other) const { ...@@ -7994,7 +7994,7 @@ bool ModuleInfo::Equals(ModuleInfo* other) const {
return regular_exports() == other->regular_exports() && return regular_exports() == other->regular_exports() &&
regular_imports() == other->regular_imports() && regular_imports() == other->regular_imports() &&
special_exports() == other->special_exports() && special_exports() == other->special_exports() &&
special_imports() == other->special_imports(); namespace_imports() == other->namespace_imports();
} }
#endif #endif
......
...@@ -4587,7 +4587,7 @@ class ModuleInfo : public FixedArray { ...@@ -4587,7 +4587,7 @@ class ModuleInfo : public FixedArray {
inline FixedArray* module_requests() const; inline FixedArray* module_requests() const;
inline FixedArray* special_exports() const; inline FixedArray* special_exports() const;
inline FixedArray* regular_exports() const; inline FixedArray* regular_exports() const;
inline FixedArray* special_imports() const; inline FixedArray* namespace_imports() const;
inline FixedArray* regular_imports() const; inline FixedArray* regular_imports() const;
#ifdef DEBUG #ifdef DEBUG
...@@ -4600,7 +4600,7 @@ class ModuleInfo : public FixedArray { ...@@ -4600,7 +4600,7 @@ class ModuleInfo : public FixedArray {
kModuleRequestsIndex, kModuleRequestsIndex,
kSpecialExportsIndex, kSpecialExportsIndex,
kRegularExportsIndex, kRegularExportsIndex,
kSpecialImportsIndex, kNamespaceImportsIndex,
kRegularImportsIndex, kRegularImportsIndex,
kLength kLength
}; };
......
...@@ -1208,7 +1208,7 @@ void Parser::ParseImportDeclaration(bool* ok) { ...@@ -1208,7 +1208,7 @@ void Parser::ParseImportDeclaration(bool* ok) {
if (tok == Token::STRING) { if (tok == Token::STRING) {
const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID);
ExpectSemicolon(CHECK_OK_VOID); ExpectSemicolon(CHECK_OK_VOID);
module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); module()->AddEmptyImport(module_specifier);
return; return;
} }
...@@ -1276,7 +1276,7 @@ void Parser::ParseImportDeclaration(bool* ok) { ...@@ -1276,7 +1276,7 @@ void Parser::ParseImportDeclaration(bool* ok) {
if (named_imports != nullptr) { if (named_imports != nullptr) {
if (named_imports->length() == 0) { if (named_imports->length() == 0) {
module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); module()->AddEmptyImport(module_specifier);
} else { } else {
for (int i = 0; i < named_imports->length(); ++i) { for (int i = 0; i < named_imports->length(); ++i) {
const NamedImport* import = named_imports->at(i); const NamedImport* import = named_imports->at(i);
...@@ -1415,8 +1415,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1415,8 +1415,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
export_locations[i], zone()); export_locations[i], zone());
} }
} else if (length == 0) { } else if (length == 0) {
module()->AddEmptyImport(module_specifier, scanner()->location(), module()->AddEmptyImport(module_specifier);
zone());
} else { } else {
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
module()->AddExport(original_names[i], export_names[i], module()->AddExport(original_names[i], export_names[i],
......
...@@ -6169,10 +6169,10 @@ TEST(ModuleParsingInternals) { ...@@ -6169,10 +6169,10 @@ TEST(ModuleParsingInternals) {
CheckEntry(entry, "y", "x", nullptr, -1); CheckEntry(entry, "y", "x", nullptr, -1);
} }
CHECK_EQ(3, descriptor->special_imports().length()); CHECK_EQ(2, descriptor->namespace_imports().length());
CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr, 3); CheckEntry(descriptor->namespace_imports().at(0), nullptr, "loo", nullptr, 4);
CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr, 4); CheckEntry(descriptor->namespace_imports().at(1), nullptr, "foob", nullptr,
CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr, 4); 4);
CHECK_EQ(4, descriptor->regular_imports().size()); CHECK_EQ(4, descriptor->regular_imports().size());
entry = descriptor->regular_imports().find( entry = descriptor->regular_imports().find(
......
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