Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser cache files maintenance #7082

Merged
merged 6 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
</errorLevel>
</PossiblyUnusedProperty>

<UnusedMethod>
<errorLevel type="suppress">
<referencedMethod name="Psalm\Internal\Analyzer\ProjectAnalyzer::getAllFiles"/>
</errorLevel>
</UnusedMethod>

<PossiblyUnusedMethod>
<errorLevel type="suppress">
<directory name="src/Psalm/Plugin"/>
Expand All @@ -128,6 +134,8 @@
<referencedMethod name="Psalm\Codebase::createClassLikeStorage"/>
<referencedMethod name="Psalm\Codebase::isVariadic"/>
<referencedMethod name="Psalm\Codebase::getMethodReturnsByRef"/>
<referencedMethod name="Psalm\Internal\Provider\ParserCacheProvider::processSuccessfulRun"/>
<referencedMethod name="Psalm\Internal\Provider\ParserCacheProvider::touchParserCaches"/>
</errorLevel>
</PossiblyUnusedMethod>

Expand Down
11 changes: 3 additions & 8 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,18 +684,12 @@ public function check(string $base_dir, bool $is_diff = false): void
true
);

if ($this->project_cache_provider && $this->parser_cache_provider) {
$removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches(
$is_diff ? $this->project_cache_provider->getLastRun(PSALM_VERSION) : $start_checks
);
if ($this->project_cache_provider && $this->parser_cache_provider && !$is_diff) {
$removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches($start_checks);

if ($removed_parser_files) {
$this->progress->debug('Removed ' . $removed_parser_files . ' old parser caches' . "\n");
}

if ($is_diff) {
$this->parser_cache_provider->touchParserCaches($this->getAllFiles($this->config), $start_checks);
}
}
}

Expand Down Expand Up @@ -1074,6 +1068,7 @@ private function checkDirWithConfig(string $dir_name, Config $config, bool $allo

/**
* @return list<string>
* @deprecated going to be removed in Psalm 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private function of an internal class may be removed right away.

*/
private function getAllFiles(Config $config): array
{
Expand Down
6 changes: 5 additions & 1 deletion src/Psalm/Internal/Provider/ParserCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function deleteOldParserCaches(float $time_before): int
{
$cache_directory = Config::getInstance()->getCacheDirectory();

if ($cache_directory) {
if (!$cache_directory) {
return 0;
}

Expand Down Expand Up @@ -349,6 +349,9 @@ public function deleteOldParserCaches(float $time_before): int
return $removed_count;
}

/**
* @deprecated going to be removed in Psalm 5
*/
public function processSuccessfulRun(): void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't require deprecation period either.

{
$cache_directory = Config::getInstance()->getCacheDirectory();
Expand Down Expand Up @@ -376,6 +379,7 @@ public function processSuccessfulRun(): void

/**
* @param array<string> $file_names
* @deprecated going to be removed in Psalm 5
*/
public function touchParserCaches(array $file_names, int $min_time): void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

{
Expand Down
4 changes: 0 additions & 4 deletions src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,6 @@ function (IssueData $d1, IssueData $d2): int {
if ($project_analyzer->project_cache_provider) {
$project_analyzer->project_cache_provider->processSuccessfulRun($start_time, PSALM_VERSION);
}

if ($codebase->statements_provider->parser_cache_provider) {
$codebase->statements_provider->parser_cache_provider->processSuccessfulRun();
}
}

if ($error_count
Expand Down