Skip to content

Commit

Permalink
Update to master
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 13, 2023
1 parent ea3dff7 commit 3b89105
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
12 changes: 1 addition & 11 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@1ee0f1bcb81fa87d8b33a74ede37a6b1d8317294">
<files psalm-version="dev-master@0fb0714141f08525d32caba1169ec169903cd227">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
Expand Down Expand Up @@ -233,11 +233,6 @@
<code><![CDATA[$options['tcp'] ?? null]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Psalm/Internal/Cli/Psalm.php">
<PossiblyUndefinedStringArrayOffset>
<code><![CDATA[opcache_get_status(false)['opcache_enabled']]]></code>
</PossiblyUndefinedStringArrayOffset>
</file>
<file src="src/Psalm/Internal/Cli/Refactor.php">
<PossiblyUndefinedIntArrayOffset>
<code>$identifier_name</code>
Expand Down Expand Up @@ -315,11 +310,6 @@
<code><![CDATA[$stmt->props[0]]]></code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Fork/PsalmRestarter.php">
<PossiblyUndefinedStringArrayOffset>
<code><![CDATA[opcache_get_status(false)['opcache_enabled']]]></code>
</PossiblyUndefinedStringArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/LanguageClient.php">
<DocblockTypeContradiction>
<code><![CDATA[$type < 1]]></code>
Expand Down
5 changes: 3 additions & 2 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,9 @@ private static function restart(array $options, int $threads, Progress $progress
$ini_handler->check();

if (!function_exists('opcache_get_status')
|| !opcache_get_status(false)
|| !opcache_get_status(false)['opcache_enabled']
|| !($opcache_status = opcache_get_status(false))
|| !isset($opcache_status['opcache_enabled'])
|| !$opcache_status['opcache_enabled']
) {
$progress->write(PHP_EOL
. 'Install the opcache extension to make use of JIT on PHP 8.0+ for a 20%+ performance boost!'
Expand Down
63 changes: 32 additions & 31 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use function extension_loaded;
use function file_get_contents;
use function file_put_contents;
use function function_exists;
use function implode;
use function in_array;
use function ini_get;
use function opcache_get_status;
use function preg_replace;

use const PHP_VERSION_ID;

/**
* @internal
*/
Expand Down Expand Up @@ -45,20 +45,20 @@ protected function requiresRestart($default): bool
$this->disabledExtensions,
static fn(string $extension): bool => extension_loaded($extension)
);
if (!function_exists('opcache_get_status')
|| !opcache_get_status(false)
|| !opcache_get_status(false)['opcache_enabled']
) {
return true;
}
if (!in_array(ini_get('opcache.enable_cli'), ['1', 'true', true, 1])) {
return true;
}
if (((int) ini_get('opcache.jit')) !== 1205) {
return true;
}
if (((int) ini_get('opcache.jit')) === 0) {
return true;

if (PHP_VERSION_ID >= 8_00_00 && (extension_loaded('opcache') || extension_loaded('Zend OPcache'))) {
// restart to enable JIT if it's not configured in the optimal way
if (!in_array(ini_get('opcache.enable_cli'), ['1', 'true', true, 1])) {
return true;
}

if (((int) ini_get('opcache.jit')) !== 1205) {
return true;
}

if (((int) ini_get('opcache.jit')) === 0) {
return true;
}
}

return $default || $this->required;
Expand All @@ -79,26 +79,27 @@ protected function restart(array $command): void

file_put_contents($this->tmpIni, $content);
}

$additional_options = [];

// executed in the parent process (before restart)
// if it wasn't loaded then we apparently don't have opcache installed and there's no point trying
// to tweak it
// If we're running on 7.4 there's no JIT available
if (PHP_VERSION_ID >= 8_00_00 && (extension_loaded('opcache') || extension_loaded('Zend OPcache'))) {
$additional_options = [
'-dopcache.enable_cli=true',
'-dopcache.jit_buffer_size=512M',
'-dopcache.jit=1205',
];
}

array_splice(
$command,
1,
0,
[
'-dopcache.enable_cli=true',
'-dopcache.jit_buffer_size=512M',
'-dopcache.jit=1205',
],
$additional_options,
);
if (!function_exists('opcache_get_status')) {
array_splice(
$command,
1,
0,
[
'-dzend_extension=opcache',
],
);
}

parent::restart($command);
}
Expand Down

0 comments on commit 3b89105

Please sign in to comment.