Eliminate use of CompilationInfo in several AstVisitor descendants.
authorbradnelson <bradnelson@google.com>
Tue, 1 Sep 2015 23:06:29 +0000 (16:06 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 1 Sep 2015 23:06:37 +0000 (23:06 +0000)
We're moving away from using CompilationInfo as a big bag o' stuff.
Passing in just what we need to several AstVisitors to avoid
increasing the problem.

BUG=None
TEST=trybots
R=titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1318823010

Cr-Commit-Position: refs/heads/master@{#30529}

13 files changed:
src/ast-expression-visitor.cc
src/ast-expression-visitor.h
src/compiler.cc
src/hydrogen.cc
src/typing-reset.cc
src/typing-reset.h
src/typing.cc
src/typing.h
test/cctest/expression-type-collector.cc
test/cctest/expression-type-collector.h
test/cctest/test-asm-validator.cc
test/cctest/test-ast-expression-visitor.cc
test/cctest/test-typing-reset.cc

index 5a0912576155dd64cdde5556574a8281a1889a7a..014f56de5335f5d4040cc3546efe66db50495565 100644 (file)
@@ -32,15 +32,14 @@ namespace internal {
   } while (false)
 
 
-AstExpressionVisitor::AstExpressionVisitor(CompilationInfo* info)
-    : compilation_info_(info), depth_(0) {
-  InitializeAstVisitor(info->isolate(), info->zone());
+AstExpressionVisitor::AstExpressionVisitor(Isolate* isolate, Zone* zone,
+                                           FunctionLiteral* root)
+    : root_(root), depth_(0) {
+  InitializeAstVisitor(isolate, zone);
 }
 
 
-void AstExpressionVisitor::Run() {
-  RECURSE(VisitFunctionLiteral(compilation_info_->literal()));
-}
+void AstExpressionVisitor::Run() { RECURSE(VisitFunctionLiteral(root_)); }
 
 
 void AstExpressionVisitor::VisitVariableDeclaration(VariableDeclaration* decl) {
index 37960e03683ef1bbdca64269e970bb00d3e753ce..43b34bac7968f9b6477e788764a7a76f7d336edd 100644 (file)
@@ -21,7 +21,7 @@ namespace internal {
 
 class AstExpressionVisitor : public AstVisitor {
  public:
-  explicit AstExpressionVisitor(CompilationInfo* info);
+  AstExpressionVisitor(Isolate* isolate, Zone* zone, FunctionLiteral* root);
   void Run();
 
  protected:
@@ -38,7 +38,7 @@ class AstExpressionVisitor : public AstVisitor {
   AST_NODE_LIST(DECLARE_VISIT)
 #undef DECLARE_VISIT
 
-  CompilationInfo* compilation_info_;
+  FunctionLiteral* root_;
   int depth_;
 
   DISALLOW_COPY_AND_ASSIGN(AstExpressionVisitor);
index 3a833c520e89569cc5dab526ef05c657fabd937e..db0fd7be7d10a50125b308bbcd782c96c40558b0 100644 (file)
@@ -488,7 +488,9 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
   }
 
   // Type-check the function.
-  AstTyper(info()).Run();
+  AstTyper(info()->isolate(), info()->zone(), info()->closure(),
+           info()->scope(), info()->osr_ast_id(), info()->literal())
+      .Run();
 
   // Optimization could have been disabled by the parser. Note that this check
   // is only needed because the Hydrogen graph builder is missing some bailouts.
index fadf6e9ad2131385df9fb96a27da62ac88c39f5a..4a3dd2710b1514dcf0c179575a2e5420c132cfde 100644 (file)
@@ -8335,7 +8335,9 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
 
   // Type-check the inlined function.
   DCHECK(target_shared->has_deoptimization_support());
-  AstTyper(&target_info).Run();
+  AstTyper(target_info.isolate(), target_info.zone(), target_info.closure(),
+           target_info.scope(), target_info.osr_ast_id(), target_info.literal())
+      .Run();
 
   int inlining_id = 0;
   if (top_info()->is_tracking_positions()) {
index 97a641a8d07d75d130a91f910e455df08bd8c6c8..af7641b48558ee2533104c10ba37af13255db53f 100644 (file)
@@ -14,8 +14,9 @@ namespace v8 {
 namespace internal {
 
 
-TypingReseter::TypingReseter(CompilationInfo* info)
-    : AstExpressionVisitor(info) {}
+TypingReseter::TypingReseter(Isolate* isolate, Zone* zone,
+                             FunctionLiteral* root)
+    : AstExpressionVisitor(isolate, zone, root) {}
 
 
 void TypingReseter::VisitExpression(Expression* expression) {
index 7d87dc0f50c873393b039a062b014935010e579d..b809eb21618084ea8475bba2566cfb4b498c8e82 100644 (file)
@@ -15,7 +15,7 @@ namespace internal {
 
 class TypingReseter : public AstExpressionVisitor {
  public:
-  explicit TypingReseter(CompilationInfo* info);
+  TypingReseter(Isolate* isolate, Zone* zone, FunctionLiteral* root);
 
  protected:
   void VisitExpression(Expression* expression) override;
index b2b60bde2c7a39dcf2ac56f54fedee8edf2e0237..fb758828b076524a47c6be702050437507d4be95 100644 (file)
@@ -15,14 +15,17 @@ namespace v8 {
 namespace internal {
 
 
-AstTyper::AstTyper(CompilationInfo* info)
-    : info_(info),
-      oracle_(info->isolate(), info->zone(),
-              handle(info->closure()->shared()->code()),
-              handle(info->closure()->shared()->feedback_vector()),
-              handle(info->closure()->context()->native_context())),
-      store_(info->zone()) {
-  InitializeAstVisitor(info->isolate(), info->zone());
+AstTyper::AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
+                   Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root)
+    : closure_(closure),
+      scope_(scope),
+      osr_ast_id_(osr_ast_id),
+      root_(root),
+      oracle_(isolate, zone, handle(closure->shared()->code()),
+              handle(closure->shared()->feedback_vector()),
+              handle(closure->context()->native_context())),
+      store_(zone) {
+  InitializeAstVisitor(isolate, zone);
 }
 
 
@@ -45,18 +48,17 @@ Effect AstTyper::ObservedOnStack(Object* value) {
 
 
 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) {
-  if (stmt->OsrEntryId() != info_->osr_ast_id()) return;
+  if (stmt->OsrEntryId() != osr_ast_id_) return;
 
   DisallowHeapAllocation no_gc;
   JavaScriptFrameIterator it(isolate());
   JavaScriptFrame* frame = it.frame();
-  Scope* scope = info_->scope();
 
   // Assert that the frame on the stack belongs to the function we want to OSR.
-  DCHECK_EQ(*info_->closure(), frame->function());
+  DCHECK_EQ(*closure_, frame->function());
 
-  int params = scope->num_parameters();
-  int locals = scope->StackLocalCount();
+  int params = scope_->num_parameters();
+  int locals = scope_->StackLocalCount();
 
   // Use sequential composition to achieve desired narrowing.
   // The receiver is a parameter with index -1.
@@ -71,21 +73,19 @@ void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) {
 
 #ifdef OBJECT_PRINT
   if (FLAG_trace_osr && FLAG_print_scopes) {
-    PrintObserved(scope->receiver(),
-                  frame->receiver(),
+    PrintObserved(scope_->receiver(), frame->receiver(),
                   store_.LookupBounds(parameter_index(-1)).lower);
 
     for (int i = 0; i < params; i++) {
-      PrintObserved(scope->parameter(i),
-                    frame->GetParameter(i),
+      PrintObserved(scope_->parameter(i), frame->GetParameter(i),
                     store_.LookupBounds(parameter_index(i)).lower);
     }
 
     ZoneList<Variable*> local_vars(locals, zone());
-    ZoneList<Variable*> context_vars(scope->ContextLocalCount(), zone());
-    ZoneList<Variable*> global_vars(scope->ContextGlobalCount(), zone());
-    scope->CollectStackAndContextLocals(&local_vars, &context_vars,
-                                        &global_vars);
+    ZoneList<Variable*> context_vars(scope_->ContextLocalCount(), zone());
+    ZoneList<Variable*> global_vars(scope_->ContextGlobalCount(), zone());
+    scope_->CollectStackAndContextLocals(&local_vars, &context_vars,
+                                         &global_vars);
     for (int i = 0; i < locals; i++) {
       PrintObserved(local_vars.at(i),
                     frame->GetExpression(i),
@@ -105,9 +105,8 @@ void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) {
 
 
 void AstTyper::Run() {
-  Scope* scope = info_->scope();
-  RECURSE(VisitDeclarations(scope->declarations()));
-  RECURSE(VisitStatements(info_->literal()->body()));
+  RECURSE(VisitDeclarations(scope_->declarations()));
+  RECURSE(VisitStatements(root_->body()));
 }
 
 
index ccfb973437faa6f672ac1f1f0ffb29f895aa7516..8b3e97b67ca67141ab9283c580fd2982c6a973e8 100644 (file)
@@ -19,7 +19,8 @@ namespace internal {
 
 class AstTyper: public AstVisitor {
  public:
-  explicit AstTyper(CompilationInfo* info);
+  AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
+           Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root);
   void Run();
 
   DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
@@ -32,7 +33,10 @@ class AstTyper: public AstVisitor {
   typedef v8::internal::Effects<int, kNoVar> Effects;
   typedef v8::internal::NestedEffects<int, kNoVar> Store;
 
-  CompilationInfo* info_;
+  Handle<JSFunction> closure_;
+  Scope* scope_;
+  BailoutId osr_ast_id_;
+  FunctionLiteral* root_;
   TypeFeedbackOracle oracle_;
   Store store_;
 
index b64638b8e0b9b16e9bef2e5ebd2578e52cc85bae..9ab85edf82c8087df2922b44a718d4871859ef50 100644 (file)
@@ -28,8 +28,9 @@ struct {
 
 
 ExpressionTypeCollector::ExpressionTypeCollector(
-    CompilationInfo* info, ZoneVector<ExpressionTypeEntry>* dst)
-    : AstExpressionVisitor(info), result_(dst) {}
+    Isolate* isolate, Zone* zone, FunctionLiteral* root,
+    ZoneVector<ExpressionTypeEntry>* dst)
+    : AstExpressionVisitor(isolate, zone, root), result_(dst) {}
 
 
 void ExpressionTypeCollector::Run() {
index 4cf4e47e33676f884ef8e5de560726fc4bdd99b0..2175f5a0451262f26c1462c2280e09950626cb03 100644 (file)
 namespace v8 {
 namespace internal {
 
-// A Visitor over a CompilationInfo's AST that collects
-// a human readable string summarizing structure and types.
-// Used for testing of the typing information attached to the
-// expression nodes of an AST.
+// A Visitor over an AST that collects a human readable string summarizing
+// structure and types. Used for testing of the typing information attached
+// to the expression nodes of an AST.
 
 struct ExpressionTypeEntry {
   int depth;
@@ -24,7 +23,7 @@ struct ExpressionTypeEntry {
 
 class ExpressionTypeCollector : public AstExpressionVisitor {
  public:
-  ExpressionTypeCollector(CompilationInfo* info,
+  ExpressionTypeCollector(Isolate* isolate, Zone* zone, FunctionLiteral* root,
                           ZoneVector<ExpressionTypeEntry>* dst);
   void Run();
 
index 886c0377a66fa4f0fb952af305e91737d598ce60..0cc71ec2f54fbc84fda2fe2398807ef1ca20e51f 100644 (file)
@@ -62,16 +62,13 @@ std::string Validate(Zone* zone, const char* source,
   info.set_allow_lazy_parsing(false);
   info.set_toplevel(true);
 
-  i::CompilationInfo compilation_info(&info);
   CHECK(i::Compiler::ParseAndAnalyze(&info));
-  info.set_literal(
-      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
 
-  AsmTyper typer(
-      isolate, zone, *script,
-      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
+  FunctionLiteral* root =
+      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun();
+  AsmTyper typer(isolate, zone, *script, root);
   if (typer.Validate()) {
-    ExpressionTypeCollector(&compilation_info, types).Run();
+    ExpressionTypeCollector(isolate, zone, root, types).Run();
     return "";
   } else {
     return typer.error_message();
index 33d64d3f20321180d99f5dd536d5bd6d90f2ddcf..8bf4c600dcf45a2f5f7b7e8e31b05a2b3e7a45f2 100644 (file)
@@ -38,12 +38,12 @@ static void CollectTypes(HandleAndZoneScope* handles, const char* source,
   info.set_allow_lazy_parsing(false);
   info.set_toplevel(true);
 
-  i::CompilationInfo compilation_info(&info);
   CHECK(i::Compiler::ParseAndAnalyze(&info));
-  info.set_literal(
-      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
 
-  ExpressionTypeCollector(&compilation_info, dst).Run();
+  ExpressionTypeCollector(
+      isolate, handles->main_zone(),
+      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun(), dst)
+      .Run();
 }
 }
 
index 67b123bd56e1b9a74bf126e577fec22bbb335654..3d1284810b2a7c1b0fba800f5e167dc2a8ef633a 100644 (file)
@@ -25,7 +25,8 @@ namespace {
 
 class TypeSetter : public AstExpressionVisitor {
  public:
-  explicit TypeSetter(CompilationInfo* info) : AstExpressionVisitor(info) {}
+  TypeSetter(Isolate* isolate, Zone* zone, FunctionLiteral* root)
+      : AstExpressionVisitor(isolate, zone, root) {}
 
  protected:
   void VisitExpression(Expression* expression) {
@@ -276,23 +277,22 @@ TEST(ResetTypingInfo) {
   info.set_allow_lazy_parsing(false);
   info.set_toplevel(true);
 
-  i::CompilationInfo compilation_info(&info);
   CHECK(i::Compiler::ParseAndAnalyze(&info));
-  info.set_literal(
-      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
+  FunctionLiteral* root =
+      info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun();
 
   // Core of the test.
   ZoneVector<ExpressionTypeEntry> types(handles.main_zone());
-  ExpressionTypeCollector(&compilation_info, &types).Run();
+  ExpressionTypeCollector(isolate, handles.main_zone(), root, &types).Run();
   CheckAllSame(types, Bounds::Unbounded());
 
-  TypeSetter(&compilation_info).Run();
+  TypeSetter(isolate, handles.main_zone(), root).Run();
 
-  ExpressionTypeCollector(&compilation_info, &types).Run();
+  ExpressionTypeCollector(isolate, handles.main_zone(), root, &types).Run();
   CheckAllSame(types, INT32_TYPE);
 
-  TypingReseter(&compilation_info).Run();
+  TypingReseter(isolate, handles.main_zone(), root).Run();
 
-  ExpressionTypeCollector(&compilation_info, &types).Run();
+  ExpressionTypeCollector(isolate, handles.main_zone(), root, &types).Run();
   CheckAllSame(types, Bounds::Unbounded());
 }