Skip to content

Commit e2f410f

Browse files
authored
Rollup merge of #63642 - eddyb:wrap-it-up, r=rkruppe,Mark-Simulacrum
Rename overflowing_{add,sub,mul} intrinsics to wrapping_{add,sub,mul}. These confused @Gankra, and then, also me, especially since `overflowing_*` *methods* also exist, but they map to `*_with_overflow` intrinsics! r? @oli-obk / @nikomatsakis cc @Mark-Simulacrum (on the rustbuild workaround)
2 parents 4151153 + 892ef6f commit e2f410f

File tree

8 files changed

+89
-26
lines changed

8 files changed

+89
-26
lines changed

src/bootstrap/bin/rustc.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ fn main() {
102102
// FIXME: the fact that core here is excluded is due to core_arch from our stdarch submodule
103103
// being broken on the beta compiler with bootstrap passed, so this is a temporary workaround
104104
// (we've just snapped, so there are no cfg(bootstrap) related annotations in core).
105-
if stage == "0" && crate_name != Some("core") {
106-
cmd.arg("--cfg").arg("bootstrap");
105+
if stage == "0" {
106+
if crate_name != Some("core") {
107+
cmd.arg("--cfg").arg("bootstrap");
108+
} else {
109+
// NOTE(eddyb) see FIXME above, except now we need annotations again in core.
110+
cmd.arg("--cfg").arg("boostrap_stdarch_ignore_this");
111+
}
107112
}
108113

109114
// Print backtrace in case of ICE

src/libcore/intrinsics.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1293,18 +1293,40 @@ extern "rust-intrinsic" {
12931293
/// The stabilized versions of this intrinsic are available on the integer
12941294
/// primitives via the `wrapping_add` method. For example,
12951295
/// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
1296+
#[cfg(boostrap_stdarch_ignore_this)]
12961297
pub fn overflowing_add<T>(a: T, b: T) -> T;
12971298
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
12981299
/// The stabilized versions of this intrinsic are available on the integer
12991300
/// primitives via the `wrapping_sub` method. For example,
13001301
/// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
1302+
#[cfg(boostrap_stdarch_ignore_this)]
13011303
pub fn overflowing_sub<T>(a: T, b: T) -> T;
13021304
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
13031305
/// The stabilized versions of this intrinsic are available on the integer
13041306
/// primitives via the `wrapping_mul` method. For example,
13051307
/// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
1308+
#[cfg(boostrap_stdarch_ignore_this)]
13061309
pub fn overflowing_mul<T>(a: T, b: T) -> T;
13071310

1311+
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1312+
/// The stabilized versions of this intrinsic are available on the integer
1313+
/// primitives via the `wrapping_add` method. For example,
1314+
/// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
1315+
#[cfg(not(boostrap_stdarch_ignore_this))]
1316+
pub fn wrapping_add<T>(a: T, b: T) -> T;
1317+
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1318+
/// The stabilized versions of this intrinsic are available on the integer
1319+
/// primitives via the `wrapping_sub` method. For example,
1320+
/// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
1321+
#[cfg(not(boostrap_stdarch_ignore_this))]
1322+
pub fn wrapping_sub<T>(a: T, b: T) -> T;
1323+
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1324+
/// The stabilized versions of this intrinsic are available on the integer
1325+
/// primitives via the `wrapping_mul` method. For example,
1326+
/// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
1327+
#[cfg(not(boostrap_stdarch_ignore_this))]
1328+
pub fn wrapping_mul<T>(a: T, b: T) -> T;
1329+
13081330
/// Computes `a + b`, while saturating at numeric bounds.
13091331
/// The stabilized versions of this intrinsic are available on the integer
13101332
/// primitives via the `saturating_add` method. For example,

src/libcore/num/mod.rs

+42-6
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,13 @@ $EndFeature, "
11121112
without modifying the original"]
11131113
#[inline]
11141114
pub const fn wrapping_add(self, rhs: Self) -> Self {
1115-
intrinsics::overflowing_add(self, rhs)
1115+
#[cfg(boostrap_stdarch_ignore_this)] {
1116+
intrinsics::overflowing_add(self, rhs)
1117+
}
1118+
1119+
#[cfg(not(boostrap_stdarch_ignore_this))] {
1120+
intrinsics::wrapping_add(self, rhs)
1121+
}
11161122
}
11171123
}
11181124

