Skip to content

Commit ddfdf91

Browse files
authored
Unrolled build for #146915
Rollup merge of #146915 - clarfonthey:safe-intrinsics-2, r=RalfJung Make missed precondition-free float intrinsics safe So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse. Extra follow-up to #146683. r? ```@RalfJung``` who reviewed the previous one These don't appear to be used anywhere outside of the standard locations, at least.
2 parents 15283f6 + e8a8e06 commit ddfdf91

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
9090
| sym::contract_check_ensures
9191
| sym::contract_check_requires
9292
| sym::contract_checks
93+
| sym::copysignf16
94+
| sym::copysignf32
95+
| sym::copysignf64
96+
| sym::copysignf128
9397
| sym::cosf16
9498
| sym::cosf32
9599
| sym::cosf64
@@ -106,6 +110,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
106110
| sym::expf32
107111
| sym::expf64
108112
| sym::expf128
113+
| sym::fabsf16
114+
| sym::fabsf32
115+
| sym::fabsf64
116+
| sym::fabsf128
109117
| sym::fadd_algebraic
110118
| sym::fdiv_algebraic
111119
| sym::floorf16

library/core/src/intrinsics/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ pub const fn maximumf128(x: f128, y: f128) -> f128 {
31703170
/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
31713171
#[rustc_nounwind]
31723172
#[rustc_intrinsic]
3173-
pub const unsafe fn fabsf16(x: f16) -> f16;
3173+
pub const fn fabsf16(x: f16) -> f16;
31743174

31753175
/// Returns the absolute value of an `f32`.
31763176
///
@@ -3179,7 +3179,7 @@ pub const unsafe fn fabsf16(x: f16) -> f16;
31793179
#[rustc_nounwind]
31803180
#[rustc_intrinsic_const_stable_indirect]
31813181
#[rustc_intrinsic]
3182-
pub const unsafe fn fabsf32(x: f32) -> f32;
3182+
pub const fn fabsf32(x: f32) -> f32;
31833183

31843184
/// Returns the absolute value of an `f64`.
31853185
///
@@ -3188,23 +3188,23 @@ pub const unsafe fn fabsf32(x: f32) -> f32;
31883188
#[rustc_nounwind]
31893189
#[rustc_intrinsic_const_stable_indirect]
31903190
#[rustc_intrinsic]
3191-
pub const unsafe fn fabsf64(x: f64) -> f64;
3191+
pub const fn fabsf64(x: f64) -> f64;
31923192

31933193
/// Returns the absolute value of an `f128`.
31943194
///
31953195
/// The stabilized version of this intrinsic is
31963196
/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
31973197
#[rustc_nounwind]
31983198
#[rustc_intrinsic]
3199-
pub const unsafe fn fabsf128(x: f128) -> f128;
3199+
pub const fn fabsf128(x: f128) -> f128;
32003200

32013201
/// Copies the sign from `y` to `x` for `f16` values.
32023202
///
32033203
/// The stabilized version of this intrinsic is
32043204
/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
32053205
#[rustc_nounwind]
32063206
#[rustc_intrinsic]
3207-
pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
3207+
pub const fn copysignf16(x: f16, y: f16) -> f16;
32083208

32093209
/// Copies the sign from `y` to `x` for `f32` values.
32103210
///
@@ -3213,23 +3213,23 @@ pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
32133213
#[rustc_nounwind]
32143214
#[rustc_intrinsic_const_stable_indirect]
32153215
#[rustc_intrinsic]
3216-
pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
3216+
pub const fn copysignf32(x: f32, y: f32) -> f32;
32173217
/// Copies the sign from `y` to `x` for `f64` values.
32183218
///
32193219
/// The stabilized version of this intrinsic is
32203220
/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
32213221
#[rustc_nounwind]
32223222
#[rustc_intrinsic_const_stable_indirect]
32233223
#[rustc_intrinsic]
3224-
pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
3224+
pub const fn copysignf64(x: f64, y: f64) -> f64;
32253225

32263226
/// Copies the sign from `y` to `x` for `f128` values.
32273227
///
32283228
/// The stabilized version of this intrinsic is
32293229
/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
32303230
#[rustc_nounwind]
32313231
#[rustc_intrinsic]
3232-
pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
3232+
pub const fn copysignf128(x: f128, y: f128) -> f128;
32333233

32343234
/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
32353235
/// with `df` as the derivative function and `args` as its arguments.

library/core/src/num/f128.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,7 @@ impl f128 {
13671367
#[rustc_const_unstable(feature = "f128", issue = "116909")]
13681368
#[must_use = "method returns a new number and does not mutate the original value"]
13691369
pub const fn copysign(self, sign: f128) -> f128 {
1370-
// SAFETY: this is actually a safe intrinsic
1371-
unsafe { intrinsics::copysignf128(self, sign) }
1370+
intrinsics::copysignf128(self, sign)
13721371
}
13731372

13741373
/// Float addition that allows optimizations based on algebraic rules.

library/core/src/num/f16.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,7 @@ impl f16 {
13441344
#[rustc_const_unstable(feature = "f16", issue = "116909")]
13451345
#[must_use = "method returns a new number and does not mutate the original value"]
13461346
pub const fn copysign(self, sign: f16) -> f16 {
1347-
// SAFETY: this is actually a safe intrinsic
1348-
unsafe { intrinsics::copysignf16(self, sign) }
1347+
intrinsics::copysignf16(self, sign)
13491348
}
13501349

13511350
/// Float addition that allows optimizations based on algebraic rules.

library/core/src/num/f32.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,7 @@ impl f32 {
14501450
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
14511451
#[inline]
14521452
pub const fn abs(self) -> f32 {
1453-
// SAFETY: this is actually a safe intrinsic
1454-
unsafe { intrinsics::fabsf32(self) }
1453+
intrinsics::fabsf32(self)
14551454
}
14561455

14571456
/// Returns a number that represents the sign of `self`.
@@ -1509,8 +1508,7 @@ impl f32 {
15091508
#[stable(feature = "copysign", since = "1.35.0")]
15101509
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
15111510
pub const fn copysign(self, sign: f32) -> f32 {
1512-
// SAFETY: this is actually a safe intrinsic
1513-
unsafe { intrinsics::copysignf32(self, sign) }
1511+
intrinsics::copysignf32(self, sign)
15141512
}
15151513

15161514
/// Float addition that allows optimizations based on algebraic rules.

library/core/src/num/f64.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,7 @@ impl f64 {
14481448
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
14491449
#[inline]
14501450
pub const fn abs(self) -> f64 {
1451-
// SAFETY: this is actually a safe intrinsic
1452-
unsafe { intrinsics::fabsf64(self) }
1451+
intrinsics::fabsf64(self)
14531452
}
14541453

14551454
/// Returns a number that represents the sign of `self`.
@@ -1507,8 +1506,7 @@ impl f64 {
15071506
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
15081507
#[inline]
15091508
pub const fn copysign(self, sign: f64) -> f64 {
1510-
// SAFETY: this is actually a safe intrinsic
1511-
unsafe { intrinsics::copysignf64(self, sign) }
1509+
intrinsics::copysignf64(self, sign)
15121510
}
15131511

15141512
/// Float addition that allows optimizations based on algebraic rules.

0 commit comments

Comments
 (0)