Skip to content

Commit cc39314

Browse files
committed
Split only shapes whose union values hold no array when accepting them
A split shape is accepted member by member, which split the arrays among its values again, so shapes nested in each other split into exponentially many shapes (nested-nullable-shape-accepts: 213M to 23.8B instructions). Scalar unions, which [$scalar] for list<A>|list<B> needs, still split. Amp-Thread-ID: https://ampcode.com/threads/T-01a21efd-7346-7575-a0dd-5474e0f5c329
1 parent a8b3d2a commit cc39314

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/Type/ArrayAlgebra.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ public static function splitConstantArrayAtFiniteValue(ConstantArrayType $array)
6767
}
6868
// unions of constant scalars, the values tryUnionConstantArray() unions at one key,
6969
// split into each value, and other unions into their members
70-
$finiteTypes = $valueType->isConstantScalarValue()->yes() ? $valueType->getFiniteTypes() : $valueType->getTypes();
70+
if ($valueType->isConstantScalarValue()->yes()) {
71+
$finiteTypes = $valueType->getFiniteTypes();
72+
} elseif ($valueType->isArray()->no()) {
73+
// a split shape is accepted member by member, which splits the
74+
// arrays among its values again: arrays nested in each other
75+
// would split into exponentially many shapes
76+
$finiteTypes = $valueType->getTypes();
77+
} else {
78+
continue;
79+
}
7180
if (count($finiteTypes) < 2) {
7281
continue;
7382
}

0 commit comments

Comments
 (0)