1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Simplify simplification

This commit is contained in:
Brown 2020-08-26 16:41:40 -04:00 committed by Daniil Gentili
parent a0a30c500c
commit 317131b524
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 17 additions and 22 deletions

View File

@ -192,11 +192,15 @@ class Clause
);
}
public function removePossibilities(string $var_id) : self
public function removePossibilities(string $var_id) : ?self
{
$possibilities = $this->possibilities;
unset($possibilities[$var_id]);
if (!$possibilities) {
return null;
}
return new self(
$possibilities,
$this->creating_conditional_id,

View File

@ -471,41 +471,32 @@ class Algebra
)
);
unset($cloned_clauses[$clause_hash]);
if (!$clause_var_possibilities) {
$cloned_clauses[$clause_hash] = $clause_b->removePossibilities($clause_var);
$updated_clause = $clause_b->removePossibilities($clause_var);
if ($updated_clause) {
$cloned_clauses[$updated_clause->hash] = $updated_clause;
}
} else {
$cloned_clauses[$clause_hash] = $clause_b->addPossibilities(
$updated_clause = $clause_b->addPossibilities(
$clause_var,
$clause_var_possibilities
);
$cloned_clauses[$updated_clause->hash] = $updated_clause;
}
}
}
}
$deduped_clauses = [];
// avoid strict duplicates
foreach ($cloned_clauses as $clause) {
$deduped_clauses[$clause->hash] = clone $clause;
}
$deduped_clauses = array_filter(
$deduped_clauses,
/**
* @return bool
*/
function (Clause $clause) {
return count($clause->possibilities) || $clause->wedge;
}
);
$simplified_clauses = [];
foreach ($deduped_clauses as $clause_a) {
foreach ($cloned_clauses as $clause_a) {
$is_redundant = false;
foreach ($deduped_clauses as $clause_b) {
foreach ($cloned_clauses as $clause_b) {
if ($clause_a === $clause_b
|| !$clause_b->reconcilable
|| $clause_b->wedge