larastan / larastan

⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
MIT License
5.46k stars 406 forks source link

Larastan crashing PHPStan on PHP 8.1 #1036

Closed andycowan closed 2 years ago

andycowan commented 2 years ago

Description

With php 8.0

PHP 8.0.12 (cli) (built: Oct 21 2021 14:38:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.12, Copyright (c) Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
    with Zend OPcache v8.0.12, Copyright (c), by Zend Technologies
➜  mother git:(trev-projector) ✗ vendor/bin/phpstan analyze
Note: Using configuration file /Users/andrew/PS/Code/mother/phpstan.neon.
 275/275 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 [OK] No errors                                                                                                         

With php 8.1

PHP 8.1.0RC5-dev (cli) (built: Oct 21 2021 06:23:20) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
    with Zend OPcache v8.1.0RC5-dev, Copyright (c), by Zend Technologies
➜  mother git:(trev-projector) ✗ vendor/bin/phpstan analyze
Note: Using configuration file /Users/andrew/PS/Code/mother/phpstan.neon.
 275/275 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 -- ---------------------------------------------- 
     Error                                         
 -- ---------------------------------------------- 
     Some parallel worker jobs have not finished.  
 -- ---------------------------------------------- 

 [ERROR] Found 1 error

If I enable debug mode on phpstan, I get the following

➜  mother git:(trev-projector) ✗ vendor/bin/phpstan analyze --no-progress --debug
Note: Using configuration file /Users/andrew/PS/Code/mother/phpstan.neon.
/Users/andrew/PS/Code/mother/app/Mixins/FindByHashIdMixin.php

I'm fully aware that this is not enough detail to diagnose the problem, but I'm asking for help collecting whatever you need.

However, removing/excluding that file just then repeats the problem for another file.

I've tried changing the level, which made no difference, and I've tried lengthening the parallel.processTimeout parameter - again with no change.

But, if I remove the larastan include from phpstan.neon, phpstan runs to completion - albeit with a pile of errors it now finds because of laravel's magic.

szepeviktor commented 2 years ago

if I remove the larastan include from phpstan.neon, phpstan runs to completion

That is the key.

Thank you!

szepeviktor commented 2 years ago

Please consider reading https://github.com/phpstan/phpstan/discussions/5124

There may be a die in your code. Honestly I do not understand the above discussion :(

andycowan commented 2 years ago

Thanks for reply - I have a phpcs rule in place that prevents those getting into a commit.

Just checked anyway, for dd and die and can confirm none present.

szepeviktor commented 2 years ago

Have you tried running a single process?

parameters:
    parallel:
        maximumNumberOfProcesses: 1
andycowan commented 2 years ago

--debug turns off parallel processes and the result cache.

But I've tried it, just in case, and same result.

It should also print a stacktrace on an internal error...

szepeviktor commented 2 years ago

It should also print a stacktrace on an internal error...

Do you have xdebug enabled?

andycowan commented 2 years ago

Xdebug is enabled in php (as shown in the PHP version above), but phpstan automatically disables it.

Interestingly, running phpstan with xdebug on using the --xdebug option produces

Note: Using configuration file /Users/andrew/PS/Code/mother/phpstan.neon.
PHPStan crashed in the previous run probably because of excessive memory consumption.
/Users/andrew/PS/Code/mother/app/Mixins/FindByHashIdMixin.php
[1]    67754 segmentation fault  vendor/bin/phpstan analyze --no-progress --debug --xdebug

A segfault.

andycowan commented 2 years ago

Just for fun's sake - I reran that using php8.0

No error, runs to completion.

szepeviktor commented 2 years ago

How about raising memory limit? vendor/bin/phpstan analyze --no-progress --debug --xdebug --memory-limit 2G

andycowan commented 2 years ago

Yeah, that was my first attempt at solving it. No change.

➜  mother git:(trev-projector) ✗ vendor/bin/phpstan analyze --no-progress --debug --xdebug --memory-limit 2G
Note: Using configuration file /Users/andrew/PS/Code/mother/phpstan.neon.
/Users/andrew/PS/Code/mother/app/Mixins/FindByHashIdMixin.php
[1]    71179 segmentation fault  vendor/bin/phpstan analyze --no-progress --debug --xdebug --memory-limit 2G
szepeviktor commented 2 years ago

All I can think of is asking help from @ondrejmirtes

ondrejmirtes commented 2 years ago

I think it might be this: https://bugs.php.net/bug.php?id=81630 (fixed today, try to build the latest PHP commit)

Otherwise there is very little information. It'd be nice to configure your error handler (display errors?) so that we can see more.

andycowan commented 2 years ago

Hi Ondřej - thanks for joining in.

Are you referring to php's display_errors? Or is there a phpstan setting I need to tweak?

szepeviktor commented 2 years ago

Maybe Laravel's error handler.

luigel commented 2 years ago

I had the same problem with this one.

I agree with @andycowan so I just updated my php8.1 from PHP 8.1.0RC5-dev to PHP 8.1.0-dev

I think it might be this: https://bugs.php.net/bug.php?id=81630 (fixed today, try to build the latest PHP commit)

Otherwise there is very little information. It'd be nice to configure your error handler (display errors?) so that we can see more.

andycowan commented 2 years ago

Updated PHP 8.1 to the overnight (from homebrew using shimamathur/php@8.1) - note the build date

PHP 8.1.0-dev (cli) (built: Nov 18 2021 00:35:21) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
    with Zend OPcache v8.1.0-dev, Copyright (c), by Zend Technologies

phpstan now working as expected! Thanks for the help everyone