mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
validate that override ids are unique
This commit is contained in:
1 parent
2929ec333c
commit
d7cfe16b79
1 file changed
+12
-1
+12
-1
@@ -174,6 +174,7 @@ pub struct Validator {
|
||||
switch_values: FastHashSet<crate::SwitchValue>,
|
||||
valid_expression_list: Vec<Handle<crate::Expression>>,
|
||||
valid_expression_set: BitSet,
|
||||
override_ids: FastHashSet<u16>,
|
||||
}
|
||||
|
||||
#[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<crate::Override>,
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user