Updated Rector to commit 4c56874ee79f5dd3ea2e97ea12e13335ebd6765b

4c56874ee7 Cache on successful file processing (#3604)
This commit is contained in:
Tomas Votruba 2023-04-11 06:22:54 +00:00
parent c65ab46563
commit 87f8efd4a8
10 changed files with 59 additions and 43 deletions

View File

@ -13,6 +13,10 @@ use Rector\Caching\Enum\CacheKey;
*/
final class ChangedFilesDetector
{
/**
* @var array<string, string[]>
*/
private $dependentFiles = [];
/**
* @readonly
* @var \Rector\Caching\Config\FileHashComputer
@ -31,12 +35,17 @@ final class ChangedFilesDetector
/**
* @param string[] $dependentFiles
*/
public function addFileWithDependencies(string $filePath, array $dependentFiles) : void
public function addFileDependentFiles(string $filePath, array $dependentFiles) : void
{
$filePathCacheKey = $this->getFilePathCacheKey($filePath);
$this->dependentFiles[$filePathCacheKey] = $dependentFiles;
}
public function addFileWithDependencies(string $filePath) : void
{
$filePathCacheKey = $this->getFilePathCacheKey($filePath);
$hash = $this->hashFile($filePath);
$this->cache->save($filePathCacheKey, CacheKey::FILE_HASH_KEY, $hash);
$this->cache->save($filePathCacheKey . '_files', CacheKey::DEPENDENT_FILES_KEY, $dependentFiles);
$this->cache->save($filePathCacheKey . '_files', CacheKey::DEPENDENT_FILES_KEY, $this->dependentFiles[$filePathCacheKey]);
}
public function hasFileChanged(string $filePath) : bool
{

View File

@ -376,6 +376,6 @@ final class PHPStanNodeScopeResolver
// @ignoreException
}
}
$this->changedFilesDetector->addFileWithDependencies($filePath, $dependentFiles);
$this->changedFilesDetector->addFileDependentFiles($filePath, $dependentFiles);
}
}

View File

@ -6,6 +6,7 @@ namespace Rector\Parallel;
use RectorPrefix202304\Clue\React\NDJson\Decoder;
use RectorPrefix202304\Clue\React\NDJson\Encoder;
use RectorPrefix202304\Nette\Utils\FileSystem;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Core\Application\ApplicationFileProcessor;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
@ -58,6 +59,11 @@ final class WorkerRunner
* @var \Rector\Core\Application\ApplicationFileProcessor
*/
private $applicationFileProcessor;
/**
* @readonly
* @var \Rector\Caching\Detector\ChangedFilesDetector
*/
private $changedFilesDetector;
/**
* @var FileProcessorInterface[]
* @readonly
@ -66,7 +72,7 @@ final class WorkerRunner
/**
* @param FileProcessorInterface[] $fileProcessors
*/
public function __construct(ArrayParametersMerger $arrayParametersMerger, CurrentFileProvider $currentFileProvider, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, RectorConsoleOutputStyle $rectorConsoleOutputStyle, RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor, ApplicationFileProcessor $applicationFileProcessor, array $fileProcessors = [])
public function __construct(ArrayParametersMerger $arrayParametersMerger, CurrentFileProvider $currentFileProvider, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, RectorConsoleOutputStyle $rectorConsoleOutputStyle, RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor, ApplicationFileProcessor $applicationFileProcessor, ChangedFilesDetector $changedFilesDetector, array $fileProcessors = [])
{
$this->arrayParametersMerger = $arrayParametersMerger;
$this->currentFileProvider = $currentFileProvider;
@ -74,6 +80,7 @@ final class WorkerRunner
$this->rectorConsoleOutputStyle = $rectorConsoleOutputStyle;
$this->removedAndAddedFilesProcessor = $removedAndAddedFilesProcessor;
$this->applicationFileProcessor = $applicationFileProcessor;
$this->changedFilesDetector = $changedFilesDetector;
$this->fileProcessors = $fileProcessors;
}
public function run(Encoder $encoder, Decoder $decoder, Configuration $configuration) : void
@ -100,13 +107,20 @@ final class WorkerRunner
// 1. allow PHPStan to work with static reflection on provided files
$this->applicationFileProcessor->configurePHPStanNodeScopeResolver($filePaths, $configuration);
foreach ($filePaths as $filePath) {
$file = null;
try {
$file = new File($filePath, FileSystem::read($filePath));
$this->currentFileProvider->setFile($file);
$errorAndFileDiffs = $this->processFiles($file, $configuration, $errorAndFileDiffs);
if ($errorAndFileDiffs[Bridge::SYSTEM_ERRORS] !== []) {
$this->changedFilesDetector->invalidateFile($file->getFilePath());
} else {
$this->changedFilesDetector->addFileWithDependencies($file->getFilePath());
}
} catch (Throwable $throwable) {
++$systemErrorsCount;
$systemErrors = $this->collectSystemErrors($systemErrors, $throwable, $filePath);
$this->invalidateFile($file);
}
}
$this->removedAndAddedFilesProcessor->run($configuration);
@ -147,4 +161,11 @@ final class WorkerRunner
$systemErrors[] = new SystemError($errorMessage, $filePath, $throwable->getLine());
return $systemErrors;
}
private function invalidateFile(?File $file) : void
{
if ($file === null) {
return;
}
$this->changedFilesDetector->invalidateFile($file->getFilePath());
}
}

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Core\Application;
use PHPStan\Analyser\NodeScopeResolver;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Configuration\Option;
@ -88,6 +89,11 @@ final class ApplicationFileProcessor
* @var \Symplify\EasyParallel\CpuCoreCountProvider
*/
private $cpuCoreCountProvider;
/**
* @readonly
* @var \Rector\Caching\Detector\ChangedFilesDetector
*/
private $changedFilesDetector;
/**
* @var FileProcessorInterface[]
* @readonly
@ -96,7 +102,7 @@ final class ApplicationFileProcessor
/**
* @param FileProcessorInterface[] $fileProcessors
*/
public function __construct(Filesystem $filesystem, FileDiffFileDecorator $fileDiffFileDecorator, RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor, OutputStyleInterface $rectorOutputStyle, FileFactory $fileFactory, NodeScopeResolver $nodeScopeResolver, ArrayParametersMerger $arrayParametersMerger, ParallelFileProcessor $parallelFileProcessor, ParameterProvider $parameterProvider, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, array $fileProcessors = [])
public function __construct(Filesystem $filesystem, FileDiffFileDecorator $fileDiffFileDecorator, RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor, OutputStyleInterface $rectorOutputStyle, FileFactory $fileFactory, NodeScopeResolver $nodeScopeResolver, ArrayParametersMerger $arrayParametersMerger, ParallelFileProcessor $parallelFileProcessor, ParameterProvider $parameterProvider, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, array $fileProcessors = [])
{
$this->filesystem = $filesystem;
$this->fileDiffFileDecorator = $fileDiffFileDecorator;
@ -109,6 +115,7 @@ final class ApplicationFileProcessor
$this->parameterProvider = $parameterProvider;
$this->scheduleFactory = $scheduleFactory;
$this->cpuCoreCountProvider = $cpuCoreCountProvider;
$this->changedFilesDetector = $changedFilesDetector;
$this->fileProcessors = $fileProcessors;
}
/**
@ -160,6 +167,11 @@ final class ApplicationFileProcessor
$result = $fileProcessor->process($file, $configuration);
$systemErrorsAndFileDiffs = $this->arrayParametersMerger->merge($systemErrorsAndFileDiffs, $result);
}
if ($systemErrorsAndFileDiffs[Bridge::SYSTEM_ERRORS] !== []) {
$this->changedFilesDetector->invalidateFile($file->getFilePath());
} else {
$this->changedFilesDetector->addFileWithDependencies($file->getFilePath());
}
// progress bar +1
if ($shouldShowProgressBar) {
$this->rectorOutputStyle->progressAdvance();

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '5ea7727cfd05ece95fa8730576360e58148b3d56';
public const PACKAGE_VERSION = '4c56874ee79f5dd3ea2e97ea12e13335ebd6765b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-04-11 11:11:36';
public const RELEASE_DATE = '2023-04-11 08:18:06';
/**
* @var int
*/

