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(
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);
}
......
......@@ -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<const Entry*>& special_imports() const {
return special_imports_;
// Namespace imports.
const ZoneList<const Entry*>& 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<FixedArray> SerializeRegularExports(Isolate* isolate,
......@@ -166,7 +166,7 @@ class ModuleDescriptor : public ZoneObject {
// TODO(neis): Use STL datastructure instead of ZoneList?
ZoneMap<const AstRawString*, int> module_requests_;
ZoneList<const Entry*> special_exports_;
ZoneList<const Entry*> special_imports_;
ZoneList<const Entry*> namespace_imports_;
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
ZoneMap<const AstRawString*, const Entry*> regular_imports_;
......
......@@ -871,13 +871,13 @@ Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, Zone* zone,
}
}
// Serialize special imports.
Handle<FixedArray> special_imports =
isolate->factory()->NewFixedArray(descr->special_imports().length());
// Serialize namespace imports.
Handle<FixedArray> 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> 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;
}
......
......@@ -185,12 +185,13 @@ ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
module_descriptor_->DeserializeRegularExports(isolate, avfactory,
regular_exports);
// Deserialize special imports.
Handle<FixedArray> special_imports(module_info->special_imports(), isolate);
for (int i = 0, n = special_imports->length(); i < n; ++i) {
// Deserialize namespace imports.
Handle<FixedArray> namespace_imports(module_info->namespace_imports(),
isolate);
for (int i = 0, n = namespace_imports->length(); i < n; ++i) {
Handle<ModuleInfoEntry> 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());
......
......@@ -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
......
......@@ -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
};
......
......@@ -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],
......
......@@ -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(
......
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