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 5 cache is unstable #8874

Closed
jack-worman opened this issue Dec 9, 2022 · 8 comments · Fixed by #8883
Closed

Psalm 5 cache is unstable #8874

jack-worman opened this issue Dec 9, 2022 · 8 comments · Fixed by #8883

Comments

@jack-worman
Copy link
Contributor

The follow has been frustrating:

  1. Clear psalm cache
  2. Run psalm and get no errors
  3. Do any change (even adding a blank line)
  4. Run psalm and get errors in totally unrelated files. Seems like mostly unused errors: UnusedProperty, PossiblyUnusedMethod, PossiblyUnusedProperty
@jack-worman jack-worman changed the title Psalm 5 cache seems unstable Psalm 5 cache is unstable Dec 9, 2022
@weirdan
Copy link
Collaborator

weirdan commented Dec 10, 2022

@kkmuffme you've done a lot of work on caching lately, perhaps this may interest you.

@kkmuffme
Copy link
Contributor

Please create a reproduction repo

I can't reproduce this issue in our environment atm

@jack-worman
Copy link
Contributor Author

Trying to work on a reproduction repo, but seems hard to reproduce.

But something I just noticed, all the issues it is reporting are in the baseline. So something about using the cache causes the baselined issues to not be ignored.

@weirdan
Copy link
Collaborator

weirdan commented Dec 10, 2022

I did see a similar issue in Psalm's own codebase.

@weirdan
Copy link
Collaborator

weirdan commented Dec 10, 2022

> ./psalm  # run with a cache, no files changed
Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer)
Scanning files...
Analyzing files...



------------------------------

       No errors found!

------------------------------
217 other issues found.
You can display them with --show-info=true
------------------------------

Checks took 0.13 seconds and used 68.385MB of memory
No files analyzed
Psalm was able to infer types for 99.8722% of the codebase

> vim src/Psalm/Config.php # edit the file - I just added a bunch of empty lines in `use` block

> ./psalm  # run Psalm again
Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer)
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 263 (22%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 263 (45%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 263 (68%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 240 / 263 (91%)
░░░░░░░░░░░░░░░░░░░░░░░

ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:86:12 - Cannot find any references to property Psalm\Type\MutableUnion::$initialized_class (see https://psalm.dev/149)
    public $initialized_class;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:98:12 - Cannot find any references to property Psalm\Type\MutableUnion::$failed_reconciliation (see https://psalm.dev/149)
    public $failed_reconciliation = false;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:157:12 - Cannot find any references to property Psalm\Type\MutableUnion::$from_template_default (see https://psalm.dev/149)
    public $from_template_default = false;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:186:12 - Cannot find any references to property Psalm\Type\MutableUnion::$by_ref (see https://psalm.dev/149)
    public $by_ref = false;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:191:12 - Cannot find any references to property Psalm\Type\MutableUnion::$reference_free (see https://psalm.dev/149)
    public $reference_free = false;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:196:12 - Cannot find any references to property Psalm\Type\MutableUnion::$allow_mutations (see https://psalm.dev/149)
    public $allow_mutations = true;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:201:12 - Cannot find any references to property Psalm\Type\MutableUnion::$has_mutations (see https://psalm.dev/149)
    public $has_mutations = true;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/Union.php:132:12 - Cannot find any references to property Psalm\Type\Union::$ignore_isset (see https://psalm.dev/149)
    public $ignore_isset = false;


------------------------------
8 errors found
------------------------------
217 other issues found.
You can display them with --show-info=true
------------------------------

Checks took 4.53 seconds and used 948.602MB of memory
Psalm was able to infer types for 99.8690% of the codebase

The change I introduced was real trivial:

diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php
index ee172a430..88c831d8c 100644
--- a/src/Psalm/Config.php
+++ b/src/Psalm/Config.php
@@ -4,6 +4,15 @@ namespace Psalm;

 use Composer\Autoload\ClassLoader;
 use Composer\Semver\Constraint\Constraint;
+
+
+
+
+
+
+
+
+
 use Composer\Semver\VersionParser;
 use DOMAttr;
 use DOMDocument;

@kkmuffme
Copy link
Contributor

@weirdan so the problem is with the baseline? (I assume those errors are ignored via psalm's baseline?)

If yes, I can't help much, bc we don't use a baseline and I'm in crunch time until January

@weirdan
Copy link
Collaborator

weirdan commented Dec 11, 2022

Yes, all of those are ignored through the baseline (and it's the only occurrences of UnusedProperty we have there).

@weirdan
Copy link
Collaborator

weirdan commented Dec 11, 2022

Turns out there are no problems with the baseline itself. The Psalm emits (almost) the same error twice in this case, and baseline correctly suppresses only one occurrence:

ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:86:12 - Cannot find explicit references to property Psalm\Type\Mutabl
eUnion::$initialized_class (but did find some potential references) (see https://psalm.dev/149)
    public $initialized_class;


ERROR: PossiblyUnusedProperty - src/Psalm/Type/MutableUnion.php:86:12 - Cannot find any references to property Psalm\Type\MutableUnio
n::$initialized_class (see https://psalm.dev/149)
    public $initialized_class;

weirdan added a commit to weirdan/psalm that referenced this issue Dec 11, 2022
This also allows (Possibly)UnusedProperty to be suppressed with
`referencedProperty` attribute in psalm.xml

Fixes vimeo#8874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants