Skip to content

RegexArrayShapeMatcher - turn more details immutable #3892

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

Merged
merged 6 commits into from
Mar 21, 2025

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Mar 21, 2025

goal: more immutability so we can in the end re-use hoa/ast parse results instead of regex lexing/parsing the same regex over and over (which shows up in perf profiles).

this also paves the way for phpstan/phpstan#12749 for which we need the group list to infer a more precise subject-type result

Comment on lines -118 to -127
$trailingOptionals = 0;
foreach (array_reverse($groupList) as $captureGroup) {
if (!$captureGroup->isOptional()) {
break;
}
$trailingOptionals++;
}

$onlyOptionalTopLevelGroup = $this->getOnlyOptionalTopLevelGroup($groupList);
$onlyTopLevelAlternation = $this->getOnlyTopLevelAlternation($groupList);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move operations previously did on array<int, RegexCapturingGroup> $captureGroups into a dedicated class

@@ -154,12 +146,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
);
}

$onlyOptionalTopLevelGroup->clearOverrides();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more state clearing/handling

Comment on lines -203 to -206
foreach ($groupCombo as $groupId) {
$group = $comboList[$groupId];
$group->clearOverrides();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more state clearing/handling

@staabm staabm marked this pull request as ready for review March 21, 2025 09:41
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 12a0b4e into phpstan:2.1.x Mar 21, 2025
416 of 418 checks passed
@ondrejmirtes
Copy link
Member

Awesome, thank you!"

@staabm staabm deleted the readonly branch March 21, 2025 13:35
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.

3 participants