Skip to content

Commit c8aec8f

Browse files
committed
Make it possible to use hf32! and similar macros outside of libm
Adjust paths such that these macros don't go through the private `math` module. `feature = "private-test-deps"` is still needed. Additionally, ensure that `cargo check` for this crate gets run in CI because `cargo test` does not seem to identify this problem. `compiler_builtins` will need to reexport the `support` module.
1 parent 3e49c09 commit c8aec8f

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ jobs:
143143
- name: Install Rust
144144
run: rustup update nightly --no-self-update && rustup default nightly
145145
- uses: Swatinem/rust-cache@v2
146+
- run: cargo check --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml
146147
- run: cargo test --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml
147148

148149
benchmarks:

crates/compiler-builtins-smoke-test/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub mod libm;
1717

1818
use core::ffi::c_int;
1919

20+
// Required for macro paths.
21+
use libm::support;
22+
2023
/// Mark functions `#[no_mangle]` and with the C ABI.
2124
macro_rules! no_mangle {
2225
($( $name:ident( $($tt:tt)+ ) -> $ret:ty; )+) => {

src/math/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub mod support;
8181

8282
#[macro_use]
8383
#[cfg(not(feature = "unstable-public-internals"))]
84-
mod support;
84+
pub(crate) mod support;
8585

8686
cfg_if! {
8787
if #[cfg(feature = "unstable-public-internals")] {

src/math/support/float_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub trait Float:
107107
!self.is_sign_negative()
108108
}
109109

110-
/// Returns if `self` is subnormal
110+
/// Returns if `self` is subnormal.
111111
fn is_subnormal(self) -> bool {
112112
(self.to_bits() & Self::EXP_MASK) == Self::Int::ZERO
113113
}

src/math/support/macros.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,33 @@ macro_rules! select_implementation {
9090
/// Construct a 16-bit float from hex float representation (C-style), guaranteed to
9191
/// evaluate at compile time.
9292
#[cfg(f16_enabled)]
93+
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
9394
#[allow(unused_macros)]
9495
macro_rules! hf16 {
9596
($s:literal) => {{
96-
const X: f16 = $crate::math::support::hf16($s);
97+
const X: f16 = $crate::support::hf16($s);
9798
X
9899
}};
99100
}
100101

101102
/// Construct a 32-bit float from hex float representation (C-style), guaranteed to
102103
/// evaluate at compile time.
103104
#[allow(unused_macros)]
105+
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
104106
macro_rules! hf32 {
105107
($s:literal) => {{
106-
const X: f32 = $crate::math::support::hf32($s);
108+
const X: f32 = $crate::support::hf32($s);
107109
X
108110
}};
109111
}
110112

111113
/// Construct a 64-bit float from hex float representation (C-style), guaranteed to
112114
/// evaluate at compile time.
113115
#[allow(unused_macros)]
116+
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
114117
macro_rules! hf64 {
115118
($s:literal) => {{
116-
const X: f64 = $crate::math::support::hf64($s);
119+
const X: f64 = $crate::support::hf64($s);
117120
X
118121
}};
119122
}
@@ -122,9 +125,10 @@ macro_rules! hf64 {
122125
/// evaluate at compile time.
123126
#[cfg(f128_enabled)]
124127
#[allow(unused_macros)]
128+
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
125129
macro_rules! hf128 {
126130
($s:literal) => {{
127-
const X: f128 = $crate::math::support::hf128($s);
131+
const X: f128 = $crate::support::hf128($s);
128132
X
129133
}};
130134
}

src/math/support/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ mod int_traits;
99
pub use float_traits::{Float, IntTy};
1010
pub(crate) use float_traits::{f32_from_bits, f64_from_bits};
1111
#[cfg(f16_enabled)]
12+
#[allow(unused_imports)]
1213
pub use hex_float::hf16;
1314
#[cfg(f128_enabled)]
15+
#[allow(unused_imports)]
1416
pub use hex_float::hf128;
1517
#[allow(unused_imports)]
1618
pub use hex_float::{Hexf, hf32, hf64};

0 commit comments

Comments
 (0)