Skip to content

Commit f2828ac

Browse files
committed
[naga wgsl-in] Separate out convert_to_leaf_scalar.
Abstract out the body of `convert_slice_to_common_leaf_scalar`'s main loop into its own function. Code motion only, no intended change of behavior.
1 parent 0df4960 commit f2828ac

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

naga/src/front/wgsl/lower/conversion.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ impl<'source, 'temp, 'out> super::ExpressionContext<'source, 'temp, 'out> {
130130
Ok(())
131131
}
132132

133+
/// Convert `expr` to the leaf scalar type `scalar`.
134+
pub fn convert_to_leaf_scalar(
135+
&mut self,
136+
expr: &mut Handle<crate::Expression>,
137+
goal: crate::Scalar,
138+
) -> Result<(), super::Error<'source>> {
139+
let inner = super::resolve_inner!(self, *expr);
140+
// Do nothing if `inner` doesn't even have leaf scalars;
141+
// it's a type error that validation will catch.
142+
if inner.scalar() != Some(goal) {
143+
let cast = crate::Expression::As {
144+
expr: *expr,
145+
kind: goal.kind,
146+
convert: Some(goal.width),
147+
};
148+
let expr_span = self.get_expression_span(*expr);
149+
*expr = self.append_expression(cast, expr_span)?;
150+
}
151+
152+
Ok(())
153+
}
154+
133155
/// Convert all expressions in `exprs` to a common scalar type.
134156
///
135157
/// Note that the caller is responsible for making sure these
@@ -146,18 +168,7 @@ impl<'source, 'temp, 'out> super::ExpressionContext<'source, 'temp, 'out> {
146168
goal: crate::Scalar,
147169
) -> Result<(), super::Error<'source>> {
148170
for expr in exprs.iter_mut() {
149-
let inner = super::resolve_inner!(self, *expr);
150-
// Do nothing if `inner` doesn't even have leaf scalars;
151-
// it's a type error that validation will catch.
152-
if inner.scalar() != Some(goal) {
153-
let cast = crate::Expression::As {
154-
expr: *expr,
155-
kind: goal.kind,
156-
convert: Some(goal.width),
157-
};
158-
let expr_span = self.get_expression_span(*expr);
159-
*expr = self.append_expression(cast, expr_span)?;
160-
}
171+
self.convert_to_leaf_scalar(expr, goal)?;
161172
}
162173

163174
Ok(())

0 commit comments

Comments
 (0)