From 274075fb85e5b08eeb7f4a8656656f7322f05957 Mon Sep 17 00:00:00 2001 From: Georg Neis Date: Tue, 19 Feb 2019 11:04:42 +0100 Subject: [PATCH] [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 Commit-Queue: Georg Neis Cr-Commit-Position: refs/heads/master@{#59718} --- src/ast/modules.cc | 47 ---------------------------------------- src/ast/modules.h | 7 ------ src/ast/scopes.cc | 54 ++++++---------------------------------------- src/ast/scopes.h | 18 ++++++---------- 4 files changed, 13 insertions(+), 113 deletions(-) diff --git a/src/ast/modules.cc b/src/ast/modules.cc index 0f66ac91ec..d1be965a4a 100644 --- a/src/ast/modules.cc +++ b/src/ast/modules.cc @@ -91,20 +91,11 @@ void ModuleDescriptor::AddStarExport(const AstRawString* module_request, } namespace { - Handle ToStringOrUndefined(Isolate* isolate, const AstRawString* s) { return (s == nullptr) ? Handle::cast(isolate->factory()->undefined_value()) : Handle::cast(s->string()); } - -const AstRawString* FromStringOrUndefined(Isolate* isolate, - AstValueFactory* avfactory, - Handle object) { - if (object->IsUndefined(isolate)) return nullptr; - return avfactory->GetString(Handle::cast(object)); -} - } // namespace Handle ModuleDescriptor::Entry::Serialize( @@ -117,21 +108,6 @@ Handle ModuleDescriptor::Entry::Serialize( location.beg_pos, location.end_pos); } -ModuleDescriptor::Entry* ModuleDescriptor::Entry::Deserialize( - Isolate* isolate, AstValueFactory* avfactory, - Handle 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 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 ModuleDescriptor::SerializeRegularExports(Isolate* isolate, return result; } -void ModuleDescriptor::DeserializeRegularExports( - Isolate* isolate, AstValueFactory* avfactory, - Handle module_info) { - for (int i = 0, count = module_info->RegularExportCount(); i < count; ++i) { - Handle local_name(module_info->RegularExportLocalName(i), isolate); - int cell_index = module_info->RegularExportCellIndex(i); - Handle export_names(module_info->RegularExportExportNames(i), - isolate); - - for (int j = 0, length = export_names->length(); j < length; ++j) { - Handle 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; diff --git a/src/ast/modules.h b/src/ast/modules.h index 44e86dce42..ebc3e3a288 100644 --- a/src/ast/modules.h +++ b/src/ast/modules.h @@ -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 Serialize(Isolate* isolate) const; - static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory, - Handle entry); }; enum CellIndexKind { kInvalid, kExport, kImport }; @@ -191,8 +186,6 @@ class ModuleDescriptor : public ZoneObject { Handle SerializeRegularExports(Isolate* isolate, Zone* zone) const; - void DeserializeRegularExports(Isolate* isolate, AstValueFactory* avfactory, - Handle module_info); private: ModuleRequestMap module_requests_; diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index e10d55e857..e625865a11 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -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 scope_info, AstValueFactory* avfactory) - : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) { - Zone* zone = avfactory->zone(); - Handle 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 special_exports(module_info->special_exports(), isolate); - for (int i = 0, n = special_exports->length(); i < n; ++i) { - Handle 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 namespace_imports(module_info->namespace_imports(), - isolate); - for (int i = 0, n = namespace_imports->length(); i < n; ++i) { - Handle 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 regular_imports(module_info->regular_imports(), isolate); - for (int i = 0, n = regular_imports->length(); i < n; ++i) { - Handle 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 scope_info) diff --git a/src/ast/scopes.h b/src/ast/scopes.h index fb7df06ec7..849ec52073 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -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 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