diff --git a/src/back/spv/block.rs b/src/back/spv/block.rs index 64407e6b0f..4dba7ea0ca 100644 --- a/src/back/spv/block.rs +++ b/src/back/spv/block.rs @@ -245,7 +245,7 @@ impl<'w> BlockContext<'w> { crate::Expression::ZeroValue(_) => self.writer.get_constant_null(result_type_id), crate::Expression::Compose { ty, ref components } => { self.temp_list.clear(); - if self.expression_constness.contains(expr_handle) { + if self.expression_constness.is_const(expr_handle) { self.temp_list.extend( crate::proc::flatten_compose( ty, @@ -274,7 +274,7 @@ impl<'w> BlockContext<'w> { let value_id = self.cached[value]; let components = &[value_id; 4][..size as usize]; - if self.expression_constness.contains(expr_handle) { + if self.expression_constness.is_const(expr_handle) { let ty = self .writer .get_expression_lookup_type(&self.fun_info[expr_handle].ty); @@ -1777,7 +1777,7 @@ impl<'w> BlockContext<'w> { crate::Statement::Emit(ref range) => { for handle in range.clone() { // omit const expressions as we've already cached those - if !self.expression_constness.contains(handle) { + if !self.expression_constness.is_const(handle) { self.cache_expression_value(handle, &mut block)?; } } diff --git a/src/back/spv/writer.rs b/src/back/spv/writer.rs index eeedc8150c..b9f547fea9 100644 --- a/src/back/spv/writer.rs +++ b/src/back/spv/writer.rs @@ -629,7 +629,7 @@ impl Writer { context.cached.reset(ir_function.expressions.len()); for (handle, expr) in ir_function.expressions.iter() { if (expr.needs_pre_emit() && !matches!(*expr, crate::Expression::LocalVariable(_))) - || context.expression_constness.contains(handle) + || context.expression_constness.is_const(handle) { context.cache_expression_value(handle, &mut prelude)?; } diff --git a/src/front/glsl/context.rs b/src/front/glsl/context.rs index bdeffff122..8ae8908cda 100644 --- a/src/front/glsl/context.rs +++ b/src/front/glsl/context.rs @@ -248,12 +248,12 @@ impl<'a> Context<'a> { } pub fn add_expression(&mut self, expr: Expression, meta: Span) -> Result> { - let (expressions, extra_data) = if self.is_const { + let (expressions, function_info) = if self.is_const { (&mut self.module.const_expressions, None) } else { ( &mut self.expressions, - Some(crate::proc::ConstantEvaluatorExtraData { + Some(crate::proc::FunctionLocalData { const_expressions: &self.module.const_expressions, expression_constness: &mut self.expression_constness, emitter: &mut self.emitter, @@ -266,7 +266,7 @@ impl<'a> Context<'a> { types: &mut self.module.types, constants: &self.module.constants, expressions, - extra_data, + function_local_data: function_info, }; let res = eval.try_eval_and_append(&expr, meta).map_err(|e| Error { diff --git a/src/front/glsl/parser/declarations.rs b/src/front/glsl/parser/declarations.rs index c1e8634aaa..b4b88e6d50 100644 --- a/src/front/glsl/parser/declarations.rs +++ b/src/front/glsl/parser/declarations.rs @@ -251,7 +251,7 @@ impl<'source> ParsingContext<'source> { } else if ctx.external { init.and_then(|expr| ctx.ctx.lift_up_const_expression(expr).ok()) } else { - init.filter(|expr| ctx.ctx.expression_constness.contains(*expr)) + init.filter(|expr| ctx.ctx.expression_constness.is_const(*expr)) }; let pointer = ctx.add_var(frontend, ty, name, maybe_const_expr, meta)?; diff --git a/src/front/wgsl/lower/mod.rs b/src/front/wgsl/lower/mod.rs index 94f564899a..764db6ccec 100644 --- a/src/front/wgsl/lower/mod.rs +++ b/src/front/wgsl/lower/mod.rs @@ -6,8 +6,8 @@ use crate::front::wgsl::parse::number::Number; use crate::front::wgsl::parse::{ast, conv}; use crate::front::Typifier; use crate::proc::{ - ensure_block_returns, Alignment, ConstantEvaluator, ConstantEvaluatorExtraData, Emitter, - Layouter, ResolveContext, TypeResolution, + ensure_block_returns, Alignment, ConstantEvaluator, Emitter, FunctionLocalData, Layouter, + ResolveContext, TypeResolution, }; use crate::{Arena, FastHashMap, FastIndexMap, Handle, Span}; @@ -344,7 +344,7 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { types: &mut self.module.types, constants: &self.module.constants, expressions: rctx.naga_expressions, - extra_data: Some(ConstantEvaluatorExtraData { + function_local_data: Some(FunctionLocalData { const_expressions: &self.module.const_expressions, expression_constness: rctx.expression_constness, emitter: rctx.emitter, @@ -362,7 +362,7 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { types: &mut self.module.types, constants: &self.module.constants, expressions: &mut self.module.const_expressions, - extra_data: None, + function_local_data: None, }; eval.try_eval_and_append(&expr, span) @@ -1184,7 +1184,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let (const_initializer, initializer) = { match initializer { - Some(init) if ctx.expression_constness.contains(init) => { + Some(init) if ctx.expression_constness.is_const(init) => { (Some(init), None) } Some(init) => (None, Some(init)), diff --git a/src/proc/constant_evaluator.rs b/src/proc/constant_evaluator.rs index 17b5af7dc1..3b4b1031cf 100644 --- a/src/proc/constant_evaluator.rs +++ b/src/proc/constant_evaluator.rs @@ -12,11 +12,11 @@ pub struct ConstantEvaluator<'a> { /// When `self.expressions` refers to a function's local expression /// arena, this needs to be populated - pub extra_data: Option>, + pub function_local_data: Option>, } #[derive(Debug)] -pub struct ConstantEvaluatorExtraData<'a> { +pub struct FunctionLocalData<'a> { /// Global constant expressions pub const_expressions: &'a Arena, /// Tracks the constness of expressions residing in `ConstantEvaluator.expressions` @@ -41,7 +41,7 @@ impl ExpressionConstnessTracker { self.inner.insert(value.index()); } - pub fn contains(&self, value: Handle) -> bool { + pub fn is_const(&self, value: Handle) -> bool { self.inner.contains(value.index()) } @@ -53,9 +53,9 @@ impl ExpressionConstnessTracker { | crate::Expression::ZeroValue(_) | crate::Expression::Constant(_) => true, crate::Expression::Compose { ref components, .. } => { - components.iter().all(|h| tracker.contains(*h)) + components.iter().all(|h| tracker.is_const(*h)) } - crate::Expression::Splat { value, .. } => tracker.contains(value), + crate::Expression::Splat { value, .. } => tracker.is_const(value), _ => false, }; if insert { @@ -139,8 +139,8 @@ pub enum ConstantEvaluatorError { impl ConstantEvaluator<'_> { fn check(&self, expr: Handle) -> Result<(), ConstantEvaluatorError> { - if let Some(ref extra_data) = self.extra_data { - if !extra_data.expression_constness.contains(expr) { + if let Some(ref extra_data) = self.function_local_data { + if !extra_data.expression_constness.is_const(expr) { log::debug!("check: SubexpressionsAreNotConstant"); return Err(ConstantEvaluatorError::SubexpressionsAreNotConstant); } @@ -156,7 +156,7 @@ impl ConstantEvaluator<'_> { Expression::Constant(c) => { // Are we working in a function's expression arena, or the // module's constant expression arena? - if let Some(ref extra_data) = self.extra_data { + if let Some(ref extra_data) = self.function_local_data { // Deep-copy the constant's value into our arena. self.copy_from(self.constants[c].init, extra_data.const_expressions) } else { @@ -870,12 +870,12 @@ impl ConstantEvaluator<'_> { } fn register_evaluated_expr(&mut self, expr: Expression, span: Span) -> Handle { - if let Some(ConstantEvaluatorExtraData { + if let Some(FunctionLocalData { ref mut emitter, ref mut block, ref mut expression_constness, .. - }) = self.extra_data + }) = self.function_local_data { let is_running = emitter.is_running(); let needs_pre_emit = expr.needs_pre_emit(); @@ -1060,7 +1060,7 @@ mod tests { types: &mut types, constants: &constants, expressions: &mut const_expressions, - extra_data: None, + function_local_data: None, }; let res1 = solver @@ -1146,7 +1146,7 @@ mod tests { types: &mut types, constants: &constants, expressions: &mut const_expressions, - extra_data: None, + function_local_data: None, }; let res = solver @@ -1264,7 +1264,7 @@ mod tests { types: &mut types, constants: &constants, expressions: &mut const_expressions, - extra_data: None, + function_local_data: None, }; let root1 = Expression::AccessIndex { base, index: 1 }; diff --git a/src/proc/mod.rs b/src/proc/mod.rs index e51f796ba8..e5d562eba3 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -11,8 +11,7 @@ mod terminator; mod typifier; pub use constant_evaluator::{ - ConstantEvaluator, ConstantEvaluatorError, ConstantEvaluatorExtraData, - ExpressionConstnessTracker, + ConstantEvaluator, ConstantEvaluatorError, ExpressionConstnessTracker, FunctionLocalData, }; pub use emitter::Emitter; pub use index::{BoundsCheckPolicies, BoundsCheckPolicy, IndexableLength, IndexableLengthError};