-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
291 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\Codebase\Analyzer; | ||
|
||
/** @internal */ | ||
final class AnalyzerTask implements Task | ||
{ | ||
public function __construct(private string $file) | ||
{ | ||
} | ||
public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
$codebase = ProjectAnalyzer::getInstance()->getCodebase(); | ||
return Analyzer::analysisWorker($codebase->config, $codebase->getProgress(), $this->file); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\Codebase\Scanner; | ||
|
||
/** @psalm-import-type PoolData from Scanner */ | ||
final class InitAnalyzerTask implements Task | ||
{ | ||
/** @var PoolData */ | ||
private readonly array $data; | ||
public function __construct() | ||
{ | ||
$this->data = ShutdownScannerTask::getPoolData(); | ||
} | ||
public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
ProjectAnalyzer::getInstance()->getCodebase()->addThreadData($this->data); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\Provider\ClassLikeStorageProvider; | ||
use Psalm\Internal\Provider\FileStorageProvider; | ||
|
||
use const PHP_EOL; | ||
|
||
final class InitScannerTask implements Task | ||
{ | ||
final public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
$analyzer = ProjectAnalyzer::getInstance(); | ||
$analyzer->progress->debug('Initialising forked process for scanning' . PHP_EOL); | ||
|
||
$codebase = $analyzer->getCodebase(); | ||
$statements_provider = $codebase->statements_provider; | ||
|
||
$codebase->scanner->isForked(); | ||
FileStorageProvider::deleteAll(); | ||
ClassLikeStorageProvider::deleteAll(); | ||
|
||
$statements_provider->resetDiffs(); | ||
|
||
$analyzer->progress->debug('Have initialised forked process for scanning' . PHP_EOL); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Config; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\CliUtils; | ||
use Psalm\Internal\ErrorHandler; | ||
use Psalm\Internal\VersionUtils; | ||
use Psalm\IssueBuffer; | ||
|
||
use function cli_get_process_title; | ||
use function define; | ||
use function function_exists; | ||
use function gc_collect_cycles; | ||
use function gc_disable; | ||
use function ini_get; | ||
use function ini_set; | ||
|
||
final class InitStartupTask implements Task | ||
{ | ||
private readonly string $memoryLimit; | ||
private readonly array $server; | ||
private readonly ?string $processTitle; | ||
final public function __construct(private ProjectAnalyzer $analyzer) | ||
{ | ||
$this->memoryLimit = ini_get('memory_limit'); | ||
$this->server = IssueBuffer::getServer(); | ||
if (function_exists('cli_get_process_title')) { | ||
$this->processTitle = cli_get_process_title(); | ||
} else { | ||
$this->processTitle = null; | ||
} | ||
} | ||
final public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
define('PSALM_VERSION', VersionUtils::getPsalmVersion()); | ||
define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); | ||
|
||
CliUtils::checkRuntimeRequirements(); | ||
gc_collect_cycles(); | ||
gc_disable(); | ||
|
||
ErrorHandler::install([]); | ||
|
||
ini_set('memory_limit', $this->memoryLimit); | ||
|
||
IssueBuffer::captureServer($this->server); | ||
|
||
// More initialization is needed but doing just this for now... | ||
|
||
ProjectAnalyzer::$instance = $this->analyzer; | ||
Config::setInstance($this->analyzer->getConfig()); | ||
|
||
/*if (function_exists('cli_set_process_title') && $this->processTitle !== null) { | ||
@cli_set_process_title($this->processTitle); | ||
}*/ | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
|
||
/** @internal */ | ||
final class ScannerTask implements Task | ||
{ | ||
public function __construct(private string $file) | ||
{ | ||
} | ||
public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
return ProjectAnalyzer::getInstance()->getCodebase()->scanner->scanAPath($this->file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\Codebase\Analyzer; | ||
use Psalm\Internal\FileManipulation\FileManipulationBuffer; | ||
use Psalm\Internal\FileManipulation\FunctionDocblockManipulator; | ||
use Psalm\IssueBuffer; | ||
|
||
/** | ||
* @internal | ||
* @psalm-import-type WorkerData from Analyzer | ||
* @implements Task<void, void, WorkerData> | ||
*/ | ||
final class ShutdownAnalyzerTask implements Task | ||
{ | ||
/** | ||
* @return WorkerData | ||
*/ | ||
public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
$project_analyzer = ProjectAnalyzer::getInstance(); | ||
$codebase = $project_analyzer->getCodebase(); | ||
$analyzer = $codebase->analyzer; | ||
$file_reference_provider = $codebase->file_reference_provider; | ||
|
||
$project_analyzer->progress->debug('Gathering data for forked process'."\n"); | ||
|
||
$channel->send($channel->receive($cancellation)); | ||
|
||
// @codingStandardsIgnoreStart | ||
return [ | ||
'issues' => IssueBuffer::getIssuesData(), | ||
'fixable_issue_counts' => IssueBuffer::getFixableIssues(), | ||
'nonmethod_references_to_classes' => $file_reference_provider->getAllNonMethodReferencesToClasses(), | ||
'method_references_to_classes' => $file_reference_provider->getAllMethodReferencesToClasses(), | ||
'file_references_to_class_members' => $file_reference_provider->getAllFileReferencesToClassMembers(), | ||
'method_references_to_class_members' => $file_reference_provider->getAllMethodReferencesToClassMembers(), | ||
'method_dependencies' => $file_reference_provider->getAllMethodDependencies(), | ||
'file_references_to_class_properties' => $file_reference_provider->getAllFileReferencesToClassProperties(), | ||
'file_references_to_method_returns' => $file_reference_provider->getAllFileReferencesToMethodReturns(), | ||
'method_references_to_class_properties' => $file_reference_provider->getAllMethodReferencesToClassProperties(), | ||
'method_references_to_method_returns' => $file_reference_provider->getAllMethodReferencesToMethodReturns(), | ||
'file_references_to_missing_class_members' => $file_reference_provider->getAllFileReferencesToMissingClassMembers(), | ||
'method_references_to_missing_class_members' => $file_reference_provider->getAllMethodReferencesToMissingClassMembers(), | ||
'method_param_uses' => $file_reference_provider->getAllMethodParamUses(), | ||
'mixed_member_names' => $analyzer->getMixedMemberNames(), | ||
'file_manipulations' => FileManipulationBuffer::getAll(), | ||
'mixed_counts' => $analyzer->getMixedCounts(), | ||
'function_timings' => $analyzer->getFunctionTimings(), | ||
'analyzed_methods' => $analyzer->getAnalyzedMethods(), | ||
'file_maps' => $analyzer->getFileMaps(), | ||
'class_locations' => $file_reference_provider->getAllClassLocations(), | ||
'class_method_locations' => $file_reference_provider->getAllClassMethodLocations(), | ||
'class_property_locations' => $file_reference_provider->getAllClassPropertyLocations(), | ||
'possible_method_param_types' => $analyzer->getPossibleMethodParamTypes(), | ||
'taint_data' => $codebase->taint_flow_graph, | ||
'unused_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUnusedSuppressions() : [], | ||
'used_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUsedSuppressions() : [], | ||
'function_docblock_manipulators' => FunctionDocblockManipulator::getManipulators(), | ||
'mutable_classes' => $codebase->analyzer->mutable_classes, | ||
]; | ||
// @codingStandardsIgnoreEnd | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\Fork; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Parallel\Worker\Task; | ||
use Amp\Sync\Channel; | ||
use Psalm\Internal\Analyzer\ProjectAnalyzer; | ||
use Psalm\Internal\Codebase\Scanner; | ||
use Psalm\IssueBuffer; | ||
|
||
use const PHP_EOL; | ||
|
||
/** | ||
* @internal | ||
* @psalm-import-type PoolData from Scanner | ||
* @implements Task<void, void, PoolData> | ||
*/ | ||
final class ShutdownScannerTask implements Task | ||
{ | ||
/** | ||
* @return PoolData | ||
*/ | ||
public function run(Channel $channel, Cancellation $cancellation): mixed | ||
{ | ||
return self::getPoolData(); | ||
} | ||
/** | ||
* @return PoolData | ||
*/ | ||
public static function getPoolData(): array | ||
{ | ||
$project_analyzer = ProjectAnalyzer::getInstance(); | ||
$project_analyzer->progress->debug('Collecting data from forked scanner process' . PHP_EOL); | ||
|
||
$project_analyzer = ProjectAnalyzer::getInstance(); | ||
$codebase = $project_analyzer->getCodebase(); | ||
$statements_provider = $codebase->statements_provider; | ||
|
||
return [ | ||
'classlikes_data' => $codebase->classlikes->getThreadData(), | ||
'scanner_data' => $codebase->scanner->getThreadData(), | ||
'issues' => IssueBuffer::getIssuesData(), | ||
'changed_members' => $statements_provider->getChangedMembers(), | ||
'unchanged_signature_members' => $statements_provider->getUnchangedSignatureMembers(), | ||
'diff_map' => $statements_provider->getDiffMap(), | ||
'deletion_ranges' => $statements_provider->getDeletionRanges(), | ||
'errors' => $statements_provider->getErrors(), | ||
'classlike_storage' => $codebase->classlike_storage_provider->getAll(), | ||
'file_storage' => $codebase->file_storage_provider->getAll(), | ||
'new_file_content_hashes' => $statements_provider->parser_cache_provider | ||
? $statements_provider->parser_cache_provider->getNewFileContentHashes() | ||
: [], | ||
'taint_data' => $codebase->taint_flow_graph, | ||
]; | ||
} | ||
} |