Reviewers: rossberg,

Description:
Add function literal variable to declaration list.

This adds the implicit function variable for a function literal to the
declarations list in scope analysis, instead of specially handling it
throughout all back-ends.

[email protected]

Please review this at https://codereview.chromium.org/1245603003/

Base URL: https://chromium.googlesource.com/v8/v8.git@local_turbofan-super-6

Affected files (+3, -89 lines):
  M src/arm/full-codegen-arm.cc
  M src/arm64/full-codegen-arm64.cc
  M src/ast-numbering.cc
  M src/compiler/ast-graph-builder.cc
  M src/hydrogen.cc
  M src/ia32/full-codegen-ia32.cc
  M src/mips/full-codegen-mips.cc
  M src/mips64/full-codegen-mips64.cc
  M src/ppc/full-codegen-ppc.cc
  M src/scopes.h
  M src/typing.cc
  M src/x64/full-codegen-x64.cc
  M src/x87/full-codegen-x87.cc


Index: src/arm/full-codegen-arm.cc
diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc
index 32845ddb89d761dea699b6d0af499b8f1c9d28aa..d1a4faf326076908eb9a4ebe5483da701c6cea91 100644
--- a/src/arm/full-codegen-arm.cc
+++ b/src/arm/full-codegen-arm.cc
@@ -345,15 +345,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/arm64/full-codegen-arm64.cc
diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index 4b34f0309d754f453e154f53cb6dbe0d0f6160ac..388e06aec3694e0eab6510c30f4a8d9a921e7c98 100644
--- a/src/arm64/full-codegen-arm64.cc
+++ b/src/arm64/full-codegen-arm64.cc
@@ -350,13 +350,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/ast-numbering.cc
diff --git a/src/ast-numbering.cc b/src/ast-numbering.cc
index bf0f9ba2a46f4788b43b3a1af5e48dbe7b781e52..e14b84dfe8fc26dbc27ca768e59099a7f9f432a8 100644
--- a/src/ast-numbering.cc
+++ b/src/ast-numbering.cc
@@ -538,10 +538,6 @@ bool AstNumberingVisitor::Renumber(FunctionLiteral* node) {
   }

   VisitDeclarations(scope->declarations());
-  if (scope->is_function_scope() && scope->function() != NULL) {
-    // Visit the name of the named function expression.
-    Visit(scope->function());
-  }
   VisitStatements(node->body());

   return Finish(node);
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index 6f9371a061f6ffac5812926b5fb0ba71dc37f436..d6e1ceba30c4dc733404a6a102f425612cae2ae7 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -584,11 +584,6 @@ void AstGraphBuilder::CreateGraphBody(bool stack_check) {
     return;
   }

