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

psalm fails to analyze PSL when using 3..14, or 16 threads. #9185

Closed
azjezz opened this issue Jan 25, 2023 · 5 comments
Closed

psalm fails to analyze PSL when using 3..14, or 16 threads. #9185

azjezz opened this issue Jan 25, 2023 · 5 comments
Labels
hard problems Problems without an obvious easy solution

Comments

@azjezz
Copy link
Contributor

azjezz commented Jan 25, 2023

configuring psalm to use 1, 2, 15, or 17+ threads, PSL analysis passes with no issues, when configured with 3 threads or more ( up to 14 ), or 16 threads, it fails:

using --threads=1 or --threads=2:

azjezz@lua:~/Projects/php-standard-library (next) $ ./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=1
Target PHP version: 8.1 (set by config file) Extensions enabled:  (unsupported extensions: )
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 757 (7%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 757 (15%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 757 (23%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 757 (31%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 300 / 757 (39%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 360 / 757 (47%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 420 / 757 (55%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 480 / 757 (63%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 540 / 757 (71%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 600 / 757 (79%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 660 / 757 (87%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 720 / 757 (95%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
------------------------------

       No errors found!

------------------------------
Psalm can automatically fix 6 issues.
Run Psalm again with
--alter --issues=MissingParamType --dry-run
to see what it can fix.
------------------------------

Checks took 6.89 seconds and used 268.255MB of memory
Psalm was able to infer types for 99.9034% of the codebase
azjezz@lua:~/Projects/php-standard-library (next) $

using --threads=3:

azjezz@lua:~/Projects/php-standard-library (next) $ ./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=3
Target PHP version: 8.1 (set by config file) Extensions enabled:  (unsupported extensions: )
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 757 (7%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 757 (15%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 757 (23%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 757 (31%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 300 / 757 (39%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 360 / 757 (47%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 420 / 757 (55%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 480 / 757 (63%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 540 / 757 (71%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 600 / 757 (79%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 660 / 757 (87%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 720 / 757 (95%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

ERROR: MoreSpecificReturnType - ../src/Psl/Filesystem/create_temporary_file.php:24:12 - The declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file is more specific than the inferred return type 'string' (see https://psalm.dev/070)
 * @return non-empty-string The absolute path to the temporary file.


ERROR: MixedAssignment - ../src/Psl/Filesystem/create_temporary_file.php:37:5 - Unable to determine the type that $separator is being assigned to (see https://psalm.dev/032)
    $separator = namespace\SEPARATOR;


ERROR: MixedArgument - ../src/Psl/Filesystem/create_temporary_file.php:40:35 - Argument 2 of Psl\Str\contains cannot be mixed, expecting string (see https://psalm.dev/030)
        if (Str\contains($prefix, $separator)) {

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: MixedOperand - ../src/Psl/Filesystem/create_temporary_file.php:49:34 - Right operand cannot be mixed (see https://psalm.dev/059)
        $filename = $directory . $separator . $prefix . SecureRandom\string(8);

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: ArgumentTypeCoercion - ../src/Psl/Filesystem/create_temporary_file.php:56:17 - Argument 1 of Psl\Filesystem\create_file expects non-empty-string, but parent type string provided (see https://psalm.dev/193)
    create_file($filename);


ERROR: LessSpecificReturnStatement - ../src/Psl/Filesystem/create_temporary_file.php:58:12 - The type 'string' is more general than the declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file (see https://psalm.dev/129)
    return $filename;


------------------------------
6 errors found
------------------------------
Psalm can automatically fix 6 issues.
Run Psalm again with
--alter --issues=MissingParamType --dry-run
to see what it can fix.
------------------------------

Checks took 4.95 seconds and used 264.972MB of memory
Psalm was able to infer types for 99.8712% of the codebase
azjezz@lua:~/Projects/php-standard-library (next) $                                                                                                                                                            

using --threads=14:

azjezz@lua:~/Projects/php-standard-library (next) $ ./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=14
Target PHP version: 8.1 (set by config file) Extensions enabled:  (unsupported extensions: )
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 757 (7%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 757 (15%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 757 (23%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 757 (31%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 300 / 757 (39%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 360 / 757 (47%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 420 / 757 (55%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 480 / 757 (63%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 540 / 757 (71%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 600 / 757 (79%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 660 / 757 (87%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 720 / 757 (95%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

ERROR: MoreSpecificReturnType - ../src/Psl/Filesystem/create_temporary_file.php:24:12 - The declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file is more specific than the inferred return type 'string' (see https://psalm.dev/070)
 * @return non-empty-string The absolute path to the temporary file.


ERROR: MixedAssignment - ../src/Psl/Filesystem/create_temporary_file.php:37:5 - Unable to determine the type that $separator is being assigned to (see https://psalm.dev/032)
    $separator = namespace\SEPARATOR;


ERROR: MixedArgument - ../src/Psl/Filesystem/create_temporary_file.php:40:35 - Argument 2 of Psl\Str\contains cannot be mixed, expecting string (see https://psalm.dev/030)
        if (Str\contains($prefix, $separator)) {

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: MixedOperand - ../src/Psl/Filesystem/create_temporary_file.php:49:34 - Right operand cannot be mixed (see https://psalm.dev/059)
        $filename = $directory . $separator . $prefix . SecureRandom\string(8);

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: ArgumentTypeCoercion - ../src/Psl/Filesystem/create_temporary_file.php:56:17 - Argument 1 of Psl\Filesystem\create_file expects non-empty-string, but parent type string provided (see https://psalm.dev/193)
    create_file($filename);


ERROR: LessSpecificReturnStatement - ../src/Psl/Filesystem/create_temporary_file.php:58:12 - The type 'string' is more general than the declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file (see https://psalm.dev/129)
    return $filename;


------------------------------
6 errors found
------------------------------
Psalm can automatically fix 6 issues.
Run Psalm again with
--alter --issues=MissingParamType --dry-run
to see what it can fix.
------------------------------

Checks took 4.99 seconds and used 271.255MB of memory
Psalm was able to infer types for 99.8712% of the codebase
azjezz@lua:~/Projects/php-standard-library (next) $                                                                                                                                                            

using --threads=15:

azjezz@lua:~/Projects/php-standard-library (next) $ ./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=15
Target PHP version: 8.1 (set by config file) Extensions enabled:  (unsupported extensions: )
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 757 (7%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 757 (15%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 757 (23%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 757 (31%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 300 / 757 (39%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 360 / 757 (47%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 420 / 757 (55%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 480 / 757 (63%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 540 / 757 (71%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 600 / 757 (79%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 660 / 757 (87%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 720 / 757 (95%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
------------------------------

       No errors found!

------------------------------
Psalm can automatically fix 6 issues.
Run Psalm again with
--alter --issues=MissingParamType --dry-run
to see what it can fix.
------------------------------

Checks took 5.49 seconds and used 271.812MB of memory
Psalm was able to infer types for 99.9034% of the codebase
azjezz@lua:~/Projects/php-standard-library (next) $

using --threads=16:

azjezz@lua:~/Projects/php-standard-library (next) $ ./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=16                                                                            2
Target PHP version: 8.1 (set by config file) Extensions enabled:  (unsupported extensions: )
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 757 (7%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 757 (15%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 757 (23%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 757 (31%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 300 / 757 (39%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 360 / 757 (47%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 420 / 757 (55%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 480 / 757 (63%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 540 / 757 (71%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 600 / 757 (79%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 660 / 757 (87%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 720 / 757 (95%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

ERROR: MoreSpecificReturnType - ../src/Psl/Filesystem/create_temporary_file.php:24:12 - The declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file is more specific than the inferred return type 'string' (see https://psalm.dev/070)
 * @return non-empty-string The absolute path to the temporary file.


ERROR: MixedAssignment - ../src/Psl/Filesystem/create_temporary_file.php:37:5 - Unable to determine the type that $separator is being assigned to (see https://psalm.dev/032)
    $separator = namespace\SEPARATOR;


ERROR: MixedArgument - ../src/Psl/Filesystem/create_temporary_file.php:40:35 - Argument 2 of Psl\Str\contains cannot be mixed, expecting string (see https://psalm.dev/030)
        if (Str\contains($prefix, $separator)) {

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: MixedOperand - ../src/Psl/Filesystem/create_temporary_file.php:49:34 - Right operand cannot be mixed (see https://psalm.dev/059)
        $filename = $directory . $separator . $prefix . SecureRandom\string(8);

  The type of $separator is sourced from here - ../src/Psl/Filesystem/create_temporary_file.php:37:5
    $separator = namespace\SEPARATOR;



ERROR: ArgumentTypeCoercion - ../src/Psl/Filesystem/create_temporary_file.php:56:17 - Argument 1 of Psl\Filesystem\create_file expects non-empty-string, but parent type string provided (see https://psalm.dev/193)
    create_file($filename);


ERROR: LessSpecificReturnStatement - ../src/Psl/Filesystem/create_temporary_file.php:58:12 - The type 'string' is more general than the declared return type 'non-empty-string' for Psl\Filesystem\create_temporary_file (see https://psalm.dev/129)
    return $filename;


------------------------------
6 errors found
------------------------------
Psalm can automatically fix 6 issues.
Run Psalm again with
--alter --issues=MissingParamType --dry-run
to see what it can fix.
------------------------------

Checks took 5.06 seconds and used 272.085MB of memory
Psalm was able to infer types for 99.8712% of the codebase
@psalm-github-bot
Copy link

Hey @azjezz, can you reproduce the issue on https://psalm.dev ?

@weirdan
Copy link
Collaborator

weirdan commented Jan 25, 2023

@azjezz can you make sure the PSL commit you're running this on is accessible somewhere?

@azjezz
Copy link
Contributor Author

azjezz commented Jan 25, 2023

this has been happening for a long period, but thanks to @veewee we discovered that it's related to thread configuration last night.

You can replicate this behavior in the latest commit of PSL ( azjezz/psl@33496f6 ), to get the result above, i used Psalm 5.2.0@fb685a16df3050d4c18d8a4100fe83abe6458cba, however, as mentioned, you should be able to replicate this will all 5.x psalm versions, and the latest few 4.x versions as well, also across all PSL versions from 1.9.x.

azjezz added a commit to azjezz/psl that referenced this issue Jul 19, 2023
ref: vimeo/psalm#9185
Signed-off-by: azjezz <azjezz@protonmail.com>
@etremblay
Copy link

etremblay commented Jan 31, 2024

Hi,

Is there anything we can do to help with the resolution of this issue and #9083

We have relatively big application with ~10 000 PHP files (1 400 000 LOC) and this issue have been impacting our team for years. It's a 20 year old codebase with ~1500 files still in the baseline.

I'll be more than happy to provide you more information to help diagnose this problem.

The only way to make it work consistantly is with :

./vendor/bin/psalm --no-diff --no-cache --threads=15

We reproduce with php 8.1 and 8.3 on Mac M1 and Linux.

@weirdan weirdan added the hard problems Problems without an obvious easy solution label Feb 1, 2024
@etremblay
Copy link

Hi,

I'm very happy to confirm that the release of psalm 6.x fix this issue for us.

Great job on this awesome tool 🎉

@danog danog closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hard problems Problems without an obvious easy solution
Projects
None yet
Development

No branches or pull requests

4 participants