Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to amp v3 #10024

Merged
merged 13 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# See https://app.circleci.com/pipelines/github/vimeo/psalm
version: 2.1
executors:
php-74:
docker:
- image: thecodingmachine/php:7.4-v4-cli
php-80:
docker:
- image: thecodingmachine/php:8.0-v4-cli
php-81:
docker:
- image: thecodingmachine/php:8.1-v4-cli
php-82:
docker:
- image: thecodingmachine/php:8.2-v4-cli
jobs:
"Code Style Analysis":
executor: php-74
executor: php-81
steps:
- checkout

Expand Down Expand Up @@ -41,7 +38,7 @@ jobs:
command: vendor/bin/phpcs -d memory_limit=512M

phar-build:
executor: php-74
executor: php-81
steps:
- attach_workspace:
at: /home/docker/project/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
tools: composer:v2
coverage: none
env:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
tools: composer:v2
coverage: none
env:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
tools: composer:v2
coverage: none
env:
Expand Down Expand Up @@ -125,7 +125,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
ini-values: zend.assertions=1, assert.exception=1, opcache.enable_cli=1, opcache.jit=function, opcache.jit_buffer_size=512M
tools: composer:v2
coverage: none
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Upgrading from Psalm 5 to Psalm 6
## Changed

- The minimum PHP version was raised to PHP 8.1.17.

- [BC] Switched the internal representation of `list<T>` and `non-empty-list<T>` from the TList and TNonEmptyList classes to an unsealed list shape: the TList, TNonEmptyList and TCallableList classes were removed.
Nothing will change for users: the `list<T>` and `non-empty-list<T>` syntax will remain supported and its semantics unchanged.
Psalm 5 already deprecates the `TList`, `TNonEmptyList` and `TCallableList` classes: use `\Psalm\Type::getListAtomic`, `\Psalm\Type::getNonEmptyListAtomic` and `\Psalm\Type::getCallableListAtomic` to instantiate list atomics, or directly instantiate TKeyedArray objects with `is_list=true` where appropriate.
Expand All @@ -9,6 +11,8 @@

- [BC] The `TDependentListKey` type was removed and replaced with an optional property of the `TIntRange` type.

