-
Notifications
You must be signed in to change notification settings - Fork 136
Try phpstan-mutant-killer-infection-runner #1505
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
base: 6.59.x
Are you sure you want to change the base?
Conversation
Context: phpstan/phpstan#10966 (comment) |
@Ocramius Can you please check the reported mutants in the PHPStan run to see whether they're valuable and whether you expect them to be killed by static analysis? What I don't get is that the Psalm run reports:
And PHPStan's one reports:
And why Psalm's run succeeds, but PHPStan's run fails with these similar numbers. |
5c29dde
to
93d3c26
Compare
A nice side-effect of me optimizing PHPStan - BetterReflection is now analysed in 9 seconds instead of 28 seconds on my machine! |
b96d9b3
to
b45f760
Compare
b45f760
to
425a6d8
Compare
425a6d8
to
a30c338
Compare
phpstan.neon
Outdated
level: 6 | ||
level: 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: we were still at level 6 :O
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also explains why PHPStan + Infection didn't catch many of the mutants before, BTW, since many mutations are still valid under level 6
! 👍
/** @return array{get?: ReflectionMethod, set?: ReflectionMethod} */ | ||
public function getHooks(): array | ||
{ | ||
// @infection-ignore-all AssignCoalesce: It's just optimization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can possibly disable the entire mutator? It will always catch optimizations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(unless there's a way to declare these optimizations at type level, perhaps?)
a30c338
to
cf755c1
Compare
Before considering a merge here, beware that we'd first need upstream stability for the new dependency |
"roave/backward-compatibility-check": "^8.13.0", | ||
"roave/infection-static-analysis-plugin": "^1.37.0" | ||
"roave/infection-static-analysis-plugin": "^1.38.0", | ||
"phpstan/mutant-killer-infection-runner": "1.0.x-dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a note here: let's get a stable (even if 0.x
) release out, before going with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not probably going to release this package, there's a bug that causes PHPStan not be called for some mutants and I don't know why. I talked to Maks at PHPers over the weekend and the official support in Infection should land very soon.
We will continue working on this, mostly for performance improvements, but there's no reason to delay the feature in Infection itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offtop:
I talked to Maks at PHPers over the weekend and the official support in Infection should land very soon.
confirm, I do my best on bringing it to Infection natively, I think by the end of the week or early next week we will have at least opened PR with draft implementation.
Unfortunately, to support static analysis, I have to prepare other things to allow proper parallelization of PHPStan processes, so some architecture changes are required on Infection side first, thus it's not quick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think by the end of the week or early next week we will have at least opened PR with draft implementation.
Just to be clear: nobody is chasing anybody :-)
What matters most is that there's a plan 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UPD: #1510
could you please explain what do you mean here? I was told by @ondrejmirtes that we only want to run PHPStan as a CLI tool, not as a PHP code calls like Psalm's plugin is done. So we have no other way than running it as another process, or did I miss something?
I'm not sure if we are on the same page on how it's currently working, but: either in this plugin, and in Infection native implementation (which is WIP) - Infection is a "process orchestrator", so it creates Mutants (temp files) and runs PHPStan against them in different processes. But seems like I misunderstand your message. Do you mean that PHPStan itself create sub-processes when it is run as a sub-process? |
Yes. In case we can assume that most of the mutations don't lead to phpstan needs to re-analyze hundreds of files, it might be faster to run multiple mutations in parallel and let phpstan run in single-process mode (we need to measure why we currently are way slower than psalm in the github action job for infection analysis) |
does anyone involved has already a idea why/where we are slow? I am not yet sure how to measure/compare it best, as the mutation testing process takes so long to run and so many processes are spawned. do we have some machinery in place to top level profile where we spent all the time? |
This can be profiled with Blackfire same way PHPStan usually is. I suspect that the need to reflect a bunch of classes each time might have a play in that. Being able to cache BetterReflection objects on disk would be awesome. But we need to measure if it's really the cause. Since both Infection and PHPStan will be using the editor mode when modifying and reanalysing files, I have great interest in making it faster, so I will eventually look into it. |
had a look at the results of both tools
I think these errors are suspicous:
looks like PHPStan is using the wrong PHPParser sources/version . I can image PHPStan might have a similar problem with BetterReflection and might not used the right sources: |
We discussed these. PHPStan already knows it's -1|positive-int. Both >= and > will eliminate -1. So both are valid code. And it's impossible to write a test against these mutants. In the future Infection might now what's going on and not generate these mutants. |
I guess you expect PHPStan to report an error for >= between -1|positive-int and 0, but it currently does not do that. |
Not sure if it helps, but just in case: I've created the first implementation of Infection with PHPStan integrated natively, here: infection/infection#2098 What is interesting - we have e2e tests, where in There are few mutant generated, so it will probably be easier to debug why it's slow. Now, with the debug logs generated ( Example of the logs generated:
Look at the elapsed time - 1.25s for 1-file "project". |
No description provided.