From d7cfe16b7920bc3cd56b0425ef1d03ed7178c33e Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:30:10 +0100 Subject: [PATCH] validate that override ids are unique --- naga/src/valid/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index be11e8e39..311279478 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -174,6 +174,7 @@ pub struct Validator { switch_values: FastHashSet, valid_expression_list: Vec>, valid_expression_set: BitSet, + override_ids: FastHashSet, } #[derive(Clone, Debug, thiserror::Error)] @@ -188,6 +189,8 @@ pub enum ConstantError { pub enum OverrideError { #[error("Override name and ID are missing")] MissingNameAndID, + #[error("Override ID must be unique")] + DuplicateID, #[error("The type doesn't match the override")] InvalidType, #[error("The type is not constructible")] @@ -311,6 +314,7 @@ impl Validator { switch_values: FastHashSet::default(), valid_expression_list: Vec::new(), valid_expression_set: BitSet::new(), + override_ids: FastHashSet::default(), } } @@ -323,6 +327,7 @@ impl Validator { self.switch_values.clear(); self.valid_expression_list.clear(); self.valid_expression_set.clear(); + self.override_ids.clear(); } fn validate_constant( @@ -348,7 +353,7 @@ impl Validator { } fn validate_override( - &self, + &mut self, handle: Handle, gctx: crate::proc::GlobalCtx, mod_info: &ModuleInfo, @@ -359,6 +364,12 @@ impl Validator { return Err(OverrideError::MissingNameAndID); } + if let Some(id) = o.id { + if !self.override_ids.insert(id) { + return Err(OverrideError::DuplicateID); + } + } + let type_info = &self.types[o.ty.index()]; if !type_info.flags.contains(TypeFlags::CONSTRUCTIBLE) { return Err(OverrideError::NonConstructibleType);