@@ -1135,7 +1141,13 @@ $EndFeature, "
11351141
without modifying the original"]
11361142
#[inline]
11371143
pub const fn wrapping_sub(self, rhs: Self) -> Self {
1138-
intrinsics::overflowing_sub(self, rhs)
1144+
#[cfg(boostrap_stdarch_ignore_this)] {
1145+
intrinsics::overflowing_sub(self, rhs)
1146+
}
1147+
1148+
#[cfg(not(boostrap_stdarch_ignore_this))] {
1149+
intrinsics::wrapping_sub(self, rhs)
1150+
}
11391151
}
11401152
}
11411153

@@ -1157,7 +1169,13 @@ $EndFeature, "
11571169
without modifying the original"]
11581170
#[inline]
11591171
pub const fn wrapping_mul(self, rhs: Self) -> Self {
1160-
intrinsics::overflowing_mul(self, rhs)
1172+
#[cfg(boostrap_stdarch_ignore_this)] {
1173+
intrinsics::overflowing_mul(self, rhs)
1174+
}
1175+
1176+
#[cfg(not(boostrap_stdarch_ignore_this))] {
1177+
intrinsics::wrapping_mul(self, rhs)
1178+
}
11611179
}
11621180
}
11631181

@@ -3031,7 +3049,13 @@ $EndFeature, "
30313049
without modifying the original"]
30323050
#[inline]
30333051
pub const fn wrapping_add(self, rhs: Self) -> Self {
3034-
intrinsics::overflowing_add(self, rhs)
3052+
#[cfg(boostrap_stdarch_ignore_this)] {
3053+
intrinsics::overflowing_add(self, rhs)
3054+
}
3055+
3056+
#[cfg(not(boostrap_stdarch_ignore_this))] {
3057+
intrinsics::wrapping_add(self, rhs)
3058+
}
30353059
}
30363060
}
30373061

@@ -3053,7 +3077,13 @@ $EndFeature, "
30533077
without modifying the original"]
30543078
#[inline]
30553079
pub const fn wrapping_sub(self, rhs: Self) -> Self {
3056-
intrinsics::overflowing_sub(self, rhs)
3080+
#[cfg(boostrap_stdarch_ignore_this)] {
3081+
intrinsics::overflowing_sub(self, rhs)
3082+
}
3083+
3084+
#[cfg(not(boostrap_stdarch_ignore_this))] {
3085+
intrinsics::wrapping_sub(self, rhs)
3086+
}
30573087
}
30583088
}
30593089

@@ -3076,7 +3106,13 @@ $EndFeature, "
30763106
without modifying the original"]
30773107
#[inline]
30783108
pub const fn wrapping_mul(self, rhs: Self) -> Self {
3079-
intrinsics::overflowing_mul(self, rhs)
3109+
#[cfg(boostrap_stdarch_ignore_this)] {
3110+
intrinsics::overflowing_mul(self, rhs)
3111+
}
3112+
3113+
#[cfg(not(boostrap_stdarch_ignore_this))] {
3114+
intrinsics::wrapping_mul(self, rhs)
3115+
}
30803116
}
30813117