- [BC] The return type of `Psalm\Internal\LanguageServer\ProtocolWriter#write() changed from `Amp\Promise` to `void` due to the switch to Amp v3

# Upgrading from Psalm 4 to Psalm 5
## Changed

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.1.17 || ~8.2.4 || ~8.3.0",
"ext-SimpleXML": "*",
"ext-ctype": "*",
"ext-dom": "*",
Expand All @@ -24,8 +24,8 @@
"ext-mbstring": "*",
"ext-tokenizer": "*",
"composer-runtime-api": "^2",
"amphp/amp": "^2.4.2",
"amphp/byte-stream": "^1.5",
"amphp/amp": "^3",
"amphp/byte-stream": "^2",
"composer/semver": "^1.4 || ^2.0 || ^3.0",
"composer/xdebug-handler": "^2.0 || ^3.0",
"dnoegel/php-xdg-base-dir": "^0.1.1",
Expand All @@ -44,7 +44,7 @@
},
"require-dev": {
"ext-curl": "*",
"amphp/phpunit-util": "^2.0",
"amphp/phpunit-util": "^3",
"bamarni/composer-bin-plugin": "^1.4",
"brianium/paratest": "^6.9",
"mockery/mockery": "^1.5",
Expand Down
15 changes: 14 additions & 1 deletion 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@841cccd693a15da70c034a55eb05ee7ed8fdbc22">
<files psalm-version="dev-master@2e5235a0be1f106c251f69b4943ae4f027cef761">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
Expand Down Expand Up @@ -290,6 +290,19 @@
<code><![CDATA[$stmt->props[0]]]></code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/LanguageClient.php">
<InvalidArrayAccess>
<code>$config</code>
</InvalidArrayAccess>
<InvalidArrayOffset>
<code>[$config]</code>
</InvalidArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/LanguageServer.php">
<MixedAssignment>
<code>$result</code>
</MixedAssignment>
</file>
<file src="src/Psalm/Internal/MethodIdentifier.php">
<PossiblyUndefinedIntArrayOffset>
<code>$method_id_parts[1]</code>
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Algebra/FormulaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public static function getFormula(
$redefined = false;

if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
Expand Down Expand Up @@ -420,7 +419,6 @@ public static function getFormula(
$redefined = false;

if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use function assert;
use function count;
use function is_string;
use function preg_replace;
use function strpos;
use function strtolower;
Expand Down Expand Up @@ -244,7 +243,7 @@ public static function getIdentifierParts(string $identifier): array
while (($pos = strpos($identifier, "\\")) !== false) {
if ($pos > 0) {
$part = substr($identifier, 0, $pos);
assert(is_string($part) && $part !== "");
assert($part !== "");
$parts[] = $part;
}
$parts[] = "\\";
Expand All @@ -253,13 +252,13 @@ public static function getIdentifierParts(string $identifier): array
if (($pos = strpos($identifier, "::")) !== false) {
if ($pos > 0) {
$part = substr($identifier, 0, $pos);
assert(is_string($part) && $part !== "");
assert($part !== "");
$parts[] = $part;
}
$parts[] = "::";
$identifier = substr($identifier, $pos + 2);
}
if ($identifier !== "" && $identifier !== false) {
if ($identifier !== "") {
$parts[] = $identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ public static function analyze(
}

if ($literal_concat) {
// Bypass opcache bug: https://github.com/php/php-src/issues/10635
(function (int $_): void {
})($combinations);
if (count($result_type_parts) === 0) {
throw new AssertionError("The number of parts cannot be 0!");
}
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Codebase/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ public static function getPsalmTypeFromReflectionType(?ReflectionType $reflectio
if ($reflection_type instanceof ReflectionNamedType) {
$type = $reflection_type->getName();
} elseif ($reflection_type instanceof ReflectionUnionType) {
/** @psalm-suppress MixedArgument */
$type = implode(
'|',
array_map(
Expand Down
5 changes: 2 additions & 3 deletions src/Psalm/Internal/LanguageServer/Client/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Psalm\Internal\LanguageServer\Client;

use Amp\Promise;
use JsonMapper;
use Psalm\Internal\LanguageServer\ClientHandler;
use Psalm\Internal\LanguageServer\LanguageServer;
Expand Down Expand Up @@ -42,11 +41,11 @@ public function __construct(ClientHandler $handler, JsonMapper $mapper, Language
* @param string $section The configuration section asked for.
* @param string|null $scopeUri The scope to get the configuration section for.
*/
public function requestConfiguration(string $section, ?string $scopeUri = null): Promise
public function requestConfiguration(string $section, ?string $scopeUri = null): object
{
$this->server->logDebug("workspace/configuration");

/** @var Promise<object> */
/** @var object */
return $this->handler->request('workspace/configuration', [
'items' => [
[
Expand Down
27 changes: 8 additions & 19 deletions src/Psalm/Internal/LanguageServer/ClientHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
use AdvancedJsonRpc\Request;
use AdvancedJsonRpc\Response;
use AdvancedJsonRpc\SuccessResponse;
use Amp\Deferred;
use Amp\Promise;
use Generator;

use function Amp\call;
use Amp\DeferredFuture;

/**
* @internal
Expand All @@ -37,24 +33,19 @@ public function __construct(ProtocolReader $protocolReader, ProtocolWriter $prot
*
* @param string $method The method to call
* @param array|object $params The method parameters
* @return Promise<mixed> Resolved with the result of the request or rejected with an error
* @return mixed Resolved with the result of the request or rejected with an error
*/
public function request(string $method, $params): Promise
public function request(string $method, $params)
{
$id = $this->idGenerator->generate();

return call(
/**
* @return Generator<int, Promise, mixed, Promise<mixed>>
*/
function () use ($id, $method, $params): Generator {
yield $this->protocolWriter->write(
$this->protocolWriter->write(
new Message(
new Request($id, $method, (object) $params),
),
);

$deferred = new Deferred();
$deferred = new DeferredFuture();

$listener =
function (Message $msg) use ($id, $deferred, &$listener): void {
Expand All @@ -69,17 +60,15 @@ function (Message $msg) use ($id, $deferred, &$listener): void {
// Received a response
$this->protocolReader->removeListener('message', $listener);
if (SuccessResponse::isSuccessResponse($msg->body)) {
$deferred->resolve($msg->body->result);
$deferred->complete($msg->body->result);
} else {
$deferred->fail($msg->body->error);
$deferred->error($msg->body->error);
}
}
};
$this->protocolReader->on('message', $listener);

return $deferred->promise();
},
);
return $deferred->getFuture()->await();
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/Psalm/Internal/LanguageServer/LanguageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Psalm\Internal\LanguageServer\Client\Progress\ProgressInterface;
use Psalm\Internal\LanguageServer\Client\TextDocument as ClientTextDocument;
use Psalm\Internal\LanguageServer\Client\Workspace as ClientWorkspace;
use Revolt\EventLoop;
use Throwable;

use function is_null;
use function json_decode;
Expand Down Expand Up @@ -68,13 +70,13 @@ public function refreshConfiguration(): void
{
$capabilities = $this->server->clientCapabilities;
if ($capabilities->workspace->configuration ?? false) {
$this->workspace->requestConfiguration('psalm')->onResolve(function ($error, $value): void {
if ($error) {
$this->server->logError('There was an error getting configuration');
} else {
/** @var array<int, object> $value */
[$config] = $value;
EventLoop::queue(function (): void {
try {
/** @var object $config */
[$config] = $this->workspace->requestConfiguration('psalm');
$this->configurationRefreshed((array) $config);
} catch (Throwable) {
$this->server->logError('There was an error getting configuration');
}
});
}
Expand Down
Loading
Loading