Skip to content

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

);
}

$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