From: vrana Date: Tue, 19 Feb 2013 21:42:09 +0000 (-0800) Subject: Resolve XHPAST linter futures on background X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=df013f628253135bf1e9d224727fd1f34be2cd98;p=arcanist.git Resolve XHPAST linter futures on background 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 --- diff --git a/src/lint/linter/ArcanistBaseXHPASTLinter.php b/src/lint/linter/ArcanistBaseXHPASTLinter.php index 1d36ffff..99fd45a1 100644 --- a/src/lint/linter/ArcanistBaseXHPASTLinter.php +++ b/src/lint/linter/ArcanistBaseXHPASTLinter.php @@ -3,7 +3,7 @@ /** * @group linter */ -abstract class ArcanistBaseXHPASTLinter extends ArcanistLinter { +abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter { protected function raiseLintAtToken( XHPASTToken $token, diff --git a/src/lint/linter/ArcanistPhutilXHPASTLinter.php b/src/lint/linter/ArcanistPhutilXHPASTLinter.php index 7d03bbbf..56d76676 100644 --- a/src/lint/linter/ArcanistPhutilXHPASTLinter.php +++ b/src/lint/linter/ArcanistPhutilXHPASTLinter.php @@ -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; diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index d21e64f6..61689b7a 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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,