Skip to content

Introduce helper types for accessing trait items #367

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

Merged
merged 1 commit into from
Dec 22, 2024
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
2 changes: 1 addition & 1 deletion crates/libm-test/benches/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro_rules! musl_rand_benches {

#[cfg(feature = "build-musl")]
let musl_extra = MuslExtra {
musl_fn: Some(musl_math_sys::$fn_name as <Op as MathOp>::CFn),
musl_fn: Some(musl_math_sys::$fn_name as libm_test::CFn<Op>),
skip_on_i586: $skip_on_i586
};

Expand Down
4 changes: 2 additions & 2 deletions crates/libm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub mod op;
mod precision;
mod test_traits;

pub use libm::support::{Float, Int};
pub use op::{BaseName, Identifier, MathOp};
pub use libm::support::{Float, Int, IntTy};
pub use op::{BaseName, CFn, FTy, Identifier, MathOp, RustFn, RustRet};
pub use precision::{MaybeOverride, SpecialCase, default_ulp};
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};

Expand Down
9 changes: 9 additions & 0 deletions crates/libm-test/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ pub trait MathOp {
const ROUTINE: Self::RustFn;
}

/// Access the associated `FTy` type from an op (helper to avoid ambiguous associated types).
pub type FTy<Op> = <Op as MathOp>::FTy;
/// Access the associated `CFn` type from an op (helper to avoid ambiguous associated types).
pub type CFn<Op> = <Op as MathOp>::CFn;
/// Access the associated `RustFn` type from an op (helper to avoid ambiguous associated types).
pub type RustFn<Op> = <Op as MathOp>::RustFn;
/// Access the associated `RustRet` type from an op (helper to avoid ambiguous associated types).
pub type RustRet<Op> = <Op as MathOp>::RustRet;

macro_rules! do_thing {
// Matcher for unary functions
(
Expand Down
4 changes: 4 additions & 0 deletions src/math/support/float_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ pub trait Float:
}
}

/// Access the associated `Int` type from a float (helper to avoid ambiguous associated types).
#[allow(dead_code)]
pub type IntTy<F> = <F as Float>::Int;

macro_rules! float_impl {
($ty:ident, $ity:ident, $sity:ident, $expty:ident, $bits:expr, $significand_bits:expr) => {
impl Float for $ty {
Expand Down
6 changes: 5 additions & 1 deletion src/math/support/int_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub trait MinInt:
const MAX: Self;
}

/// Access the associated `OtherSign` type from an int (helper to avoid ambiguous associated
/// types).
pub type OtherSign<I> = <I as MinInt>::OtherSign;

/// Trait for some basic operations on integers
#[allow(dead_code)]
pub trait Int:
Expand Down Expand Up @@ -53,7 +57,7 @@ pub trait Int:
+ CastInto<usize>
+ CastFrom<u8>
{
fn signed(self) -> <Self::Unsigned as MinInt>::OtherSign;
fn signed(self) -> OtherSign<Self::Unsigned>;
fn unsigned(self) -> Self::Unsigned;
fn from_unsigned(unsigned: Self::Unsigned) -> Self;
fn abs(self) -> Self;
Expand Down
3 changes: 2 additions & 1 deletion src/math/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ mod float_traits;
mod hex_float;
mod int_traits;

pub use float_traits::Float;
#[allow(unused_imports)]
pub use float_traits::{Float, IntTy};
#[allow(unused_imports)]
pub use hex_float::{hf32, hf64};
pub use int_traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};
Loading