diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 909299f65d..d821c2592f 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -526,6 +526,19 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { } } + /// Return `true` if `handle` is a constant expression. + fn is_const(&self, handle: Handle) -> bool { + use ExpressionContextType as Ect; + match self.expr_type { + Ect::Runtime(ref ctx) | Ect::Constant(Some(ref ctx)) => { + ctx.local_expression_kind_tracker.is_const(handle) + } + Ect::Constant(None) | Ect::Override => { + self.global_expression_kind_tracker.is_const(handle) + } + } + } + fn get_expression_span(&self, handle: Handle) -> Span { match self.expr_type { ExpressionContextType::Runtime(ref ctx) @@ -2262,16 +2275,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { // We only have to explicitly do so for shifts as their operands may be // of different types - for other binary ops this is achieved by finding // the conversion consensus for both operands. - let expr_kind_tracker = match ctx.expr_type { - ExpressionContextType::Runtime(ref ctx) - | ExpressionContextType::Constant(Some(ref ctx)) => { - &ctx.local_expression_kind_tracker - } - ExpressionContextType::Constant(None) | ExpressionContextType::Override => { - &ctx.global_expression_kind_tracker - } - }; - if !expr_kind_tracker.is_const(right) { + if !ctx.is_const(right) { left = ctx.concretize(left)?; } } diff --git a/typos.toml b/typos.toml index f79b12d19b..8bcf28218a 100644 --- a/typos.toml +++ b/typos.toml @@ -27,6 +27,7 @@ ANDed = "ANDed" D3DCOLORtoUBYTE4 = "D3DCOLORtoUBYTE4" Derivate = "Derivate" inout = "inout" +Ect = "Ect" [type.wgsl] extend-glob = ["*.wgsl"]