View File

@ -124,8 +124,6 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
$processResult = $this->processResultFactory->create($systemErrorsAndFileDiffs);
$outputFormatter->report($processResult, $configuration);
// invalidate affected files
$this->invalidateCacheForChangedAndErroredFiles($processResult);
return $this->resolveReturnCode($processResult, $configuration);
}
protected function initialize(InputInterface $input, OutputInterface $output) : void
@ -144,19 +142,6 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
$this->changedFilesDetector->clear();
}
}
private function invalidateCacheForChangedAndErroredFiles(ProcessResult $processResult) : void
{
foreach ($processResult->getChangedFilePaths() as $changedFilePath) {
$this->changedFilesDetector->invalidateFile($changedFilePath);
}
foreach ($processResult->getErrors() as $systemError) {
$errorFile = $systemError->getFile();
if (!\is_string($errorFile)) {
continue;
}
$this->changedFilesDetector->invalidateFile($errorFile);
}
}
/**
* @return ExitCode::*
*/

View File

@ -80,15 +80,4 @@ final class ProcessResult
{
return $this->removedNodeCount;
}
/**
* @return string[]
*/
public function getChangedFilePaths() : array
{
$fileInfos = [];
foreach ($this->fileDiffs as $fileDiff) {
$fileInfos[] = $fileDiff->getRelativeFilePath();
}
return \array_unique($fileInfos);
}
}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite906da29302a84c00e68ca2917ac144e::getLoader();
return ComposerAutoloaderInit09aa5aa531bd5622dc91fe03702bfeaf::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite906da29302a84c00e68ca2917ac144e
class ComposerAutoloaderInit09aa5aa531bd5622dc91fe03702bfeaf
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInite906da29302a84c00e68ca2917ac144e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInite906da29302a84c00e68ca2917ac144e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit09aa5aa531bd5622dc91fe03702bfeaf', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite906da29302a84c00e68ca2917ac144e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit09aa5aa531bd5622dc91fe03702bfeaf', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite906da29302a84c00e68ca2917ac144e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInite906da29302a84c00e68ca2917ac144e::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInite906da29302a84c00e68ca2917ac144e
class ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3138,9 +3138,9 @@ class ComposerStaticInite906da29302a84c00e68ca2917ac144e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite906da29302a84c00e68ca2917ac144e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite906da29302a84c00e68ca2917ac144e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite906da29302a84c00e68ca2917ac144e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit09aa5aa531bd5622dc91fe03702bfeaf::$classMap;
}, null, ClassLoader::class);
}