Skip to content

Commit

Permalink
Merge pull request #9326 from vimeo/prevent-jit-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 18, 2023
2 parents 95877a0 + 4d871fd commit 5fe902b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/Psalm/Internal/Cli/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ static function (string $arg) use ($valid_long_options): void {

$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();
Expand Down
7 changes: 6 additions & 1 deletion src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,12 @@ private static function restart(array $options, int $threads, Progress $progress
$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();
Expand Down
12 changes: 9 additions & 3 deletions src/Psalm/Internal/Cli/Psalter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -218,10 +218,16 @@ public static function run(array $argv): void
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);

Expand Down
17 changes: 12 additions & 5 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -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<non-empty-string> $disable_extensions */
public function disableExtensions(array $disable_extensions): void
{
$this->disabled_extensions = array_merge($this->disabled_extensions, $disable_extensions);
}

/**
Expand All @@ -42,7 +49,7 @@ public function disableExtension(string $disabledExtension): void
protected function requiresRestart($default): bool
{
$this->required = (bool) array_filter(
$this->disabledExtensions,
$this->disabled_extensions,
static fn(string $extension): bool => extension_loaded($extension)
);

Expand Down Expand Up @@ -72,7 +79,7 @@ protected function requiresRestart($default): bool
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);
Expand Down

0 comments on commit 5fe902b

Please sign in to comment.