Skip to content

Commit

Permalink
typifier works with sin
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed Feb 3, 2025
1 parent 431e0e1 commit 6f2345c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
14 changes: 7 additions & 7 deletions naga/src/proc/builtins/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
mod scalar_sine {
use crate::proc::builtins;

use builtins::{AnyOverloadSet, list};
use builtins::OverloadSet as _;
use builtins::Rule as _;
use builtins::{list, AnyOverloadSet};

use crate::Scalar as Sc;
use crate::TypeInner as Ti;
Expand All @@ -29,13 +29,13 @@ mod scalar_sine {
// These should all be permitted.
assert!(!set.clone().arg(0, &Ti::Scalar(Sc::F32), &arena).is_empty());
assert!(!set
.clone()
.arg(0, &Ti::Scalar(Sc::ABSTRACT_FLOAT), &arena)
.is_empty());
.clone()
.arg(0, &Ti::Scalar(Sc::ABSTRACT_FLOAT), &arena)
.is_empty());
assert!(!set
.clone()
.arg(0, &Ti::Scalar(Sc::ABSTRACT_INT), &arena)
.is_empty());
.clone()
.arg(0, &Ti::Scalar(Sc::ABSTRACT_INT), &arena)
.is_empty());
}

#[test]
Expand Down
19 changes: 18 additions & 1 deletion naga/src/proc/typifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ pub enum ResolveError {
FunctionArgumentNotFound(u32),
#[error("Special type is not registered within the module")]
MissingSpecialType,
#[error("Call to builtin {0} has incorrect or ambiguous arguments")]
BuiltinArgumentsInvalid(String),
}

pub struct ResolveContext<'a> {
Expand Down Expand Up @@ -635,14 +637,29 @@ impl<'a> ResolveContext<'a> {
use crate::MathFunction as Mf;
let res_arg = past(arg)?;
match fun {
Mf::Sin => {
use crate::proc::builtins::OverloadSet as _;
use crate::proc::builtins::Rule as _;

let mut overloads = fun.overloads();
overloads = overloads.arg(0, res_arg.inner_with(types), types);
if let Some(arg1) = arg1 {
overloads = overloads.arg(0, past(arg1)?.inner_with(types), types);
}

let Some(rule) = overloads.most_preferred() else {
return Err(ResolveError::BuiltinArgumentsInvalid(format!("{fun:?}")));
};

TypeResolution::Value(rule.conclusion_type())
}
Mf::Abs
| Mf::Min
| Mf::Max
| Mf::Clamp
| Mf::Saturate
| Mf::Cos
| Mf::Cosh
| Mf::Sin
| Mf::Sinh
| Mf::Tan
| Mf::Tanh
Expand Down

0 comments on commit 6f2345c

Please sign in to comment.