From 3c702243d2b7a33b953037d9fbed26e2dad0a398 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Fri, 12 Mar 2021 20:20:08 +0100 Subject: [PATCH] [no-wasm][parsing] Remove asm detection asm validation and translation to wasm is disabled in no-wasm builds, hence remove respective detection and marking of scopes and functions. R=verwaest@chromium.org Bug: v8:11238 Change-Id: I2ac8a84024fa37a0c5896a0f85ea4beea4d93137 Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2757689 Reviewed-by: Toon Verwaest Commit-Queue: Clemens Backes Cr-Commit-Position: refs/heads/master@{#73410} --- src/ast/scopes.cc | 13 ++++++++++++- src/ast/scopes.h | 8 ++++++++ src/objects/scope-info.cc | 2 ++ src/parsing/parse-info.cc | 2 ++ src/parsing/parse-info.h | 6 ++++++ src/parsing/parser-base.h | 6 ++++++ src/parsing/parser.cc | 4 ++++ src/parsing/parser.h | 2 ++ test/cctest/test-parsing.cc | 4 ++-- 9 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index 4e396c457f..de9b25a5c5 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -296,7 +296,9 @@ Scope::Scope(Zone* zone, const AstRawString* catch_variable_name, void DeclarationScope::SetDefaults() { is_declaration_scope_ = true; has_simple_parameters_ = true; +#if V8_ENABLE_WEBASSEMBLY is_asm_module_ = false; +#endif // V8_ENABLE_WEBASSEMBLY force_eager_compilation_ = false; has_arguments_parameter_ = false; uses_super_property_ = false; @@ -373,6 +375,7 @@ void DeclarationScope::set_should_eager_compile() { should_eager_compile_ = !was_lazily_parsed_; } +#if V8_ENABLE_WEBASSEMBLY void DeclarationScope::set_is_asm_module() { is_asm_module_ = true; } bool Scope::IsAsmModule() const { @@ -393,6 +396,7 @@ bool Scope::ContainsAsmModule() const { return false; } +#endif // V8_ENABLE_WEBASSEMBLY Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, ScopeInfo scope_info, @@ -430,9 +434,11 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, } else if (scope_info.scope_type() == FUNCTION_SCOPE) { outer_scope = zone->New( zone, FUNCTION_SCOPE, ast_value_factory, handle(scope_info, isolate)); +#if V8_ENABLE_WEBASSEMBLY if (scope_info.IsAsmModule()) { outer_scope->AsDeclarationScope()->set_is_asm_module(); } +#endif // V8_ENABLE_WEBASSEMBLY } else if (scope_info.scope_type() == EVAL_SCOPE) { outer_scope = zone->New( zone, EVAL_SCOPE, ast_value_factory, handle(scope_info, isolate)); @@ -1850,7 +1856,9 @@ void Scope::Print(int n) { if (is_strict(language_mode())) { Indent(n1, "// strict mode scope\n"); } +#if V8_ENABLE_WEBASSEMBLY if (IsAsmModule()) Indent(n1, "// scope is an asm module\n"); +#endif // V8_ENABLE_WEBASSEMBLY if (is_declaration_scope() && AsDeclarationScope()->sloppy_eval_can_extend_vars()) { Indent(n1, "// scope calls sloppy 'eval'\n"); @@ -2501,7 +2509,10 @@ void Scope::AllocateVariablesRecursively() { // scope. bool must_have_context = scope->is_with_scope() || scope->is_module_scope() || - scope->IsAsmModule() || scope->ForceContextForLanguageMode() || +#if V8_ENABLE_WEBASSEMBLY + scope->IsAsmModule() || +#endif // V8_ENABLE_WEBASSEMBLY + scope->ForceContextForLanguageMode() || (scope->is_function_scope() && scope->AsDeclarationScope()->sloppy_eval_can_extend_vars()) || (scope->is_block_scope() && scope->is_declaration_scope() && diff --git a/src/ast/scopes.h b/src/ast/scopes.h index eb97c95b32..717c797383 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -389,10 +389,14 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { bool private_name_lookup_skips_outer_class() const { return private_name_lookup_skips_outer_class_; } + +#if V8_ENABLE_WEBASSEMBLY bool IsAsmModule() const; // Returns true if this scope or any inner scopes that might be eagerly // compiled are asm modules. bool ContainsAsmModule() const; +#endif // V8_ENABLE_WEBASSEMBLY + // Does this scope have the potential to execute declarations non-linearly? bool is_nonlinear() const { return scope_nonlinear_; } // Returns if we need to force a context because the current scope is stricter @@ -972,8 +976,10 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { scope_info_ = scope_info; } +#if V8_ENABLE_WEBASSEMBLY bool is_asm_module() const { return is_asm_module_; } void set_is_asm_module(); +#endif // V8_ENABLE_WEBASSEMBLY bool should_ban_arguments() const { return IsClassMembersInitializerFunction(function_kind()); @@ -1242,8 +1248,10 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope { void RecalcPrivateNameContextChain(); bool has_simple_parameters_ : 1; +#if V8_ENABLE_WEBASSEMBLY // This scope contains an "use asm" annotation. bool is_asm_module_ : 1; +#endif // V8_ENABLE_WEBASSEMBLY bool force_eager_compilation_ : 1; // This function scope has a rest parameter. bool has_rest_ : 1; diff --git a/src/objects/scope-info.cc b/src/objects/scope-info.cc index 4325b0f8e6..9e37b0ef11 100644 --- a/src/objects/scope-info.cc +++ b/src/objects/scope-info.cc @@ -190,7 +190,9 @@ Handle ScopeInfo::Create(LocalIsolate* isolate, Zone* zone, if (scope->is_function_scope()) { DeclarationScope* function_scope = scope->AsDeclarationScope(); has_simple_parameters = function_scope->has_simple_parameters(); +#if V8_ENABLE_WEBASSEMBLY is_asm_module = function_scope->is_asm_module(); +#endif // V8_ENABLE_WEBASSEMBLY } FunctionKind function_kind = kNormalFunction; if (scope->is_declaration_scope()) { diff --git a/src/parsing/parse-info.cc b/src/parsing/parse-info.cc index 4632f22b8a..69d18ef2b2 100644 --- a/src/parsing/parse-info.cc +++ b/src/parsing/parse-info.cc @@ -195,7 +195,9 @@ ParseInfo::ParseInfo(const UnoptimizedCompileFlags flags, source_range_map_(nullptr), literal_(nullptr), allow_eval_cache_(false), +#if V8_ENABLE_WEBASSEMBLY contains_asm_module_(false), +#endif // V8_ENABLE_WEBASSEMBLY language_mode_(flags.outer_language_mode()) { if (flags.block_coverage_enabled()) { AllocateSourceRangeMap(); diff --git a/src/parsing/parse-info.h b/src/parsing/parse-info.h index 35665490fc..2068847efb 100644 --- a/src/parsing/parse-info.h +++ b/src/parsing/parse-info.h @@ -254,8 +254,12 @@ class V8_EXPORT_PRIVATE ParseInfo { // Accessor methods for output flags. bool allow_eval_cache() const { return allow_eval_cache_; } void set_allow_eval_cache(bool value) { allow_eval_cache_ = value; } + +#if V8_ENABLE_WEBASSEMBLY bool contains_asm_module() const { return contains_asm_module_; } void set_contains_asm_module(bool value) { contains_asm_module_ = value; } +#endif // V8_ENABLE_WEBASSEMBLY + LanguageMode language_mode() const { return language_mode_; } void set_language_mode(LanguageMode value) { language_mode_ = value; } @@ -347,7 +351,9 @@ class V8_EXPORT_PRIVATE ParseInfo { //----------- Output of parsing and scope analysis ------------------------ FunctionLiteral* literal_; bool allow_eval_cache_ : 1; +#if V8_ENABLE_WEBASSEMBLY bool contains_asm_module_ : 1; +#endif // V8_ENABLE_WEBASSEMBLY LanguageMode language_mode_ : 1; }; diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 0ff9a9617e..f83ff8636c 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -5036,14 +5036,18 @@ void ParserBase::ParseStatementList(StatementListT* body, while (peek() == Token::STRING) { bool use_strict = false; +#if V8_ENABLE_WEBASSEMBLY bool use_asm = false; +#endif // V8_ENABLE_WEBASSEMBLY Scanner::Location token_loc = scanner()->peek_location(); if (scanner()->NextLiteralExactlyEquals("use strict")) { use_strict = true; +#if V8_ENABLE_WEBASSEMBLY } else if (scanner()->NextLiteralExactlyEquals("use asm")) { use_asm = true; +#endif // V8_ENABLE_WEBASSEMBLY } StatementT stat = ParseStatementListItem(); @@ -5065,9 +5069,11 @@ void ParserBase::ParseStatementList(StatementListT* body, "use strict"); return; } +#if V8_ENABLE_WEBASSEMBLY } else if (use_asm) { // Directive "use asm". impl()->SetAsmModule(); +#endif // V8_ENABLE_WEBASSEMBLY } else { // Possibly an unknown directive. // Should not change mode, but will increment usage counters diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 9366d195f3..a2d0b244d9 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -489,12 +489,14 @@ void Parser::DeserializeScopeChain( namespace { void MaybeResetCharacterStream(ParseInfo* info, FunctionLiteral* literal) { +#if V8_ENABLE_WEBASSEMBLY // Don't reset the character stream if there is an asm.js module since it will // be used again by the asm-parser. if (info->contains_asm_module()) { if (FLAG_stress_validate_asm) return; if (literal != nullptr && literal->scope()->ContainsAsmModule()) return; } +#endif // V8_ENABLE_WEBASSEMBLY info->ResetCharacterStream(); } @@ -3435,6 +3437,7 @@ void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) { scope->SetLanguageMode(mode); } +#if V8_ENABLE_WEBASSEMBLY void Parser::SetAsmModule() { // Store the usage count; The actual use counter on the isolate is // incremented after parsing is done. @@ -3443,6 +3446,7 @@ void Parser::SetAsmModule() { scope()->AsDeclarationScope()->set_is_asm_module(); info_->set_contains_asm_module(true); } +#endif // V8_ENABLE_WEBASSEMBLY Expression* Parser::ExpressionListToExpression( const ScopedPtrList& args) { diff --git a/src/parsing/parser.h b/src/parsing/parser.h index db7d5aed0e..7510fd8dac 100644 --- a/src/parsing/parser.h +++ b/src/parsing/parser.h @@ -502,7 +502,9 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase) { Expression* RewriteSuperCall(Expression* call_expression); void SetLanguageMode(Scope* scope, LanguageMode mode); +#if V8_ENABLE_WEBASSEMBLY void SetAsmModule(); +#endif // V8_ENABLE_WEBASSEMBLY Expression* RewriteSpreads(ArrayLiteral* lit); diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index 49ce61fb07..1c55995efa 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -4323,6 +4323,7 @@ TEST(MaybeAssignedTopLevel) { } } +#if V8_ENABLE_WEBASSEMBLY namespace { i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, @@ -4365,7 +4366,6 @@ TEST(AsmModuleFlag) { CHECK(s->IsAsmModule() && s->AsDeclarationScope()->is_asm_module()); } - TEST(UseAsmUseCount) { i::Isolate* isolate = CcTest::i_isolate(); i::HandleScope scope(isolate); @@ -4378,7 +4378,7 @@ TEST(UseAsmUseCount) { "function bar() { \"use asm\"; var baz = 1; }"); CHECK_LT(0, use_counts[v8::Isolate::kUseAsm]); } - +#endif // V8_ENABLE_WEBASSEMBLY TEST(StrictModeUseCount) { i::Isolate* isolate = CcTest::i_isolate();