Skip to content
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
74 changes: 41 additions & 33 deletions .github/workflows/phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,34 @@
if: matrix.target.family == 'zts'
run: "php -r 'exit((bool) PHP_ZTS ? 0 : 1);'"

- name: "Compile phpstan_turbo with strict warnings"
# The training run of `make pgo` (bin/pgo-train.sh) runs bin/phpstan on
# the checkout, so the dependencies must be in place before the build.
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
if: matrix.target.family == 'macos'
with:
ignore-cache: true

- name: "Install Composer dependencies (pinned composer)"
if: matrix.target.family != 'macos'
# checksum-pinned composer, run under the matrix PHP so platform
# requirements are validated against the interpreter the tests below
# run on. COMPOSER_HOME is isolated: on the runner (ZTS) legs,
# setup-php seeds ~/.composer/auth.json with the workflow's GitHub
# token, which this pinned composer rejects at startup ("github oauth
# token contains invalid characters") — everything here comes from
# packagist dists, no auth needed.
run: |
curl -fsSLo composer.phar "https://getcomposer.org/download/$COMPOSER_VERSION/composer.phar"
echo "$COMPOSER_PHAR_SHA256 composer.phar" | sha256sum -c -
COMPOSER_HOME="$(mktemp -d)" php composer.phar install --no-interaction --no-progress
rm composer.phar

- name: "Compile phpstan_turbo with strict warnings (profile-guided)"
working-directory: "turbo-ext"
# `make pgo`: an instrumented build, a training run of PHPStan over
# its own sources with that build loaded, then the final build using
# the recorded profile — the same three stages `make pgo` runs
# locally, so a profile-guided binary can be reproduced outside CI.
# Exemptions, each caused by third-party macro expansions, not our code:
# -Wno-assume: zend's parameter-parsing macros expand __builtin_assume
# with (potential) side effects
Expand All @@ -467,7 +493,7 @@
# clang lexes the \N in "PhpParser\NodeVisitor" as a universal
# character name (GCC ignores the unknown -Wno- flag)
run: |
make WARN_FLAGS="-Wall -Wextra -Werror -Wno-assume -Wno-unused-parameter -Wno-unicode" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
make pgo WARN_FLAGS="-Wall -Wextra -Werror -Wno-assume -Wno-unused-parameter -Wno-unicode" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"

# On arm64 AMFI refuses to map unsigned code, so the binary must carry
# at least an ad-hoc signature. The linker applies one itself, but
Expand All @@ -489,26 +515,6 @@
echo "built extension reports: $REPORTED, enabler expects: $EXPECTED"
[ "$REPORTED" = "$EXPECTED" ]

- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
if: matrix.target.family == 'macos'
with:
ignore-cache: true

- name: "Install Composer dependencies (pinned composer)"
if: matrix.target.family != 'macos'
# checksum-pinned composer, run under the matrix PHP so platform
# requirements are validated against the interpreter the tests below
# run on. COMPOSER_HOME is isolated: on the runner (ZTS) legs,
# setup-php seeds ~/.composer/auth.json with the workflow's GitHub
# token, which this pinned composer rejects at startup ("github oauth
# token contains invalid characters") — everything here comes from
# packagist dists, no auth needed.
run: |
curl -fsSLo composer.phar "https://getcomposer.org/download/$COMPOSER_VERSION/composer.phar"
echo "$COMPOSER_PHAR_SHA256 composer.phar" | sha256sum -c -
COMPOSER_HOME="$(mktemp -d)" php composer.phar install --no-interaction --no-progress
rm composer.phar

- name: "Smoke test (differential: native vs PHP implementations)"
run: php -d extension="$PWD/turbo-ext/phpstan_turbo.so" turbo-ext/tests/smoke.php

Expand Down Expand Up @@ -609,10 +615,21 @@
- name: "Trust the checkout despite the container/host uid mismatch"
run: docker exec alpine-build git config --global --add safe.directory /work

- name: "Compile phpstan_turbo with strict warnings"
# The training run of `make pgo` runs bin/phpstan on the checkout, so
# the dependencies must be in place before the build.
- name: "Install Composer dependencies (pinned composer)"
run: |
docker exec -i alpine-build sh -e <<'EOF'
curl -fsSLo composer.phar "https://getcomposer.org/download/$COMPOSER_VERSION/composer.phar"
echo "$COMPOSER_PHAR_SHA256 composer.phar" | sha256sum -c -
COMPOSER_HOME="$(mktemp -d)" php composer.phar install --no-interaction --no-progress
rm composer.phar
EOF

