Skip to content

Commit

Permalink
Get rid of legacy 7.3 logic
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 26, 2023
1 parent 2726ad4 commit 07b45b8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 74 deletions.
31 changes: 5 additions & 26 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
use function fwrite;
use function implode;
use function in_array;
use function ini_get;
use function is_dir;
use function is_file;
use function microtime;
Expand All @@ -86,11 +85,8 @@
use function strtolower;
use function substr;
use function usort;
use function version_compare;

use const PHP_EOL;
use const PHP_OS;
use const PHP_VERSION;
use const PSALM_VERSION;
use const STDERR;

Expand Down Expand Up @@ -391,21 +387,13 @@ public function serverMode(LanguageServer $server): void
$this->file_reference_provider->loadReferenceCache();
$this->codebase->enterServerMode();

if (ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
// do nothing
} else {
$cpu_count = self::getCpuCount();
$cpu_count = self::getCpuCount();

// let's not go crazy
$usable_cpus = $cpu_count - 2;
// let's not go crazy
$usable_cpus = $cpu_count - 2;

if ($usable_cpus > 1) {
$this->threads = $usable_cpus;
}
if ($usable_cpus > 1) {
$this->threads = $usable_cpus;
}

$server->logInfo("Initializing: Initialize Plugins...");
Expand Down Expand Up @@ -1356,15 +1344,6 @@ public static function getCpuCount(): int
return 1;
}

// PHP 7.3 with JIT on OSX is screwed for multi-threads
if (ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
return 1;
}

if (!extension_loaded('pcntl')) {
// Psalm requires pcntl for multi-threads support
return 1;
Expand Down
6 changes: 1 addition & 5 deletions src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
use function in_array;
use function is_string;
use function strtolower;
use function version_compare;

use const PHP_VERSION;

/**
* @internal
Expand Down Expand Up @@ -267,8 +264,7 @@ public static function analyze(
$fq_catch_class,
false,
false,
version_compare(PHP_VERSION, '7.0.0dev', '>=')
&& strtolower($fq_catch_class) !== 'throwable'
strtolower($fq_catch_class) !== 'throwable'
&& $codebase->interfaceExists($fq_catch_class)
&& !$codebase->interfaceExtends($fq_catch_class, 'Throwable')
? ['Throwable' => new TNamedObject('Throwable')]
Expand Down
24 changes: 0 additions & 24 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Psalm\Internal\Codebase\ReferenceMapGenerator;
use Psalm\Internal\Composer;
use Psalm\Internal\ErrorHandler;
use Psalm\Internal\Fork\Pool;
use Psalm\Internal\Fork\PsalmRestarter;
use Psalm\Internal\IncludeCollector;
use Psalm\Internal\Provider\ClassLikeStorageCacheProvider;
Expand Down Expand Up @@ -73,15 +72,12 @@
use function strlen;
use function strpos;
use function substr;
use function version_compare;

use const DIRECTORY_SEPARATOR;
use const JSON_THROW_ON_ERROR;
use const LC_CTYPE;
use const PHP_EOL;
use const PHP_OS;
use const PHP_URL_SCHEME;
use const PHP_VERSION;
use const STDERR;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -269,8 +265,6 @@ public static function run(array $argv): void

$progress = self::initProgress($options, $config);

self::emitMacPcreWarning($options, $threads);

self::restart($options, $threads, $progress);

if (isset($options['debug-emitted-issues'])) {
Expand Down Expand Up @@ -865,24 +859,6 @@ private static function getCurrentDir(array $options): string
return $current_dir;
}

private static function emitMacPcreWarning(array $options, int $threads): void
{
if (!isset($options['threads'])
&& !isset($options['debug'])
&& $threads === 1
&& ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
echo(
'If you want to run Psalm as a language server, or run Psalm with' . PHP_EOL
. 'multiple processes (--threads=4), beware:' . PHP_EOL
. Pool::MAC_PCRE_MESSAGE . PHP_EOL . PHP_EOL
);
}
}

private static function restart(array $options, int $threads, Progress $progress): void
{
$ini_handler = new PsalmRestarter('PSALM');
Expand Down
19 changes: 0 additions & 19 deletions src/Psalm/Internal/Fork/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@
use function substr;
use function unserialize;
use function usleep;
use function version_compare;

use const PHP_EOL;
use const PHP_OS;
use const PHP_VERSION;
use const SIGALRM;
use const SIGTERM;
use const STREAM_IPPROTO_IP;
Expand Down Expand Up @@ -88,12 +85,6 @@ class Pool
/** @var ?Closure(mixed): void */
private ?Closure $task_done_closure = null;

public const MAC_PCRE_MESSAGE = 'Mac users: pcre.jit is set to 1 in your PHP config.' . PHP_EOL
. 'The pcre jit is known to cause segfaults in PHP 7.3 on Macs, and Psalm' . PHP_EOL
. 'will not execute in threaded mode to avoid indecipherable errors.' . PHP_EOL
. 'Consider adding pcre.jit=0 to your PHP config, or upgrade to PHP 7.4.' . PHP_EOL
. 'Relevant info: https://bugs.php.net/bug.php?id=77260';

/**
* @param array<int, array<int, mixed>> $process_task_data_iterator
* An array of task data items to be divided up among the
Expand Down Expand Up @@ -141,16 +132,6 @@ public function __construct(
exit(1);
}

if (ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
die(
self::MAC_PCRE_MESSAGE . PHP_EOL
);
}

// We'll keep track of if this is the parent process
// so that we can tell who will be doing the waiting
$is_parent = false;
Expand Down

0 comments on commit 07b45b8

Please sign in to comment.