Skip to content

Commit

Permalink
Calculate upper bound ahead of time
Browse files Browse the repository at this point in the history
This prevents generating large numbers of clauses we'll have to ignore anyway
  • Loading branch information
muglug committed Mar 14, 2022
1 parent 77f47ed commit e578413
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Psalm/Internal/Algebra.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,21 @@ public static function groupImpossibilities(array $clauses): array
return $seed_clauses;
}

$complexity_upper_bound = count($seed_clauses);

foreach ($clauses as $clause) {
$i = 0;
foreach ($clause->possibilities as $p) {
$i += count($p);
}

$complexity_upper_bound *= $i;

if ($complexity_upper_bound > 20_000) {
throw new ComplicatedExpressionException();
}
}

while ($clauses) {
$clause = array_pop($clauses);

Expand Down

0 comments on commit e578413

Please sign in to comment.