Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Add checks via annotation that lists are sorted or exhaustive #489

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 13 additions & 7 deletions crates/libm-macros/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
None,
&[
"acosf", "acoshf", "asinf", "asinhf", "atanf", "atanhf", "cbrtf", "ceilf", "cosf",
"coshf", "erff", "erfcf", "exp10f", "exp2f", "expf", "expm1f", "fabsf", "floorf",
"coshf", "erfcf", "erff", "exp10f", "exp2f", "expf", "expm1f", "fabsf", "floorf",
"j0f", "j1f", "lgammaf", "log10f", "log1pf", "log2f", "logf", "rintf", "roundf",
"sinf", "sinhf", "sqrtf", "tanf", "tanhf", "tgammaf", "truncf", "y0f", "y1f",
],
Expand All @@ -30,8 +30,8 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
None,
&[
"acos", "acosh", "asin", "asinh", "atan", "atanh", "cbrt", "ceil", "cos", "cosh",
"erf", "erfc", "exp10", "exp2", "exp", "expm1", "fabs", "floor", "j0", "j1", "lgamma",
"log10", "log1p", "log2", "log", "rint", "round", "sin", "sinh", "sqrt", "tan", "tanh",
"erf", "erfc", "exp", "exp10", "exp2", "expm1", "fabs", "floor", "j0", "j1", "lgamma",
"log", "log10", "log1p", "log2", "rint", "round", "sin", "sinh", "sqrt", "tan", "tanh",
"tgamma", "trunc", "y0", "y1",
],
),
Expand Down Expand Up @@ -139,28 +139,28 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
FloatTy::F16,
Signature { args: &[Ty::F16, Ty::I32], returns: &[Ty::F16] },
None,
&["scalbnf16", "ldexpf16"],
&["ldexpf16", "scalbnf16"],
),
(
// `(f32, i32) -> f32`
FloatTy::F32,
Signature { args: &[Ty::F32, Ty::I32], returns: &[Ty::F32] },
None,
&["scalbnf", "ldexpf"],
&["ldexpf", "scalbnf"],
),
(
// `(f64, i64) -> f64`
FloatTy::F64,
Signature { args: &[Ty::F64, Ty::I32], returns: &[Ty::F64] },
None,
&["scalbn", "ldexp"],
&["ldexp", "scalbn"],
),
(
// `(f128, i32) -> f128`
FloatTy::F128,
Signature { args: &[Ty::F128, Ty::I32], returns: &[Ty::F128] },
None,
&["scalbnf128", "ldexpf128"],
&["ldexpf128", "scalbnf128"],
),
(
// `(f32, &mut f32) -> f32` as `(f32) -> (f32, f32)`
Expand Down Expand Up @@ -312,6 +312,12 @@ pub static ALL_OPERATIONS: LazyLock<Vec<MathOpInfo>> = LazyLock::new(|| {
};
ret.push(api);
}

if !names.is_sorted() {
let mut sorted = (*names).to_owned();
sorted.sort_unstable();
panic!("names list is not sorted: {names:?}\nExpected: {sorted:?}");
}
}

ret.sort_by_key(|item| item.name);
Expand Down
9 changes: 8 additions & 1 deletion crates/libm-test/benches/icount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ libm_macros::for_each_function! {
}

main!(
library_benchmark_groups = icount_bench_acos_group,
library_benchmark_groups =
// verify-apilist-start
// verify-sorted-start
icount_bench_acos_group,
icount_bench_acosf_group,
icount_bench_acosh_group,
icount_bench_acoshf_group,
Expand Down Expand Up @@ -169,6 +172,8 @@ main!(
icount_bench_scalbnf16_group,
icount_bench_scalbnf_group,
icount_bench_sin_group,
icount_bench_sincos_group,
icount_bench_sincosf_group,
icount_bench_sinf_group,
icount_bench_sinh_group,
icount_bench_sinhf_group,
Expand All @@ -192,4 +197,6 @@ main!(
icount_bench_y1f_group,
icount_bench_yn_group,
icount_bench_ynf_group,
// verify-sorted-end
// verify-apilist-end
);
2 changes: 2 additions & 0 deletions crates/libm-test/src/mpfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ libm_macros::for_each_function! {
emit_types: [RustFn],
skip: [
// Most of these need a manual implementation
// verify-sorted-start
ceil,
ceilf,
ceilf128,
Expand Down Expand Up @@ -188,6 +189,7 @@ libm_macros::for_each_function! {
truncf128,
truncf16,yn,
ynf,
// verify-sorted-end
],
fn_extra: match MACRO_FN_NAME {
// Remap function names that are different between mpfr and libm
Expand Down
2 changes: 2 additions & 0 deletions crates/libm-test/tests/compare_built_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ libm_macros::for_each_function! {
ynf,

// Not provided by musl
// verify-sorted-start
ceilf128,
ceilf16,
copysignf128,
Expand Down Expand Up @@ -107,5 +108,6 @@ libm_macros::for_each_function! {
sqrtf16,
truncf128,
truncf16,
// verify-sorted-end
],
}
Loading