Remove formats [T; N] does not impl (rust-lang/portable-simd#337)

Remove these extra formatting traits, as they are
inconsistent with how arrays and slices format,
and it can cause unnecessary code bloat in binaries.
We can revisit this if people ever agree on doing these
formatters for the other slice-y types.

Prefer to dispatch to the `impl `fmt::Debug for [T]`,
to reduce the chances of monomorphizing twice.
Inlining it seems like a good idea for similar reasons?
This commit is contained in:
Jubilee 2023-04-09 21:26:40 -07:00 committed by GitHub
parent 90f2af774a
commit ceb2611592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,39 +1,21 @@
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
use core::fmt; use core::fmt;
macro_rules! impl_fmt_trait { impl<T, const LANES: usize> fmt::Debug for Simd<T, LANES>
{ $($trait:ident,)* } => { where
$( LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> fmt::$trait for Simd<T, LANES> T: SimdElement + fmt::Debug,
where {
LaneCount<LANES>: SupportedLaneCount, /// A `Simd<T, N>` has a debug format like the one for `[T]`:
T: SimdElement + fmt::$trait, /// ```
{ /// # #![feature(portable_simd)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { /// # #[cfg(feature = "as_crate")] use core_simd::simd::Simd;
#[repr(transparent)] /// # #[cfg(not(feature = "as_crate"))] use core::simd::Simd;
struct Wrapper<'a, T: fmt::$trait>(&'a T); /// let floats = Simd::<f32, 4>::splat(-1.0);
/// assert_eq!(format!("{:?}", [-1.0; 4]), format!("{:?}", floats));
impl<T: fmt::$trait> fmt::Debug for Wrapper<'_, T> { /// ```
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[inline]
self.0.fmt(f) fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
} <[T] as fmt::Debug>::fmt(self.as_array(), f)
}
f.debug_list()
.entries(self.as_array().iter().map(|x| Wrapper(x)))
.finish()
}
}
)*
} }
} }
impl_fmt_trait! {
Debug,
Binary,
LowerExp,
UpperExp,
Octal,
LowerHex,
UpperHex,
}