- name: "Compile phpstan_turbo with strict warnings (profile-guided)"
run: |
docker exec -i -w /work/turbo-ext alpine-build sh -e <<'EOF'
make WARN_FLAGS="-Wall -Wextra -Werror -Wno-assume -Wno-unused-parameter -Wno-unicode" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
make pgo WARN_FLAGS="-Wall -Wextra -Werror -Wno-assume -Wno-unused-parameter -Wno-unicode" -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
EOF

- name: "Verify the built extension reports the expected version"
Expand All @@ -624,15 +641,6 @@
[ "$REPORTED" = "$EXPECTED" ]
EOF

- name: "Install Composer dependencies (pinned composer)"
run: |
docker exec -i alpine-build sh -e <<'EOF'
curl -fsSLo composer.phar "https://getcomposer.org/download/$COMPOSER_VERSION/composer.phar"
echo "$COMPOSER_PHAR_SHA256 composer.phar" | sha256sum -c -
COMPOSER_HOME="$(mktemp -d)" php composer.phar install --no-interaction --no-progress
rm composer.phar
EOF

- name: "Smoke test (differential: native vs PHP implementations)"
run: docker exec alpine-build php -d extension=/work/turbo-ext/phpstan_turbo.so turbo-ext/tests/smoke.php

Expand Down
2 changes: 2 additions & 0 deletions build/PHPStan/Build/TurboAttributeCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PhpParser\Node\VariadicPlaceholder;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnum;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionIntersectionType;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionNamedType;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionUnionType;
Expand Down Expand Up @@ -162,6 +163,7 @@ final class TurboAttributeCollector
'offsetAccessTypeNode' => OffsetAccessTypeNode::class,
'conditionalTypeNode' => ConditionalTypeNode::class,
'conditionalTypeForParameterNode' => ConditionalTypeForParameterNode::class,
'reflectionEnum' => ReflectionEnum::class,
];

private string $realRoot;
Expand Down
2 changes: 2 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\HasOffsetValueType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
Expand Down Expand Up @@ -146,6 +147,7 @@
use const PHP_INT_MAX;
use const PHP_INT_MIN;

