Skip to content

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

Draft
wants to merge 5 commits into
base: 6.59.x
Choose a base branch
from

Conversation

ondrejmirtes
Copy link
Contributor

No description provided.

@ondrejmirtes
Copy link
Contributor Author

Context: phpstan/phpstan#10966 (comment)

@ondrejmirtes
Copy link
Contributor Author

@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:

4469 mutations were generated:
    3397 mutants were killed
       0 mutants were configured to be ignored
      10 mutants were not covered by tests
       8 covered mutants were not detected
       7 errors were encountered
       0 syntax errors were encountered
       6 time outs were encountered
    1041 mutants required more time than configured

And PHPStan's one reports:


4469 mutations were generated:
    3312 mutants were killed
       0 mutants were configured to be ignored
      10 mutants were not covered by tests
      29 covered mutants were not detected
       7 errors were encountered
       0 syntax errors were encountered
      53 time outs were encountered
    1058 mutants required more time than configured

And why Psalm's run succeeds, but PHPStan's run fails with these similar numbers.

@ondrejmirtes ondrejmirtes force-pushed the phpstan-infection branch 3 times, most recently from 5c29dde to 93d3c26 Compare May 20, 2025 17:48
@ondrejmirtes
Copy link
Contributor Author

A nice side-effect of me optimizing PHPStan - BetterReflection is now analysed in 9 seconds instead of 28 seconds on my machine!

@kukulich kukulich force-pushed the phpstan-infection branch 3 times, most recently from b96d9b3 to b45f760 Compare May 21, 2025 07:17
@kukulich kukulich force-pushed the phpstan-infection branch from 425a6d8 to a30c338 Compare May 23, 2025 07:40
phpstan.neon Outdated
level: 6
level: 8
Copy link
Member

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

Copy link
Member

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! 👍

@@ -621,6 +622,7 @@ public function getHook(ReflectionPropertyHookType $hookType): ReflectionMethod|
/** @return array{get?: ReflectionMethod, set?: ReflectionMethod} */
public function getHooks(): array
{
// @infection-ignore-all AssignCoalesce: It's just optimization
Copy link
Member

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

Copy link
Member

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?)

@kukulich kukulich force-pushed the phpstan-infection branch from a30c338 to cf755c1 Compare May 27, 2025 21:12
@Ocramius
Copy link
Member

Before considering a merge here, beware that we'd first need upstream stability for the new dependency

@kukulich kukulich changed the base branch from 6.58.x to 6.59.x May 27, 2025 21:14
@@ -5,7 +5,8 @@
"phpstan/phpstan-phpunit": "^2.0.6",
"vimeo/psalm": "^6.11.0",
"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"
Copy link
Member

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

Copy link
Contributor Author

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.

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.

Copy link
Member

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 👍

@staabm
Copy link
Contributor

staabm commented May 29, 2025

just ran PHPStan based infection on this PR on my machine and looked at the process monitoring.
I had the impression PHPStan is running a main process and worker processes for each mutation.

grafik

My gut feeling is we maybe can speedup the overall process by not using a worker, but run the analysis in the main process per mutation to reduce process spawning overhead

@maks-rafalko
Copy link

maks-rafalko commented May 29, 2025

My gut feeling is we maybe can speedup the overall process by not using a worker, but run the analysis in the main process per mutation to reduce process spawning overhead

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 had the impression PHPStan is running a main process and worker processes for each mutation.

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?

@staabm
Copy link
Contributor

staabm commented May 29, 2025

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)

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

Successfully merging this pull request may close these issues.

5 participants