-  // Visit implicit declaration of the function name.
-  if (scope->is_function_scope() && scope->function() != NULL) {
-    VisitVariableDeclaration(scope->function());
-  }
-
   // Visit declarations within the function scope.
   VisitDeclarations(scope->declarations());

Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 56980266af249194862def6a90b425c7364003b7..94f0d578b73d2698118bcf158a7c8f6d2e24001f 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -4357,11 +4357,6 @@ bool HOptimizedGraphBuilder::BuildGraph() {
   body_entry->SetJoinId(BailoutId::FunctionEntry());
   set_current_block(body_entry);

-  // Handle implicit declaration of the function name in named function
-  // expressions before other declarations.
-  if (scope->is_function_scope() && scope->function() != NULL) {
-    VisitVariableDeclaration(scope->function());
-  }
   VisitDeclarations(scope->declarations());
   Add<HSimulate>(BailoutId::Declarations());

Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index 6060b3616efe778e4742678675f3669894911d10..762726711b55cdb6e29d1db718ad20e537a2b18a 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -347,15 +347,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/mips/full-codegen-mips.cc
diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc
index 7258c746bfb8ad3d51452e9b6db6d353b1aeea75..beaff831a6c27721b074ede9348824c06d12f3a0 100644
--- a/src/mips/full-codegen-mips.cc
+++ b/src/mips/full-codegen-mips.cc
@@ -363,15 +363,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/mips64/full-codegen-mips64.cc
diff --git a/src/mips64/full-codegen-mips64.cc b/src/mips64/full-codegen-mips64.cc index 95fc92669bfdcfaab40a52fb01512307319b45fc..94a67b51854b42bfce2a5d210311c9f07389fedc 100644
--- a/src/mips64/full-codegen-mips64.cc
+++ b/src/mips64/full-codegen-mips64.cc
@@ -358,15 +358,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }
     { Comment cmnt(masm_, "[ Stack check");
Index: src/ppc/full-codegen-ppc.cc
diff --git a/src/ppc/full-codegen-ppc.cc b/src/ppc/full-codegen-ppc.cc
index 5de6823d3f0eb290260b77666350e0931c5daf9e..44fe92af7764eca77836eaf10cb87936e3c0a16e 100644
--- a/src/ppc/full-codegen-ppc.cc
+++ b/src/ppc/full-codegen-ppc.cc
@@ -357,15 +357,6 @@ void FullCodeGenerator::Generate() {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     {
       Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/scopes.h
diff --git a/src/scopes.h b/src/scopes.h
index 9f913450abd9f7f8622ef1b85082bd4c3e43a15b..f9354188bf31e99858e2da0c0696eb5cd049c9da 100644
--- a/src/scopes.h
+++ b/src/scopes.h
@@ -119,6 +119,9 @@ class Scope: public ZoneObject {
   // outer scope. Only possible for function scopes; at most one variable.
   void DeclareFunctionVar(VariableDeclaration* declaration) {
     DCHECK(is_function_scope());
+    // Handle implicit declaration of the function name in named function
+    // expressions before other declarations.
+    decls_.InsertAt(0, declaration, zone());
     function_ = declaration;
   }

Index: src/typing.cc
diff --git a/src/typing.cc b/src/typing.cc
index 2f10328f0978d70363e4809cc343613a02da5b57..3e811ca49c649035659c364ed7bb58b57ce00bed 100644
--- a/src/typing.cc
+++ b/src/typing.cc
@@ -36,11 +36,6 @@ void AstTyper::Run(CompilationInfo* info) {
   AstTyper* visitor = new(info->zone()) AstTyper(info);
   Scope* scope = info->scope();

-  // Handle implicit declaration of the function name in named function
-  // expressions before other declarations.
-  if (scope->is_function_scope() && scope->function() != NULL) {
-    RECURSE(visitor->VisitVariableDeclaration(scope->function()));
-  }
   RECURSE(visitor->VisitDeclarations(scope->declarations()));
   RECURSE(visitor->VisitStatements(info->function()->body()));
 }
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index d6c3428998679d0cab8c23fc9f0b8af358457dbb..36a7eed1f98a92044d7a79795b4e7b2ba12fc4ea 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -345,15 +345,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }

Index: src/x87/full-codegen-x87.cc
diff --git a/src/x87/full-codegen-x87.cc b/src/x87/full-codegen-x87.cc
index ab7bcd6cde1a0c44c43dff68fa358d52495591f8..1e6a88c97ec185b202ce1064b83681e797ae6251 100644
--- a/src/x87/full-codegen-x87.cc
+++ b/src/x87/full-codegen-x87.cc
@@ -344,15 +344,6 @@ void FullCodeGenerator::Generate() {
   } else {
     PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
     { Comment cmnt(masm_, "[ Declarations");
-      // For named function expressions, declare the function name as a
-      // constant.
-      if (scope()->is_function_scope() && scope()->function() != NULL) {
-        VariableDeclaration* function = scope()->function();
-        DCHECK(function->proxy()->var()->mode() == CONST ||
-               function->proxy()->var()->mode() == CONST_LEGACY);
-        DCHECK(!function->proxy()->var()->IsUnallocatedOrGlobalSlot());
-        VisitVariableDeclaration(function);
-      }
       VisitDeclarations(scope()->declarations());
     }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to