30823118
doc_comment! {

src/librustc_codegen_llvm/intrinsic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
328328
},
329329
"ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "ctpop" | "bswap" |
330330
"bitreverse" | "add_with_overflow" | "sub_with_overflow" |
331-
"mul_with_overflow" | "overflowing_add" | "overflowing_sub" | "overflowing_mul" |
331+
"mul_with_overflow" | "wrapping_add" | "wrapping_sub" | "wrapping_mul" |
332332
"unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" |
333333
"unchecked_add" | "unchecked_sub" | "unchecked_mul" | "exact_div" |
334334
"rotate_left" | "rotate_right" | "saturating_add" | "saturating_sub" => {
@@ -398,9 +398,9 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
398398

399399
return;
400400
},
401-
"overflowing_add" => self.add(args[0].immediate(), args[1].immediate()),
402-
"overflowing_sub" => self.sub(args[0].immediate(), args[1].immediate()),
403-
"overflowing_mul" => self.mul(args[0].immediate(), args[1].immediate()),
401+
"wrapping_add" => self.add(args[0].immediate(), args[1].immediate()),
402+
"wrapping_sub" => self.sub(args[0].immediate(), args[1].immediate()),
403+
"wrapping_mul" => self.mul(args[0].immediate(), args[1].immediate()),
404404
"exact_div" =>
405405
if signed {
406406
self.exactsdiv(args[0].immediate(), args[1].immediate())

src/librustc_mir/interpret/intrinsics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
110110
};
111111
self.write_scalar(out_val, dest)?;
112112
}
113-
| "overflowing_add"
114-
| "overflowing_sub"
115-
| "overflowing_mul"
113+
| "wrapping_add"
114+
| "wrapping_sub"
115+
| "wrapping_mul"
116116
| "add_with_overflow"
117117
| "sub_with_overflow"
118118
| "mul_with_overflow" => {
119119
let lhs = self.read_immediate(args[0])?;
120120
let rhs = self.read_immediate(args[1])?;
121121
let (bin_op, ignore_overflow) = match intrinsic_name {
122-
"overflowing_add" => (BinOp::Add, true),
123-
"overflowing_sub" => (BinOp::Sub, true),
124-
"overflowing_mul" => (BinOp::Mul, true),
122+
"wrapping_add" => (BinOp::Add, true),
123+
"wrapping_sub" => (BinOp::Sub, true),
124+
"wrapping_mul" => (BinOp::Mul, true),
125125
"add_with_overflow" => (BinOp::Add, false),
126126
"sub_with_overflow" => (BinOp::Sub, false),
127127
"mul_with_overflow" => (BinOp::Mul, false),

src/librustc_mir/transform/qualify_consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ impl Qualif for IsNotPromotable {
537537
| "cttz_nonzero"
538538
| "ctlz"
539539
| "ctlz_nonzero"
540-
| "overflowing_add"
541-
| "overflowing_sub"
542-
| "overflowing_mul"
540+
| "wrapping_add"
541+
| "wrapping_sub"
542+
| "wrapping_mul"
543543
| "unchecked_shl"
544544
| "unchecked_shr"
545545
| "rotate_left"

src/librustc_mir/transform/qualify_min_const_fn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ fn is_intrinsic_whitelisted(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
379379
| "add_with_overflow" // ~> .overflowing_add
380380
| "sub_with_overflow" // ~> .overflowing_sub
381381
| "mul_with_overflow" // ~> .overflowing_mul
382-
| "overflowing_add" // ~> .wrapping_add
383-
| "overflowing_sub" // ~> .wrapping_sub
384-
| "overflowing_mul" // ~> .wrapping_mul
382+
| "wrapping_add" // ~> .wrapping_add
383+
| "wrapping_sub" // ~> .wrapping_sub
384+
| "wrapping_mul" // ~> .wrapping_mul
385385
| "saturating_add" // ~> .saturating_add
386386
| "saturating_sub" // ~> .saturating_sub
387387
| "unchecked_shl" // ~> .wrapping_shl

src/librustc_typeck/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn intrisic_operation_unsafety(intrinsic: &str) -> hir::Unsafety {
6767
match intrinsic {
6868
"size_of" | "min_align_of" | "needs_drop" |
6969
"add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" |
70-
"overflowing_add" | "overflowing_sub" | "overflowing_mul" |
70+
"wrapping_add" | "wrapping_sub" | "wrapping_mul" |
7171
"saturating_add" | "saturating_sub" |
7272
"rotate_left" | "rotate_right" |
7373
"ctpop" | "ctlz" | "cttz" | "bswap" | "bitreverse" |
@@ -314,7 +314,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
314314
(1, vec![param(0), param(0)], param(0)),
315315
"unchecked_add" | "unchecked_sub" | "unchecked_mul" =>
316316
(1, vec![param(0), param(0)], param(0)),
317-
"overflowing_add" | "overflowing_sub" | "overflowing_mul" =>
317+
"wrapping_add" | "wrapping_sub" | "wrapping_mul" =>
318318
(1, vec![param(0), param(0)], param(0)),
319319
"saturating_add" | "saturating_sub" =>
320320
(1, vec![param(0), param(0)], param(0)),

0 commit comments

Comments
 (0)