[modules] Don't deserialize module descriptor
... as it can be expensive and there are no users of it anymore (we just read the information directly from ModuleInfo instead). Bug: v8:8847 Change-Id: I30a3bec186fbdea3821979e642b27b3b827309ce Reviewed-on: https://chromium-review.googlesource.com/c/1477220 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{#59718}
This commit is contained in:
parent
6b132181eb
commit
274075fb85
@ -91,20 +91,11 @@ void ModuleDescriptor::AddStarExport(const AstRawString* module_request,
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Handle<Object> ToStringOrUndefined(Isolate* isolate, const AstRawString* s) {
|
||||
return (s == nullptr)
|
||||
? Handle<Object>::cast(isolate->factory()->undefined_value())
|
||||
: Handle<Object>::cast(s->string());
|
||||
}
|
||||
|
||||
const AstRawString* FromStringOrUndefined(Isolate* isolate,
|
||||
AstValueFactory* avfactory,
|
||||
Handle<Object> object) {
|
||||
if (object->IsUndefined(isolate)) return nullptr;
|
||||
return avfactory->GetString(Handle<String>::cast(object));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Handle<ModuleInfoEntry> ModuleDescriptor::Entry::Serialize(
|
||||
@ -117,21 +108,6 @@ Handle<ModuleInfoEntry> ModuleDescriptor::Entry::Serialize(
|
||||
location.beg_pos, location.end_pos);
|
||||
}
|
||||
|
||||
ModuleDescriptor::Entry* ModuleDescriptor::Entry::Deserialize(
|
||||
Isolate* isolate, AstValueFactory* avfactory,
|
||||
Handle<ModuleInfoEntry> entry) {
|
||||
Entry* result = new (avfactory->zone()) Entry(Scanner::Location::invalid());
|
||||
result->export_name = FromStringOrUndefined(
|
||||
isolate, avfactory, handle(entry->export_name(), isolate));
|
||||
result->local_name = FromStringOrUndefined(
|
||||
isolate, avfactory, handle(entry->local_name(), isolate));
|
||||
result->import_name = FromStringOrUndefined(
|
||||
isolate, avfactory, handle(entry->import_name(), isolate));
|
||||
result->module_request = entry->module_request();
|
||||
result->cell_index = entry->cell_index();
|
||||
return result;
|
||||
}
|
||||
|
||||
Handle<FixedArray> ModuleDescriptor::SerializeRegularExports(Isolate* isolate,
|
||||
Zone* zone) const {
|
||||
// We serialize regular exports in a way that lets us later iterate over their
|
||||
@ -183,29 +159,6 @@ Handle<FixedArray> ModuleDescriptor::SerializeRegularExports(Isolate* isolate,
|
||||
return result;
|
||||
}
|
||||
|
||||
void ModuleDescriptor::DeserializeRegularExports(
|
||||
Isolate* isolate, AstValueFactory* avfactory,
|
||||
Handle<ModuleInfo> module_info) {
|
||||
for (int i = 0, count = module_info->RegularExportCount(); i < count; ++i) {
|
||||
Handle<String> local_name(module_info->RegularExportLocalName(i), isolate);
|
||||
int cell_index = module_info->RegularExportCellIndex(i);
|
||||
Handle<FixedArray> export_names(module_info->RegularExportExportNames(i),
|
||||
isolate);
|
||||
|
||||
for (int j = 0, length = export_names->length(); j < length; ++j) {
|
||||
Handle<String> export_name(String::cast(export_names->get(j)), isolate);
|
||||
|
||||
Entry* entry =
|
||||
new (avfactory->zone()) Entry(Scanner::Location::invalid());
|
||||
entry->local_name = avfactory->GetString(local_name);
|
||||
entry->export_name = avfactory->GetString(export_name);
|
||||
entry->cell_index = cell_index;
|
||||
|
||||
AddRegularExport(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
|
||||
for (auto it = regular_exports_.begin(); it != regular_exports_.end();) {
|
||||
Entry* entry = it->second;
|
||||
|
@ -107,12 +107,7 @@ class ModuleDescriptor : public ZoneObject {
|
||||
module_request(-1),
|
||||
cell_index(0) {}
|
||||
|
||||
// (De-)serialization support.
|
||||
// Note that the location value is not preserved as it's only needed by the
|
||||
// parser. (A Deserialize'd entry has an invalid location.)
|
||||
Handle<ModuleInfoEntry> Serialize(Isolate* isolate) const;
|
||||
static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory,
|
||||
Handle<ModuleInfoEntry> entry);
|
||||
};
|
||||
|
||||
enum CellIndexKind { kInvalid, kExport, kImport };
|
||||
@ -191,8 +186,6 @@ class ModuleDescriptor : public ZoneObject {
|
||||
|
||||
Handle<FixedArray> SerializeRegularExports(Isolate* isolate,
|
||||
Zone* zone) const;
|
||||
void DeserializeRegularExports(Isolate* isolate, AstValueFactory* avfactory,
|
||||
Handle<ModuleInfo> module_info);
|
||||
|
||||
private:
|
||||
ModuleRequestMap module_requests_;
|
||||
|
@ -125,59 +125,19 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
|
||||
}
|
||||
|
||||
ModuleScope::ModuleScope(DeclarationScope* script_scope,
|
||||
AstValueFactory* ast_value_factory)
|
||||
: DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE,
|
||||
kModule) {
|
||||
Zone* zone = ast_value_factory->zone();
|
||||
module_descriptor_ = new (zone) ModuleDescriptor(zone);
|
||||
AstValueFactory* avfactory)
|
||||
: DeclarationScope(avfactory->zone(), script_scope, MODULE_SCOPE, kModule),
|
||||
module_descriptor_(new (avfactory->zone())
|
||||
ModuleDescriptor(avfactory->zone())) {
|
||||
set_language_mode(LanguageMode::kStrict);
|
||||
DeclareThis(ast_value_factory);
|
||||
DeclareThis(avfactory);
|
||||
}
|
||||
|
||||
ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
|
||||
AstValueFactory* avfactory)
|
||||
: DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) {
|
||||
Zone* zone = avfactory->zone();
|
||||
Handle<ModuleInfo> module_info(scope_info->ModuleDescriptorInfo(), isolate);
|
||||
|
||||
: DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info),
|
||||
module_descriptor_(nullptr) {
|
||||
set_language_mode(LanguageMode::kStrict);
|
||||
module_descriptor_ = new (zone) ModuleDescriptor(zone);
|
||||
|
||||
// Deserialize special exports.
|
||||
Handle<FixedArray> special_exports(module_info->special_exports(), isolate);
|
||||
for (int i = 0, n = special_exports->length(); i < n; ++i) {
|
||||
Handle<ModuleInfoEntry> serialized_entry(
|
||||
ModuleInfoEntry::cast(special_exports->get(i)), isolate);
|
||||
module_descriptor_->AddSpecialExport(
|
||||
ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
|
||||
serialized_entry),
|
||||
avfactory->zone());
|
||||
}
|
||||
|
||||
// Deserialize regular exports.
|
||||
module_descriptor_->DeserializeRegularExports(isolate, avfactory,
|
||||
module_info);
|
||||
|
||||
// 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(namespace_imports->get(i)), isolate);
|
||||
module_descriptor_->AddNamespaceImport(
|
||||
ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
|
||||
serialized_entry),
|
||||
avfactory->zone());
|
||||
}
|
||||
|
||||
// Deserialize regular imports.
|
||||
Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate);
|
||||
for (int i = 0, n = regular_imports->length(); i < n; ++i) {
|
||||
Handle<ModuleInfoEntry> serialized_entry(
|
||||
ModuleInfoEntry::cast(regular_imports->get(i)), isolate);
|
||||
module_descriptor_->AddRegularImport(ModuleDescriptor::Entry::Deserialize(
|
||||
isolate, avfactory, serialized_entry));
|
||||
}
|
||||
}
|
||||
|
||||
Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
|
||||
|
@ -1138,27 +1138,21 @@ Scope::Snapshot::Snapshot(Scope* scope)
|
||||
|
||||
class ModuleScope final : public DeclarationScope {
|
||||
public:
|
||||
ModuleScope(DeclarationScope* script_scope,
|
||||
AstValueFactory* ast_value_factory);
|
||||
ModuleScope(DeclarationScope* script_scope, AstValueFactory* avfactory);
|
||||
|
||||
// Deserialization.
|
||||
// The generated ModuleDescriptor does not preserve all information. In
|
||||
// particular, its module_requests map will be empty because we no longer need
|
||||
// the map after parsing.
|
||||
// Deserialization. Does not restore the module descriptor.
|
||||
ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
|
||||
AstValueFactory* ast_value_factory);
|
||||
AstValueFactory* avfactory);
|
||||
|
||||
ModuleDescriptor* module() const {
|
||||
DCHECK_NOT_NULL(module_descriptor_);
|
||||
return module_descriptor_;
|
||||
}
|
||||
// Returns nullptr in a deserialized scope.
|
||||
ModuleDescriptor* module() const { return module_descriptor_; }
|
||||
|
||||
// Set MODULE as VariableLocation for all variables that will live in a
|
||||
// module's export table.
|
||||
void AllocateModuleVariables();
|
||||
|
||||
private:
|
||||
ModuleDescriptor* module_descriptor_;
|
||||
ModuleDescriptor* const module_descriptor_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
Loading…
Reference in New Issue
Block a user