Skip to content

Commit b2dca02

Browse files
committed
update all (i32, i32) arithmetic operations to use wrapping_ instead of checked_
1 parent d12e65f commit b2dca02

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
157157
- Show types of LHS and RHS in binary operation type mismatch errors. By @ErichDonGubler in [#6450](https://github.com/gfx-rs/wgpu/pull/6450).
158158
- The GLSL parser now uses less expressions for function calls. By @magcius in [#6604](https://github.com/gfx-rs/wgpu/pull/6604).
159159
- Add a note to help with a common syntax error case for global diagnostic filter directives. By @e-hat in [#6718](https://github.com/gfx-rs/wgpu/pull/6718)
160-
- Change multiplication between two i32 variables to wrap on overflow to match WGSL spec. By @matthew-wong1 in [#6835](https://github.com/gfx-rs/wgpu/pull/6835).
160+
- Change arithmetic operations between two i32 variables to wrap on overflow to match WGSL spec. By @matthew-wong1 in [#6835](https://github.com/gfx-rs/wgpu/pull/6835).
161161

162162
#### General
163163

naga/src/proc/constant_evaluator.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,27 +1808,23 @@ impl<'a> ConstantEvaluator<'a> {
18081808

18091809
_ => match (left_value, right_value) {
18101810
(Literal::I32(a), Literal::I32(b)) => Literal::I32(match op {
1811-
BinaryOperator::Add => a.checked_add(b).ok_or_else(|| {
1812-
ConstantEvaluatorError::Overflow("addition".into())
1813-
})?,
1814-
BinaryOperator::Subtract => a.checked_sub(b).ok_or_else(|| {
1815-
ConstantEvaluatorError::Overflow("subtraction".into())
1816-
})?,
1811+
BinaryOperator::Add => a.wrapping_add(b),
1812+
BinaryOperator::Subtract => a.wrapping_sub(b),
18171813
BinaryOperator::Multiply => a.wrapping_mul(b),
1818-
BinaryOperator::Divide => a.checked_div(b).ok_or_else(|| {
1814+
BinaryOperator::Divide => {
18191815
if b == 0 {
1820-
ConstantEvaluatorError::DivisionByZero
1816+
return Err(ConstantEvaluatorError::DivisionByZero);
18211817
} else {
1822-
ConstantEvaluatorError::Overflow("division".into())
1818+
a.wrapping_div(b)
18231819
}
1824-
})?,
1825-
BinaryOperator::Modulo => a.checked_rem(b).ok_or_else(|| {
1820+
}
1821+
BinaryOperator::Modulo => {
18261822
if b == 0 {
1827-
ConstantEvaluatorError::RemainderByZero
1823+
return Err(ConstantEvaluatorError::RemainderByZero);
18281824
} else {
1829-
ConstantEvaluatorError::Overflow("remainder".into())
1825+
a.wrapping_rem(b)
18301826
}
1831-
})?,
1827+
}
18321828
BinaryOperator::And => a & b,
18331829
BinaryOperator::ExclusiveOr => a ^ b,
18341830
BinaryOperator::InclusiveOr => a | b,

0 commit comments

Comments
 (0)