Skip to content

Commit

Permalink
valid: Check dependencies between functions calls
Browse files Browse the repository at this point in the history
This commit enforces the forward dependency rules on the IR across
functions and their calls, this fixes a crash in a later stage of the
validator.
  • Loading branch information
JCapucho authored and jimblandy committed Jan 31, 2023
1 parent bebaac9 commit 0074c68
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/valid/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl super::Validator {
}
}

let validate_function = |function: &_| -> Result<_, InvalidHandleError> {
let validate_function = |function_handle, function: &_| -> Result<_, InvalidHandleError> {
let &crate::Function {
name: _,
ref arguments,
Expand Down Expand Up @@ -175,6 +175,7 @@ impl super::Validator {
local_variables,
global_variables,
functions,
function_handle,
)?;
}

Expand All @@ -184,11 +185,11 @@ impl super::Validator {
};

for entry_point in entry_points.iter() {
validate_function(&entry_point.function)?;
validate_function(None, &entry_point.function)?;
}

for (_function_handle, function) in functions.iter() {
validate_function(function)?;
for (function_handle, function) in functions.iter() {
validate_function(Some(function_handle), function)?;
}

Ok(())
Expand Down Expand Up @@ -229,6 +230,8 @@ impl super::Validator {
local_variables: &Arena<crate::LocalVariable>,
global_variables: &Arena<crate::GlobalVariable>,
functions: &Arena<crate::Function>,
// The handle of the current function or `None` if it's an entry point
current_function: Option<Handle<crate::Function>>,
) -> Result<(), InvalidHandleError> {
let validate_constant = |handle| Self::validate_constant_handle(handle, constants);
let validate_type = |handle| Self::validate_type_handle(handle, types);
Expand Down Expand Up @@ -373,6 +376,9 @@ impl super::Validator {
}
crate::Expression::CallResult(function) => {
Self::validate_function_handle(function, functions)?;
if let Some(handle) = current_function {
handle.check_dep(function)?;
}
}
crate::Expression::AtomicResult { .. } => (),
crate::Expression::ArrayLength(array) => {
Expand Down

0 comments on commit 0074c68

Please sign in to comment.