Reviewers: Michael Starzinger,

Description:
[turbofan] Make ContextScope a proper encapsulation of the current context.

[email protected]
BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+22, -23 lines):
  M src/compiler/ast-graph-builder.h
  M src/compiler/ast-graph-builder.cc


Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index 87b0b2ddab3337879e2772be12a6605872b76168..c72542a3e5d3bf0fb9eded388edeb5ca42ea07cb 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -105,28 +105,28 @@ class AstGraphBuilder::AstTestContext FINAL : public AstContext {
 // change the current {scope} and {context} during visitation.
 class AstGraphBuilder::ContextScope BASE_EMBEDDED {
  public:
-  ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context)
-      : owner_(owner),
-        next_(owner->execution_context()),
-        outer_(owner->current_context()),
-        scope_(scope) {
-    owner_->set_execution_context(this);  // Push.
-    owner_->set_current_context(context);
+  ContextScope(AstGraphBuilder* builder, Scope* scope, Node* context)
+      : builder_(builder),
+        outer_(builder->execution_context()),
+        scope_(scope),
+        context_(context) {
+    builder_->set_execution_context(this);  // Push.
   }

   ~ContextScope() {
-    owner_->set_execution_context(next_);  // Pop.
-    owner_->set_current_context(outer_);
+    builder_->set_execution_context(outer_);  // Pop.
   }

   // Current scope during visitation.
   Scope* scope() const { return scope_; }
+  // Current context node during visitation.
+  Node* context() const { return context_; }

  private:
-  AstGraphBuilder* owner_;
-  ContextScope* next_;
-  Node* outer_;
+  AstGraphBuilder* builder_;
+  ContextScope* outer_;
   Scope* scope_;
+  Node* context_;
 };


@@ -380,7 +380,6 @@ AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
       execution_context_(nullptr),
       input_buffer_size_(0),
       input_buffer_(nullptr),
-      current_context_(nullptr),
       exit_control_(nullptr),
       loop_assignment_analysis_(loop) {
   InitializeAstVisitor(info->isolate(), local_zone);
@@ -431,8 +430,8 @@ bool AstGraphBuilder::CreateGraph() {
   }

   // Initialize the incoming context.
-  Node* outer_context = GetFunctionContext();
-  set_current_context(outer_context);
+  Node* incoming_context = GetFunctionContext();
+  ContextScope incoming(this, scope, incoming_context);

   // Build receiver check for sloppy mode if necessary.
   // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC?
@@ -442,9 +441,9 @@ bool AstGraphBuilder::CreateGraph() {

   // Build node to initialize local function context.
   Node* closure = GetFunctionClosure();
-  Node* inner_context = BuildLocalFunctionContext(outer_context, closure);
+ Node* inner_context = BuildLocalFunctionContext(incoming_context, closure);

-  // Push top-level function scope for the function body.
+  // Push top-level function context for the function body.
   ContextScope top_context(this, scope, inner_context);

   // Build the arguments object if it is used.
@@ -655,6 +654,11 @@ Scope* AstGraphBuilder::current_scope() const {
 }


+Node* AstGraphBuilder::current_context() const {
+  return execution_context_->context();
+}
+
+
 void AstGraphBuilder::ControlScope::PerformCommand(Command command,
                                                    Statement* target,
                                                    Node* value) {
@@ -2408,7 +2412,6 @@ Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context, Node* closure) {
   // Allocate a new local context.
   const Operator* op = javascript()->CreateFunctionContext();
   Node* local_context = NewNode(op, closure);
-  set_current_context(local_context);

   // Copy parameters into context if necessary.
   int num_parameters = info()->scope()->num_parameters();
Index: src/compiler/ast-graph-builder.h
diff --git a/src/compiler/ast-graph-builder.h b/src/compiler/ast-graph-builder.h index 4845a66794e65bdd175f45e322f90c64204b9615..a6cd5f6c75fda5237fe82d68c82d0def94ac964c 100644
--- a/src/compiler/ast-graph-builder.h
+++ b/src/compiler/ast-graph-builder.h
@@ -98,9 +98,6 @@ class AstGraphBuilder : public AstVisitor {
   // Node representing the control dependency for dead code.
   SetOncePointer<Node> dead_control_;

-  // Node representing the current context within the function body.
-  Node* current_context_;
-
   // Merge of all control nodes that exit the function body.
   Node* exit_control_;

@@ -125,7 +122,7 @@ class AstGraphBuilder : public AstVisitor {
   JSOperatorBuilder* javascript() { return jsgraph_->javascript(); }
   ZoneVector<Handle<Object>>* globals() { return &globals_; }
   Scope* current_scope() const;
-  Node* current_context() const { return current_context_; }
+  Node* current_context() const;
   Node* dead_control();
   Node* exit_control() const { return exit_control_; }

@@ -133,7 +130,6 @@ class AstGraphBuilder : public AstVisitor {
   void set_ast_context(AstContext* ctx) { ast_context_ = ctx; }
void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; } void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; }
-  void set_current_context(Node* ctx) { current_context_ = ctx; }
   void set_exit_control(Node* exit) { exit_control_ = exit; }

   // Node creation helpers.


--
--
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