From bdf8dc42577e25df9cdca0d3db4bc80532ddcbba Mon Sep 17 00:00:00 2001 From: adamk Date: Tue, 10 May 2016 11:57:46 -0700 Subject: [PATCH] [cleanup] Global variable declarations are never hole initialized Globals used to be hole-initialized in the case of toplevel legacy const declarations. But now that the only use of legacy const is for sloppy function expression names, we can unconditionally initialize globals to undefined instead of the_hole. Review-Url: https://codereview.chromium.org/1964993002 Cr-Commit-Position: refs/heads/master@{#36151} --- src/compiler/ast-graph-builder.cc | 9 +++------ src/crankshaft/hydrogen.cc | 5 ++--- src/full-codegen/arm/full-codegen-arm.cc | 6 ++---- src/full-codegen/arm64/full-codegen-arm64.cc | 6 ++---- src/full-codegen/ia32/full-codegen-ia32.cc | 5 ++--- src/full-codegen/mips/full-codegen-mips.cc | 6 ++---- src/full-codegen/mips64/full-codegen-mips64.cc | 6 ++---- src/full-codegen/ppc/full-codegen-ppc.cc | 6 ++---- src/full-codegen/s390/full-codegen-s390.cc | 6 ++---- src/full-codegen/x64/full-codegen-x64.cc | 6 ++---- src/full-codegen/x87/full-codegen-x87.cc | 5 ++--- src/interpreter/bytecode-generator.cc | 9 +++------ 12 files changed, 26 insertions(+), 49 deletions(-) diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index c89be45623..bbb30a497a 100644 --- a/src/compiler/ast-graph-builder.cc +++ b/src/compiler/ast-graph-builder.cc @@ -1092,14 +1092,11 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { bool hole_init = mode == CONST || mode == LET; switch (variable->location()) { case VariableLocation::GLOBAL: - case VariableLocation::UNALLOCATED: { - Handle value = variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(); + case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals()->push_back(variable->name()); - globals()->push_back(value); + globals()->push_back(isolate()->factory()->undefined_value()); break; - } case VariableLocation::PARAMETER: case VariableLocation::LOCAL: if (hole_init) { diff --git a/src/crankshaft/hydrogen.cc b/src/crankshaft/hydrogen.cc index 4c7721af37..67b7540475 100644 --- a/src/crankshaft/hydrogen.cc +++ b/src/crankshaft/hydrogen.cc @@ -12296,10 +12296,9 @@ void HOptimizedGraphBuilder::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_.Add(variable->name(), zone()); - globals_.Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), zone()); + globals_.Add(isolate()->factory()->undefined_value(), zone()); return; case VariableLocation::PARAMETER: case VariableLocation::LOCAL: diff --git a/src/full-codegen/arm/full-codegen-arm.cc b/src/full-codegen/arm/full-codegen-arm.cc index 07eab401a2..a485f16781 100644 --- a/src/full-codegen/arm/full-codegen-arm.cc +++ b/src/full-codegen/arm/full-codegen-arm.cc @@ -768,11 +768,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/arm64/full-codegen-arm64.cc b/src/full-codegen/arm64/full-codegen-arm64.cc index 5111c87146..aafcd674ca 100644 --- a/src/full-codegen/arm64/full-codegen-arm64.cc +++ b/src/full-codegen/arm64/full-codegen-arm64.cc @@ -765,11 +765,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/ia32/full-codegen-ia32.cc b/src/full-codegen/ia32/full-codegen-ia32.cc index 340bdd5be8..b408a4850c 100644 --- a/src/full-codegen/ia32/full-codegen-ia32.cc +++ b/src/full-codegen/ia32/full-codegen-ia32.cc @@ -715,10 +715,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/mips/full-codegen-mips.cc b/src/full-codegen/mips/full-codegen-mips.cc index 648566ccf8..66229237dd 100644 --- a/src/full-codegen/mips/full-codegen-mips.cc +++ b/src/full-codegen/mips/full-codegen-mips.cc @@ -765,11 +765,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/mips64/full-codegen-mips64.cc b/src/full-codegen/mips64/full-codegen-mips64.cc index 124557544e..8e69ca5317 100644 --- a/src/full-codegen/mips64/full-codegen-mips64.cc +++ b/src/full-codegen/mips64/full-codegen-mips64.cc @@ -764,11 +764,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/ppc/full-codegen-ppc.cc b/src/full-codegen/ppc/full-codegen-ppc.cc index 7a2a0c5c64..3117d28772 100644 --- a/src/full-codegen/ppc/full-codegen-ppc.cc +++ b/src/full-codegen/ppc/full-codegen-ppc.cc @@ -730,11 +730,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/s390/full-codegen-s390.cc b/src/full-codegen/s390/full-codegen-s390.cc index 776f8d9ddc..5341b4dfe8 100644 --- a/src/full-codegen/s390/full-codegen-s390.cc +++ b/src/full-codegen/s390/full-codegen-s390.cc @@ -708,11 +708,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/x64/full-codegen-x64.cc b/src/full-codegen/x64/full-codegen-x64.cc index bdfda31b0d..74dbdf08ae 100644 --- a/src/full-codegen/x64/full-codegen-x64.cc +++ b/src/full-codegen/x64/full-codegen-x64.cc @@ -727,11 +727,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), - zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/full-codegen/x87/full-codegen-x87.cc b/src/full-codegen/x87/full-codegen-x87.cc index 8da0e909ea..ee05f1393a 100644 --- a/src/full-codegen/x87/full-codegen-x87.cc +++ b/src/full-codegen/x87/full-codegen-x87.cc @@ -712,10 +712,9 @@ void FullCodeGenerator::VisitVariableDeclaration( switch (variable->location()) { case VariableLocation::GLOBAL: case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals_->Add(variable->name(), zone()); - globals_->Add(variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; case VariableLocation::PARAMETER: diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc index 10e3f90317..f1558ea17a 100644 --- a/src/interpreter/bytecode-generator.cc +++ b/src/interpreter/bytecode-generator.cc @@ -747,14 +747,11 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { bool hole_init = mode == CONST || mode == LET; switch (variable->location()) { case VariableLocation::GLOBAL: - case VariableLocation::UNALLOCATED: { - Handle value = variable->binding_needs_init() - ? isolate()->factory()->the_hole_value() - : isolate()->factory()->undefined_value(); + case VariableLocation::UNALLOCATED: + DCHECK(!variable->binding_needs_init()); globals()->push_back(variable->name()); - globals()->push_back(value); + globals()->push_back(isolate()->factory()->undefined_value()); break; - } case VariableLocation::LOCAL: if (hole_init) { Register destination(variable->index());