Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement override-expression evaluation #5249

Merged
merged 15 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion naga/src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub struct Validator {
switch_values: FastHashSet<crate::SwitchValue>,
valid_expression_list: Vec<Handle<crate::Expression>>,
valid_expression_set: BitSet,
override_ids: BitSet,
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Clone, Debug, thiserror::Error)]
Expand All @@ -186,6 +187,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")]
Expand Down Expand Up @@ -309,6 +312,7 @@ impl Validator {
switch_values: FastHashSet::default(),
valid_expression_list: Vec::new(),
valid_expression_set: BitSet::new(),
override_ids: BitSet::new(),
}
}

Expand All @@ -321,6 +325,7 @@ impl Validator {
self.switch_values.clear();
self.valid_expression_list.clear();
self.valid_expression_set.clear();
self.override_ids.clear();
}

fn validate_constant(
Expand All @@ -346,7 +351,7 @@ impl Validator {
}

fn validate_override(
&self,
&mut self,
handle: Handle<crate::Override>,
gctx: crate::proc::GlobalCtx,
mod_info: &ModuleInfo,
Expand All @@ -357,6 +362,12 @@ impl Validator {
return Err(OverrideError::MissingNameAndID);
}

if let Some(id) = o.id {
if !self.override_ids.insert(id as usize) {
return Err(OverrideError::DuplicateID);
}
}

let type_info = &self.types[o.ty.index()];
if !type_info.flags.contains(TypeFlags::CONSTRUCTIBLE) {
return Err(OverrideError::NonConstructibleType);
Expand Down