]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Resolve XHPAST linter futures on background
authorvrana <jakubv@fb.com>
Tue, 19 Feb 2013 21:42:09 +0000 (13:42 -0800)
committervrana <jakubv@fb.com>
Thu, 21 Feb 2013 08:58:23 +0000 (00:58 -0800)
Summary: This is a little bit tricky - if both XHPAST and PhutilXHPAST linters lint the same path then they get the same future wrapped in two different Future iterators.

Test Plan:
  $ arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5015

src/lint/linter/ArcanistBaseXHPASTLinter.php
src/lint/linter/ArcanistPhutilXHPASTLinter.php
src/lint/linter/ArcanistXHPASTLinter.php

index 1d36ffff2c1128972e4e167887d99932ef945669..99fd45a1d37c9073e3de9342db0a952b1de7c4e6 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * @group linter
  */
-abstract class ArcanistBaseXHPASTLinter extends ArcanistLinter {
+abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
 
   protected function raiseLintAtToken(
     XHPASTToken $token,
index 7d03bbbfcfb3520799985f1bd9df62ceb99b1c0a..56d766766c0c20d20feadbe4af4af9983d222b6f 100644 (file)
@@ -68,11 +68,11 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     return 2;
   }
 
-  public function willLintPaths(array $paths) {
-    $this->xhpastLinter->willLintPaths($paths);
+  protected function buildFutures(array $paths) {
+    return $this->xhpastLinter->buildFutures($paths);
   }
 
-  public function lintPath($path) {
+  protected function resolveFuture($path, Future $future) {
     $tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
     if (!$tree) {
       return;
index d21e64f6d44c951b689530b1f0486ab13dd19628..61689b7aef75fc880d410f38b21b065d4d8cd0f0 100644 (file)
@@ -7,7 +7,8 @@
  */
 final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
-  protected $trees = array();
+  private $futures = array();
+  private $trees = array();
 
   const LINT_PHP_SYNTAX_ERROR          = 1;
   const LINT_UNABLE_TO_PARSE           = 2;
@@ -123,21 +124,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     );
   }
 
-  public function willLintPaths(array $paths) {
-    $futures = array();
+  protected function buildFutures(array $paths) {
+    $futures = Futures(array())->limit(8);
     foreach ($paths as $path) {
-      if (array_key_exists($path, $this->trees)) {
-        continue;
+      if (!isset($this->futures[$path])) {
+        $this->futures[$path] = xhpast_get_parser_future($this->getData($path));
       }
-      $futures[$path] = xhpast_get_parser_future($this->getData($path));
+      $futures->addFuture($this->futures[$path], $path);
     }
-    foreach (Futures($futures)->limit(8) as $path => $future) {
+    return $futures;
+  }
+
+  public function getXHPASTTreeForPath($path) {
+    if (!array_key_exists($path, $this->trees)) {
       $this->willLintPath($path);
       $this->trees[$path] = null;
       try {
         $this->trees[$path] = XHPASTTree::newFromDataAndResolvedExecFuture(
           $this->getData($path),
-          $future->resolve());
+          $this->futures[$path]->resolve());
         $root = $this->trees[$path]->getRootNode();
         $root->buildSelectCache();
         $root->buildTokenCache();
@@ -147,21 +152,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
           1,
           self::LINT_PHP_SYNTAX_ERROR,
           'This file contains a syntax error: '.$ex->getMessage());
-        $this->stopAllLinters();
-        return;
       } catch (Exception $ex) {
         $this->raiseLintAtPath(
           self::LINT_UNABLE_TO_PARSE,
           'XHPAST could not parse this file, probably because the AST is too '.
           'deep. Some lint issues may not have been detected. You may safely '.
           'ignore this warning.');
-        return;
       }
     }
-  }
-
-  public function getXHPASTTreeForPath($path) {
-    return idx($this->trees, $path);
+    return $this->trees[$path];
   }
 
   public function getCacheVersion() {
@@ -173,12 +172,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     return $version;
   }
 
-  public function lintPath($path) {
-    if (!$this->trees[$path]) {
+  protected function resolveFuture($path, Future $future) {
+    $tree = $this->getXHPASTTreeForPath($path);
+    if (!$tree) {
       return;
     }
 
-    $root = $this->trees[$path]->getRootNode();
+    $root = $tree->getRootNode();
 
     $method_codes = array(
       'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,