From 4d871fd2413f6eac3d576ccd4d998db626e460ba Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 17 Feb 2023 15:30:55 -0400 Subject: [PATCH] Disable JIT-incompatible extensions to prevent warnings This also enables JIT for `psalter` and syncs the list of disabled extensions between `psalm`, `psalter` and `psalm-language-server` --- src/Psalm/Internal/Cli/LanguageServer.php | 8 +++++++- src/Psalm/Internal/Cli/Psalm.php | 7 ++++++- src/Psalm/Internal/Cli/Psalter.php | 12 +++++++++--- src/Psalm/Internal/Fork/PsalmRestarter.php | 17 ++++++++++++----- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index 1be270948..d9df65483 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -237,7 +237,13 @@ final class LanguageServer $ini_handler = new PsalmRestarter('PSALM'); - $ini_handler->disableExtension('grpc'); + $ini_handler->disableExtensions([ + 'grpc', + 'uopz', + // extensions bellow are incompatible with JIT + 'pcov', + 'blackfire', + ]); // If Xdebug is enabled, restart without it $ini_handler->check(); diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index f3551ad41..f7f60c78f 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -903,7 +903,12 @@ final class Psalm $ini_handler->disableExtension('grpc'); } - $ini_handler->disableExtension('uopz'); + $ini_handler->disableExtensions([ + 'uopz', + // extesions that are incompatible with JIT (they are also usually make Psalm slow) + 'pcov', + 'blackfire', + ]); // If Xdebug is enabled, restart without it $ini_handler->check(); diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index d19ad9888..6d5dfa0cf 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -3,13 +3,13 @@ namespace Psalm\Internal\Cli; use AssertionError; -use Composer\XdebugHandler\XdebugHandler; use Psalm\Config; use Psalm\Exception\UnsupportedIssueToFixException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\CliUtils; use Psalm\Internal\Composer; use Psalm\Internal\ErrorHandler; +use Psalm\Internal\Fork\PsalmRestarter; use Psalm\Internal\IncludeCollector; use Psalm\Internal\Provider\ClassLikeStorageCacheProvider; use Psalm\Internal\Provider\FileProvider; @@ -218,10 +218,16 @@ final class Psalter static fn(): ?\Composer\Autoload\ClassLoader => CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir) ); - + $ini_handler = new PsalmRestarter('PSALTER'); + $ini_handler->disableExtensions([ + 'grpc', + 'uopz', + 'pcov', + 'blackfire', + ]); // If Xdebug is enabled, restart without it - (new XdebugHandler('PSALTER'))->check(); + $ini_handler->check(); $paths_to_check = CliUtils::getPathsToCheck($options['f'] ?? null); diff --git a/src/Psalm/Internal/Fork/PsalmRestarter.php b/src/Psalm/Internal/Fork/PsalmRestarter.php index 1be0dbc6a..f02a33614 100644 --- a/src/Psalm/Internal/Fork/PsalmRestarter.php +++ b/src/Psalm/Internal/Fork/PsalmRestarter.php @@ -5,6 +5,7 @@ namespace Psalm\Internal\Fork; use Composer\XdebugHandler\XdebugHandler; use function array_filter; +use function array_merge; use function array_splice; use function extension_loaded; use function file_get_contents; @@ -26,11 +27,17 @@ class PsalmRestarter extends XdebugHandler /** * @var string[] */ - private array $disabledExtensions = []; + private array $disabled_extensions = []; - public function disableExtension(string $disabledExtension): void + public function disableExtension(string $disabled_extension): void { - $this->disabledExtensions[] = $disabledExtension; + $this->disabled_extensions[] = $disabled_extension; + } + + /** @param list $disable_extensions */ + public function disableExtensions(array $disable_extensions): void + { + $this->disabled_extensions = array_merge($this->disabled_extensions, $disable_extensions); } /** @@ -42,7 +49,7 @@ class PsalmRestarter extends XdebugHandler protected function requiresRestart($default): bool { $this->required = (bool) array_filter( - $this->disabledExtensions, + $this->disabled_extensions, static fn(string $extension): bool => extension_loaded($extension) ); @@ -72,7 +79,7 @@ class PsalmRestarter extends XdebugHandler protected function restart(array $command): void { if ($this->required && $this->tmpIni) { - $regex = '/^\s*(extension\s*=.*(' . implode('|', $this->disabledExtensions) . ').*)$/mi'; + $regex = '/^\s*(extension\s*=.*(' . implode('|', $this->disabled_extensions) . ').*)$/mi'; $content = file_get_contents($this->tmpIni); $content = preg_replace($regex, ';$1', $content);