Skip to content

Commit b5ae5ee

Browse files
committed
chore: truncate instead of resize on mul
1 parent a28576e commit b5ae5ee

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

libs/@local/hashql/mir/src/pass/analysis/size_estimation/estimate.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,18 @@ impl<T> Estimate<T> {
183183
where
184184
T: Clone,
185185
{
186-
let other_coefficients = other.coefficients();
186+
match self {
187+
Self::Constant(_) => {}
188+
Self::Affine(equation) => {
189+
equation.coefficients.truncate(other.coefficients().len());
190+
}
191+
}
187192

188-
for (index, coeff) in self.coefficients_mut().iter_mut().enumerate() {
189-
let other_coeff = other_coefficients.get(index).copied().unwrap_or(0);
193+
for (coeff, &other_coeff) in self
194+
.coefficients_mut()
195+
.iter_mut()
196+
.zip(other.coefficients().iter())
197+
{
190198
*coeff = coeff.saturating_mul(other_coeff);
191199
}
192200
}

libs/@local/hashql/mir/src/pass/analysis/size_estimation/footprint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,10 @@ mod tests {
621621
fn materialize_zeroes_trailing_coefficients() {
622622
// units depends on params 0, 1, 2; cardinality depends only on param 0.
623623
// Params 1 and 2 have implicit zero in cardinality, so the product
624-
// should zero those coefficients rather than preserving them.
624+
// should drop those coefficients rather than preserving them.
625625
// units = 0..0 + 3*p0 + 5*p1 + 7*p2
626626
// cardinality = 0..0 + 2*p0
627-
// element-wise: [3*2, 5*0, 7*0] = [6, 0, 0]
627+
// element-wise: [3*2] = [6] (trailing terms truncated)
628628
let footprint = Footprint {
629629
units: Estimate::Affine(AffineEquation {
630630
coefficients: [3, 5, 7].into_iter().collect(),
@@ -641,7 +641,7 @@ mod tests {
641641
let Estimate::Affine(eq) = &result else {
642642
panic!("expected Affine, got {result:?}");
643643
};
644-
assert_eq!(eq.coefficients.as_slice(), &[6, 0, 0]);
644+
assert_eq!(eq.coefficients.as_slice(), &[6]);
645645
assert_eq!(eq.constant, InformationRange::empty());
646646
}
647647
}

0 commit comments

Comments
 (0)