#[ReferencedByTurboExtension(key: 'mutatingScope')]
class MutatingScope implements Scope, NodeCallbackInvoker, CollectedDataEmitter
{

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/LruCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace PHPStan\Internal;

use PHPStan\ShouldNotHappenException;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use function array_key_exists;
use function array_key_first;
use function count;
Expand All @@ -20,7 +20,7 @@
*
* @template TValue
*/
#[ReferencedByTurboExtension(key: 'lruCache')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/LruCache.cpp')]
final class LruCache
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use PHPStan\Reflection\Php\UniversalObjectCratesClassReflectionExtension;
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
use PHPStan\ShouldNotHappenException;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\CircularTypeAliasDefinitionException;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\ErrorType;
Expand Down Expand Up @@ -82,6 +83,7 @@
* @api
*/
#[GenerateFactory(interface: ClassReflectionFactory::class)]
#[ReferencedByTurboExtension(key: 'classReflection')]
final class ClassReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/Dummy/ChangedTypeMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use PHPStan\Reflection\ExtendedParametersAcceptor;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Type;
use function count;
use function is_bool;

#[ReferencedByTurboExtension(key: 'changedTypeMethodReflection')]
final class ChangedTypeMethodReflection implements ExtendedMethodReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/Dummy/ChangedTypePropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use PHPStan\Reflection\ExtendedPropertyReflection;
use PHPStan\Reflection\WrapperPropertyReflection;
use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Type;

#[ReferencedByTurboExtension(key: 'changedTypePropertyReflection')]
final class ChangedTypePropertyReflection implements WrapperPropertyReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ExtendedFunctionVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace PHPStan\Reflection;

use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
use PHPStan\Type\Type;

/**
* @api
*/
#[ReferencedByTurboExtension(key: 'extendedFunctionVariant')]
class ExtendedFunctionVariant extends FunctionVariant implements ExtendedParametersAcceptor
{

Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/Native/NativeParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\PassedByReference;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

#[ReferencedByTurboExtension(key: 'nativeParameterReflection')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/NativeParameterReflection.cpp')]
final class NativeParameterReflection implements ParameterReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/Php/ExtendedDummyParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use PHPStan\Reflection\ParameterAllowedConstants;
use PHPStan\Reflection\PassedByReference;
use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;

#[ReferencedByTurboExtension(key: 'extendedDummyParameter')]
final class ExtendedDummyParameter extends DummyParameter implements ExtendedParameterReflection
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\NamespaceAnswerer;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Turbo\ReferencedByTurboExtension;
use function strtolower;

#[ReferencedByTurboExtension(key: 'memoizingReflectionProvider')]
final class MemoizingReflectionProvider implements ReflectionProvider
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ResolvedMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
use PHPStan\Type\Type;
use function is_bool;

#[ReferencedByTurboExtension(key: 'resolvedMethodReflection')]
final class ResolvedMethodReflection implements ExtendedMethodReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ResolvedPropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace PHPStan\Reflection;

use PHPStan\TrinaryLogic;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
use PHPStan\Type\Type;

#[ReferencedByTurboExtension(key: 'resolvedPropertyReflection')]
final class ResolvedPropertyReflection implements WrapperPropertyReflection
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use PHPStan\Reflection\ExtendedParametersAcceptor;
use PHPStan\Reflection\Php\ExtendedDummyParameter;
use PHPStan\Reflection\ResolvedMethodReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use function array_map;

#[ReferencedByTurboExtension(key: 'callbackUnresolvedMethodPrototypeReflection')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/CallbackUnresolvedMethodPrototypeReflection.cpp')]
final class CallbackUnresolvedMethodPrototypeReflection implements UnresolvedMethodPrototypeReflection
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use PHPStan\Reflection\Dummy\ChangedTypePropertyReflection;
use PHPStan\Reflection\ExtendedPropertyReflection;
use PHPStan\Reflection\ResolvedPropertyReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\Type;

#[ReferencedByTurboExtension(key: 'callbackUnresolvedPropertyPrototypeReflection')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/CallbackUnresolvedPropertyPrototypeReflection.cpp')]
final class CallbackUnresolvedPropertyPrototypeReflection implements UnresolvedPropertyPrototypeReflection
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PHPStan\Reflection\ExtendedParametersAcceptor;
use PHPStan\Reflection\Php\ExtendedDummyParameter;
use PHPStan\Reflection\ResolvedMethodReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\Generic\GenericStaticType;
use PHPStan\Type\StaticType;
use PHPStan\Type\ThisType;
Expand All @@ -19,7 +19,7 @@
use function array_map;
use function count;

#[ReferencedByTurboExtension(key: 'calledOnTypeUnresolvedMethodPrototypeReflection')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/CalledOnTypeUnresolvedMethodPrototypeReflection.cpp')]
final class CalledOnTypeUnresolvedMethodPrototypeReflection implements UnresolvedMethodPrototypeReflection
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use PHPStan\Reflection\Dummy\ChangedTypePropertyReflection;
use PHPStan\Reflection\ExtendedPropertyReflection;
use PHPStan\Reflection\ResolvedPropertyReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\StaticType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;

#[ReferencedByTurboExtension(key: 'calledOnTypeUnresolvedPropertyPrototypeReflection')]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/CalledOnTypeUnresolvedPropertyPrototypeReflection.cpp')]
final class CalledOnTypeUnresolvedPropertyPrototypeReflection implements UnresolvedPropertyPrototypeReflection
{

Expand Down
2 changes: 2 additions & 0 deletions src/Rules/PhpDoc/UnresolvableTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\Rules\PhpDoc;

use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Turbo\ShadowedByTurboExtension;
use PHPStan\Type\ErrorType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
Expand All @@ -11,6 +12,7 @@
use function array_values;

#[AutowiredService]
#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/UnresolvableTypeHelper.cpp')]
final class UnresolvableTypeHelper
{

Expand Down
3 changes: 3 additions & 0 deletions src/Rules/PhpDoc/UnresolvableTypeResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace PHPStan\Rules\PhpDoc;

use PHPStan\Turbo\ReferencedByTurboExtension;

#[ReferencedByTurboExtension(key: 'unresolvableTypeResult')]
final class UnresolvableTypeResult
{

Expand Down
2 changes: 1 addition & 1 deletion src/Turbo/TurboExtensionEnabler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
final class TurboExtensionEnabler
{

public const EXPECTED_EXTENSION_VERSION = 'cb469d0';
public const EXPECTED_EXTENSION_VERSION = '500bbe7';

private static bool $active = false;

Expand Down
5 changes: 5 additions & 0 deletions turbo-ext/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@
/src/parser/*.lo
/src/.libs/
/src/parser/.libs/

# profile-guided build artifacts (make pgo)
/pgo/
/src/*.gcda
/src/parser/*.gcda
Loading
Loading