[scopes] Remove dead code identified by coverage reports
Change-Id: I5b2ec3e8b0d2882465b33fedf62a6eac8f952f93 Reviewed-on: https://chromium-review.googlesource.com/c/1387965 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#58679}
This commit is contained in:
parent
d77e4a8484
commit
ca40805ae1
@ -22,14 +22,6 @@
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
namespace {
|
||||
bool IsLexical(Variable* variable) {
|
||||
if (variable == Scope::kDummyPreParserLexicalVariable) return true;
|
||||
if (variable == Scope::kDummyPreParserVariable) return false;
|
||||
return IsLexicalVariableMode(variable->mode());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Implementation of LocalsMap
|
||||
//
|
||||
@ -65,21 +57,6 @@ Variable* VariableMap::Declare(Zone* zone, Scope* scope,
|
||||
return reinterpret_cast<Variable*>(p->value);
|
||||
}
|
||||
|
||||
Variable* VariableMap::DeclareName(Zone* zone, const AstRawString* name,
|
||||
VariableMode mode) {
|
||||
Entry* p =
|
||||
ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->Hash(),
|
||||
ZoneAllocationPolicy(zone));
|
||||
if (p->value == nullptr) {
|
||||
// The variable has not been declared yet -> insert it.
|
||||
DCHECK_EQ(name, p->key);
|
||||
p->value = mode == VariableMode::kVar
|
||||
? Scope::kDummyPreParserVariable
|
||||
: Scope::kDummyPreParserLexicalVariable;
|
||||
}
|
||||
return reinterpret_cast<Variable*>(p->value);
|
||||
}
|
||||
|
||||
void VariableMap::Remove(Variable* var) {
|
||||
const AstRawString* name = var->raw_name();
|
||||
ZoneHashMap::Remove(const_cast<AstRawString*>(name), name->Hash());
|
||||
@ -564,7 +541,7 @@ void DeclarationScope::HoistSloppyBlockFunctions(AstNodeFactory* factory) {
|
||||
// `{ let e; try {} catch (e) { function e(){} } }`
|
||||
do {
|
||||
var = query_scope->LookupInScopeOrScopeInfo(name);
|
||||
if (var != nullptr && IsLexical(var)) {
|
||||
if (var != nullptr && IsLexicalVariableMode(var->mode())) {
|
||||
should_hoist = false;
|
||||
break;
|
||||
}
|
||||
@ -610,12 +587,9 @@ void DeclarationScope::HoistSloppyBlockFunctions(AstNodeFactory* factory) {
|
||||
} else {
|
||||
DCHECK(is_being_lazily_parsed_);
|
||||
Variable* var = DeclareVariableName(name, VariableMode::kVar);
|
||||
if (var != kDummyPreParserVariable &&
|
||||
var != kDummyPreParserLexicalVariable) {
|
||||
var->set_maybe_assigned();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarationScope::AttachOuterScopeInfo(ParseInfo* info, Isolate* isolate) {
|
||||
@ -717,7 +691,7 @@ void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) {
|
||||
// allocated during variable allocation.
|
||||
arguments_ = Declare(zone(), ast_value_factory->arguments_string(),
|
||||
VariableMode::kVar);
|
||||
} else if (IsLexical(arguments_)) {
|
||||
} else if (IsLexicalVariableMode(arguments_->mode())) {
|
||||
// Check if there's lexically declared variable named arguments to avoid
|
||||
// redeclaration. See ES#sec-functiondeclarationinstantiation, step 20.
|
||||
arguments_ = nullptr;
|
||||
@ -1138,8 +1112,6 @@ Variable* Scope::DeclareVariableName(const AstRawString* name,
|
||||
|
||||
// Declare the variable in the declaration scope.
|
||||
Variable* var = LookupLocal(name);
|
||||
DCHECK_NE(var, kDummyPreParserLexicalVariable);
|
||||
DCHECK_NE(var, kDummyPreParserVariable);
|
||||
if (var == nullptr) {
|
||||
var = DeclareLocal(name, mode);
|
||||
} else if (IsLexicalVariableMode(mode) ||
|
||||
@ -1238,13 +1210,6 @@ const AstRawString* Scope::FindVariableDeclaredIn(Scope* scope,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Declaration* Scope::DeclarationFor(const AstRawString* name) {
|
||||
for (Declaration* decl : decls_) {
|
||||
if (decl->proxy()->raw_name() == name) return decl;
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
bool DeclarationScope::AllocateVariables(ParseInfo* info) {
|
||||
// Module variables must be allocated before variable resolution
|
||||
// to ensure that UpdateNeedsHoleCheck() can detect import variables.
|
||||
@ -1425,8 +1390,7 @@ void Scope::AnalyzePartially(DeclarationScope* max_outer_scope,
|
||||
VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy);
|
||||
new_unresolved_list->Add(copy);
|
||||
}
|
||||
} else if (var != Scope::kDummyPreParserVariable &&
|
||||
var != Scope::kDummyPreParserLexicalVariable) {
|
||||
} else {
|
||||
var->set_is_used();
|
||||
if (proxy->is_assigned()) var->set_maybe_assigned();
|
||||
}
|
||||
@ -1617,10 +1581,6 @@ void PrintMap(int indent, const char* label, VariableMap* map, bool locals,
|
||||
for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
|
||||
Variable* var = reinterpret_cast<Variable*>(p->value);
|
||||
if (var == function_var) continue;
|
||||
if (var == Scope::kDummyPreParserVariable ||
|
||||
var == Scope::kDummyPreParserLexicalVariable) {
|
||||
continue;
|
||||
}
|
||||
bool local = !IsDynamicVariableMode(var->mode());
|
||||
if ((locals ? local : !local) &&
|
||||
(var->is_used() || !var->IsUnallocated())) {
|
||||
@ -1864,13 +1824,6 @@ namespace {
|
||||
bool CanBeShadowed(Scope* scope, Variable* var) {
|
||||
if (var == nullptr) return false;
|
||||
|
||||
// TODO(marja): Separate Lookup for preparsed scopes better.
|
||||
if (var == Scope::kDummyPreParserVariable ||
|
||||
var == Scope::kDummyPreParserLexicalVariable) {
|
||||
DCHECK(scope->GetDeclarationScope()->is_being_lazily_parsed());
|
||||
return false;
|
||||
}
|
||||
|
||||
// "this" can't be shadowed by "eval"-introduced bindings or by "with" scopes.
|
||||
// TODO(wingo): There are other variables in this category; add them.
|
||||
return !var->is_this();
|
||||
@ -2097,9 +2050,6 @@ bool Scope::ResolveVariablesRecursively(ParseInfo* info) {
|
||||
}
|
||||
|
||||
bool Scope::MustAllocate(Variable* var) {
|
||||
if (var == kDummyPreParserLexicalVariable || var == kDummyPreParserVariable) {
|
||||
return true;
|
||||
}
|
||||
DCHECK(var->location() != VariableLocation::MODULE);
|
||||
// Give var a read/write use if there is a chance it might be accessed
|
||||
// via an eval() call. This is only possible if the variable has a
|
||||
@ -2364,14 +2314,6 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info, Isolate* isolate) {
|
||||
}
|
||||
}
|
||||
|
||||
int Scope::StackLocalCount() const {
|
||||
Variable* function =
|
||||
is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
|
||||
return num_stack_slots() -
|
||||
(function != nullptr && function->IsStackLocal() ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
int Scope::ContextLocalCount() const {
|
||||
if (num_heap_slots() == 0) return 0;
|
||||
Variable* function =
|
||||
@ -2382,9 +2324,5 @@ int Scope::ContextLocalCount() const {
|
||||
(is_function_var_in_context ? 1 : 0);
|
||||
}
|
||||
|
||||
void* const Scope::kDummyPreParserVariable = reinterpret_cast<void*>(0x1);
|
||||
void* const Scope::kDummyPreParserLexicalVariable =
|
||||
reinterpret_cast<void*>(0x2);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -39,11 +39,6 @@ class VariableMap: public ZoneHashMap {
|
||||
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
|
||||
base::ThreadedList<Variable>* variable_list = nullptr);
|
||||
|
||||
// Records that "name" exists (if not recorded yet) but doesn't create a
|
||||
// Variable. Useful for preparsing.
|
||||
Variable* DeclareName(Zone* zone, const AstRawString* name,
|
||||
VariableMode mode);
|
||||
|
||||
Variable* Lookup(const AstRawString* name);
|
||||
void Remove(Variable* var);
|
||||
void Add(Zone* zone, Variable* var);
|
||||
@ -297,9 +292,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
|
||||
const AstRawString* FindVariableDeclaredIn(Scope* scope,
|
||||
VariableMode mode_limit);
|
||||
|
||||
// Find the declaration that introduced |name|.
|
||||
Declaration* DeclarationFor(const AstRawString* name);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scope-specific info.
|
||||
|
||||
@ -460,7 +452,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
|
||||
int num_stack_slots() const { return num_stack_slots_; }
|
||||
int num_heap_slots() const { return num_heap_slots_; }
|
||||
|
||||
int StackLocalCount() const;
|
||||
int ContextLocalCount() const;
|
||||
|
||||
// Determine if we can parse a function literal in this scope lazily without
|
||||
@ -549,9 +540,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void* const kDummyPreParserVariable;
|
||||
static void* const kDummyPreParserLexicalVariable;
|
||||
|
||||
protected:
|
||||
explicit Scope(Zone* zone);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user