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

Result cache metadata can be different just by adding --generate-baseline #8778

Closed
schlndh opened this issue Jan 26, 2023 · 9 comments
Closed
Labels

Comments

@schlndh
Copy link

schlndh commented Jan 26, 2023

Bug report

I like to run phpstan analyse first to see the new issues and then phpstan analyse --generate-baseline, which should be almost instantaneous thanks to the result cache. However, in my setup the cache is not reused for --generate-baseline. I found out that it starts working when I swap the two includes at the beginning of my config:

includes:
    - phpstan-baseline.neon
    - other.neon # Declares a few services
parameters:
# ...
    ignoreErrors: # ...

If I have it like this and run phpstan clear-result-cache -vvv; phpstan analyse -vvv; phpstan analyse -vvv --generate-baseline I get:

Result cache not used because the metadata do not match.

I think the problem is this. Since the other.neon declares services, the order of parameters and services in the $currentMeta['projectConfig'] depends on whether the baseline is loaded or not. If it is loaded then parameters are first, otherwise services are first.

Ideally, the config keys should be sorted such that this doesn't happen.

Code snippet that reproduces the problem

Create dir/file.php (any php code will do), dir/phpstan.neon, dir/phpstan-baseline.neon and dir/other.neon.

# phpstan.neon
includes:
	- phpstan-baseline.neon
	- other.neon

parameters:
	paths:
		- .
	level: 9
# other.neon
services: []

Run phpstan clear-result-cache; phpstan analyse -vvv; phpstan analyse -vvv --generate-baseline in dir.

var_dump($cachedMeta['projectConfig']);
var_dump($currentMeta['projectConfig']);

at the end of isMetaDifferent gives me:

string(98) "{parameters: {paths: [...], level: 9}, services: []}"
string(98) "{services: [], parameters: {paths: [...], level: 9}}"

Expected output

The cache should be reused with --generate-baseline, unless something else changes.

@mergeable
Copy link

mergeable bot commented Jan 26, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@stramunin
Copy link

I think it's better to create a repository to reproduce what you want.

@ondrejmirtes
Copy link
Member

I don't think we need a reproduction. A call to ksort at the right place would fix the problem.

@stramunin
Copy link

@ondrejmirtes

I wanted to ask you about the cache, but this does not apply to this topic. Recently I had to use analysis without a cache and did not find anything about it in the help. And I know about the page https://phpstan.org/user-guide/command-line-usage#--help and what it says in the description for this option.

$ phpstan --help | grep cache

It would be better to get all the necessary and up-to-date information from the help, do you agree? I think this is not so difficult to do, if of course you are interested in it.

@ondrejmirtes
Copy link
Member

@metaliciouz Please don't hijack unrelated threads, and open a separate discussion or issue instead.

@stramunin
Copy link

Sorry, didn't think about that.

@staabm
Copy link
Contributor

staabm commented Sep 6, 2023

@schlndh thanks for the great repro steps. I was able to reproduce and sent over a fix in

in my tests the baseline generation after a successfull analysis runs considerably faster now

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2606

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants