mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Simplify simplification
This commit is contained in:
parent
a0a30c500c
commit
317131b524
@ -192,11 +192,15 @@ class Clause
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removePossibilities(string $var_id) : self
|
public function removePossibilities(string $var_id) : ?self
|
||||||
{
|
{
|
||||||
$possibilities = $this->possibilities;
|
$possibilities = $this->possibilities;
|
||||||
unset($possibilities[$var_id]);
|
unset($possibilities[$var_id]);
|
||||||
|
|
||||||
|
if (!$possibilities) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return new self(
|
return new self(
|
||||||
$possibilities,
|
$possibilities,
|
||||||
$this->creating_conditional_id,
|
$this->creating_conditional_id,
|
||||||
|
@ -471,41 +471,32 @@ class Algebra
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
unset($cloned_clauses[$clause_hash]);
|
||||||
|
|
||||||
if (!$clause_var_possibilities) {
|
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 {
|
} else {
|
||||||
$cloned_clauses[$clause_hash] = $clause_b->addPossibilities(
|
$updated_clause = $clause_b->addPossibilities(
|
||||||
$clause_var,
|
$clause_var,
|
||||||
$clause_var_possibilities
|
$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 = [];
|
$simplified_clauses = [];
|
||||||
|
|
||||||
foreach ($deduped_clauses as $clause_a) {
|
foreach ($cloned_clauses as $clause_a) {
|
||||||
$is_redundant = false;
|
$is_redundant = false;
|
||||||
|
|
||||||
foreach ($deduped_clauses as $clause_b) {
|
foreach ($cloned_clauses as $clause_b) {
|
||||||
if ($clause_a === $clause_b
|
if ($clause_a === $clause_b
|
||||||
|| !$clause_b->reconcilable
|
|| !$clause_b->reconcilable
|
||||||
|| $clause_b->wedge
|
|| $clause_b->wedge
|
||||||
|
Loading…
Reference in New Issue
Block a user