From d1577f57770658f00f2b3af74281bc13cfd0b490 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 9 Jan 2023 16:31:01 -0800 Subject: [PATCH] Let the uniformity analysis trust the handle validation pass. Undo some changes from #1668, now that #2090 has been merged. --- src/valid/analyzer.rs | 33 +++++++-------------------------- src/valid/expression.rs | 2 -- src/valid/function.rs | 2 -- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/valid/analyzer.rs b/src/valid/analyzer.rs index eb6c1fc4a7..30fb32d076 100644 --- a/src/valid/analyzer.rs +++ b/src/valid/analyzer.rs @@ -6,7 +6,7 @@ Figures out the following properties: - expression reference counts !*/ -use super::{CallError, ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags}; +use super::{ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags}; use crate::span::{AddSpan as _, WithSpan}; use crate::{ arena::{Arena, Handle}, @@ -308,10 +308,7 @@ impl FunctionInfo { handle: Handle, global_use: GlobalUse, ) -> NonUniformResult { - //Note: if the expression doesn't exist, this function - // will return `None`, but the later validation of - // expressions should detect this and error properly. - let info = self.expressions.get_mut(handle.index())?; + let info = &mut self.expressions[handle.index()]; info.ref_count += 1; // mark the used global as read if let Some(global) = info.assignable_global { @@ -335,8 +332,7 @@ impl FunctionInfo { handle: Handle, assignable_global: &mut Option>, ) -> NonUniformResult { - //Note: similarly to `add_ref_impl`, this ignores invalid expressions. - let info = self.expressions.get_mut(handle.index())?; + let info = &mut self.expressions[handle.index()]; info.ref_count += 1; // propagate the assignable global up the chain, till it either hits // a value-type expression, or the assignment statement. @@ -689,13 +685,7 @@ impl FunctionInfo { non_uniform_result: self.add_ref(expr), requirements: UniformityRequirements::empty(), }, - E::CallResult(function) => { - let info = other_functions - .get(function.index()) - .ok_or(ExpressionError::CallToUndeclaredFunction(function))?; - - info.uniformity.clone() - } + E::CallResult(function) => other_functions[function.index()].uniformity.clone(), E::AtomicResult { .. } => Uniformity { non_uniform_result: Some(handle), requirements: UniformityRequirements::empty(), @@ -736,15 +726,12 @@ impl FunctionInfo { use crate::Statement as S; let mut combined_uniformity = FunctionUniformity::new(); - for (statement, &span) in statements.span_iter() { + for statement in statements { let uniformity = match *statement { S::Emit(ref range) => { let mut requirements = UniformityRequirements::empty(); for expr in range.clone() { - let req = match self.expressions.get(expr.index()) { - Some(expr) => expr.uniformity.requirements, - None => UniformityRequirements::empty(), - }; + let req = self.expressions[expr.index()].uniformity.requirements; #[cfg(feature = "validate")] if self .flags @@ -889,13 +876,7 @@ impl FunctionInfo { for &argument in arguments { let _ = self.add_ref(argument); } - let info = other_functions.get(function.index()).ok_or( - FunctionError::InvalidCall { - function, - error: CallError::ForwardDeclaredFunction, - } - .with_span_static(span, "forward call"), - )?; + let info = &other_functions[function.index()]; //Note: the result is validated by the Validator, not here self.process_call(info, arguments, expression_arena)? } diff --git a/src/valid/expression.rs b/src/valid/expression.rs index 14f52fb93c..9853f1d1be 100644 --- a/src/valid/expression.rs +++ b/src/valid/expression.rs @@ -65,8 +65,6 @@ pub enum ExpressionError { ExpectedGlobalVariable, #[error("Not a global variable or a function argument")] ExpectedGlobalOrArgument, - #[error("Calling an undeclared function {0:?}")] - CallToUndeclaredFunction(Handle), #[error("Needs to be an binding array instead of {0:?}")] ExpectedBindingArrayType(Handle), #[error("Needs to be an image instead of {0:?}")] diff --git a/src/valid/function.rs b/src/valid/function.rs index 3c555491c3..b615895ae3 100644 --- a/src/valid/function.rs +++ b/src/valid/function.rs @@ -19,8 +19,6 @@ use bit_set::BitSet; #[derive(Clone, Debug, thiserror::Error)] #[cfg_attr(test, derive(PartialEq))] pub enum CallError { - #[error("The callee is declared after the caller")] - ForwardDeclaredFunction, #[error("Argument {index} expression is invalid")] Argument { index: usize,