Skip to content

Commit

Permalink
Resolve monomorphization errors in compiler-builtins
Browse files Browse the repository at this point in the history
`compiler-builtins` is not allowed to call anything from `core`;
however, there are a couple of cases where we do so in `libm` for debug
output. Gate relevant locations behind the `compiler-builtins` Cargo
feature.
  • Loading branch information
tgross35 committed Feb 24, 2025
1 parent 9a60739 commit 8dbc140
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ exclude = [
[dev-dependencies]
no-panic = "0.1.33"


[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
# compiler-builtins sets this feature, but we use it in `libm`
'cfg(feature, values("compiler-builtins"))',
] }

# The default release profile is unchanged.

# Release mode with debug assertions
Expand Down
1 change: 1 addition & 0 deletions crates/compiler-builtins-smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(arch_enabled)",
"cfg(assert_no_panic)",
"cfg(intrinsics_enabled)",
'cfg(feature, values("compiler-builtins"))',
'cfg(feature, values("force-soft-floats"))',
'cfg(feature, values("unstable"))',
'cfg(feature, values("unstable-intrinsics"))',
Expand Down
2 changes: 2 additions & 0 deletions crates/compiler-builtins-smoke-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//! Additionally, it provides a `#[no_mangle]` C API that can be easier to inspect than the
//! default `.rlib`.
#![compiler_builtins]
#![feature(core_intrinsics)]
#![feature(compiler_builtins)]
#![feature(f16)]
#![feature(f128)]
#![allow(internal_features)]
Expand Down
16 changes: 14 additions & 2 deletions src/math/support/hex_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ fn fmt_any_hex<F: Float>(x: &F, f: &mut fmt::Formatter<'_>) -> fmt::Result {

impl<F: Float> fmt::LowerHex for Hexf<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_any_hex(&self.0, f)
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
unreachable!()
} else {
fmt_any_hex(&self.0, f)
}
}
}
}

Expand All @@ -264,7 +270,13 @@ impl<F: Float> fmt::LowerHex for Hexf<(F, i32)> {

impl fmt::LowerHex for Hexf<i32> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(&self.0, f)
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
unreachable!()
} else {
fmt::LowerHex::fmt(&self.0, f)
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/math/support/int_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ macro_rules! cast_into_float {
($ty:ty; $($into:ty),*) => {$(
impl CastInto<$into> for $ty {
fn cast(self) -> $into {
#[cfg(not(feature = "compiler-builtins"))]
debug_assert_eq!(self as $into as $ty, self, "inexact float cast");
self as $into
}
Expand Down

0 comments on commit 8dbc140

Please sign in to comment.