Skip to content

Commit

Permalink
valid: Check regular functions don't have bindings
Browse files Browse the repository at this point in the history
Checks that all arguments and return types have no bindings in regular functions.
  • Loading branch information
JCapucho committed Sep 10, 2022
1 parent 7d0e984 commit 22ca6c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ pub enum FunctionError {
Handle<crate::Expression>,
UniformityDisruptor,
),
#[error("Functions that are not entry points cannot have `@location` or `@builtin` attributes on their arguments: \"{name}\" has attributes")]
PipelineInputRegularFunction { name: String },
#[error("Functions that are not entry points cannot have `@location` or `@builtin` attributes on their return value types")]
PipelineOutputRegularFunction,
}

bitflags::bitflags! {
Expand Down Expand Up @@ -859,6 +863,7 @@ impl super::Validator {
fun: &crate::Function,
module: &crate::Module,
mod_info: &ModuleInfo,
entry_point: bool,
) -> Result<FunctionInfo, WithSpan<FunctionError>> {
#[cfg_attr(not(feature = "validate"), allow(unused_mut))]
let mut info = mod_info.process_function(fun, module, self.flags, self.capabilities)?;
Expand Down Expand Up @@ -909,6 +914,13 @@ impl super::Validator {
}
.with_span_handle(argument.ty, &module.types));
}

if !entry_point && argument.binding.is_some() {
return Err(FunctionError::PipelineInputRegularFunction {
name: argument.name.clone().unwrap_or_default(),
}
.with_span_handle(argument.ty, &module.types));
}
}

#[cfg(feature = "validate")]
Expand All @@ -920,6 +932,11 @@ impl super::Validator {
return Err(FunctionError::NonConstructibleReturnType
.with_span_handle(result.ty, &module.types));
}

if !entry_point && result.binding.is_some() {
return Err(FunctionError::PipelineOutputRegularFunction
.with_span_handle(result.ty, &module.types));
}
}

self.valid_expression_set.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl super::Validator {
}

let info = self
.validate_function(&ep.function, module, mod_info)
.validate_function(&ep.function, module, mod_info, true)
.map_err(WithSpan::into_other)?;

#[cfg(feature = "validate")]
Expand Down
2 changes: 1 addition & 1 deletion src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl Validator {
};

for (handle, fun) in module.functions.iter() {
match self.validate_function(fun, module, &mod_info) {
match self.validate_function(fun, module, &mod_info, false) {
Ok(info) => mod_info.functions.push(info),
Err(error) => {
return Err(error.and_then(|error| {
Expand Down

0 comments on commit 22ca6c3

Please sign in to comment.