1
1
//! Compiler intrinsics.
2
2
//!
3
3
//! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`.
4
+ //! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs`
5
+ //!
6
+ //! # Const intrinsics
7
+ //!
8
+ //! Note: any changes to the constness of intrinsics should be discussed with the language team.
9
+ //! This includes changes in the stability of the constness.
10
+ //!
11
+ //! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12
+ //! from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to
13
+ //! `librustc_mir/interpret/intrinsics.rs` and add a
14
+ //! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
15
+ //!
16
+ //! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
17
+ //! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
18
+ //! without T-lang consulation, because it bakes a feature into the language that cannot be
19
+ //! replicated in user code without compiler support.
4
20
//!
5
21
//! # Volatiles
6
22
//!
@@ -671,14 +687,17 @@ extern "rust-intrinsic" {
671
687
///
672
688
/// The stabilized version of this intrinsic is
673
689
/// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
690
+ #[ rustc_const_stable( feature = "const_size_of" , since = "1.40.0" ) ]
674
691
pub fn size_of < T > ( ) -> usize ;
675
692
676
693
/// Moves a value to an uninitialized memory location.
677
694
///
678
695
/// Drop glue is not run on the destination.
679
696
pub fn move_val_init < T > ( dst : * mut T , src : T ) ;
680
697
698
+ #[ rustc_const_stable( feature = "const_min_align_of" , since = "1.40.0" ) ]
681
699
pub fn min_align_of < T > ( ) -> usize ;
700
+ #[ rustc_const_unstable( feature = "const_pref_align_of" , issue = "0" ) ]
682
701
pub fn pref_align_of < T > ( ) -> usize ;
683
702
684
703
/// The size of the referenced value in bytes.
@@ -689,18 +708,21 @@ extern "rust-intrinsic" {
689
708
pub fn min_align_of_val < T : ?Sized > ( _: & T ) -> usize ;
690
709
691
710
/// Gets a static string slice containing the name of a type.
711
+ #[ rustc_const_unstable( feature = "const_type_name" , issue = "0" ) ]
692
712
pub fn type_name < T : ?Sized > ( ) -> & ' static str ;
693
713
694
714
/// Gets an identifier which is globally unique to the specified type. This
695
715
/// function will return the same value for a type regardless of whichever
696
716
/// crate it is invoked in.
717
+ #[ rustc_const_unstable( feature = "const_type_id" , issue = "0" ) ]
697
718
pub fn type_id < T : ?Sized + ' static > ( ) -> u64 ;
698
719
699
720
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
700
721
/// This will statically either panic, or do nothing.
701
722
pub fn panic_if_uninhabited < T > ( ) ;
702
723
703
724
/// Gets a reference to a static `Location` indicating where it was called.
725
+ #[ rustc_const_unstable( feature = "const_caller_location" , issue = "47809" ) ]
704
726
pub fn caller_location ( ) -> & ' static crate :: panic:: Location < ' static > ;
705
727
706
728
/// Creates a value initialized to zero.
@@ -957,6 +979,7 @@ extern "rust-intrinsic" {
957
979
///
958
980
/// The stabilized version of this intrinsic is
959
981
/// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
982
+ #[ rustc_const_stable( feature = "const_needs_drop" , since = "1.40.0" ) ]
960
983
pub fn needs_drop < T > ( ) -> bool ;
961
984
962
985
/// Calculates the offset from a pointer.
@@ -1154,6 +1177,7 @@ extern "rust-intrinsic" {
1154
1177
pub fn float_to_int_approx_unchecked < Float , Int > ( value : Float ) -> Int ;
1155
1178
1156
1179
/// Returns the number of bits set in an integer type `T`
1180
+ #[ rustc_const_stable( feature = "const_ctpop" , since = "1.40.0" ) ]
1157
1181
pub fn ctpop < T > ( x : T ) -> T ;
1158
1182
1159
1183
/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
@@ -1181,6 +1205,7 @@ extern "rust-intrinsic" {
1181
1205
/// let num_leading = ctlz(x);
1182
1206
/// assert_eq!(num_leading, 16);
1183
1207
/// ```
1208
+ #[ rustc_const_stable( feature = "const_ctlz" , since = "1.40.0" ) ]
1184
1209
pub fn ctlz < T > ( x : T ) -> T ;
1185
1210
1186
1211
/// Like `ctlz`, but extra-unsafe as it returns `undef` when
@@ -1197,6 +1222,7 @@ extern "rust-intrinsic" {
1197
1222
/// let num_leading = unsafe { ctlz_nonzero(x) };
1198
1223
/// assert_eq!(num_leading, 3);
1199
1224
/// ```
1225
+ #[ rustc_const_unstable( feature = "constctlz" , issue = "0" ) ]
1200
1226
pub fn ctlz_nonzero < T > ( x : T ) -> T ;
1201
1227
1202
1228
/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
@@ -1224,6 +1250,7 @@ extern "rust-intrinsic" {
1224
1250
/// let num_trailing = cttz(x);
1225
1251
/// assert_eq!(num_trailing, 16);
1226
1252
/// ```
1253
+ #[ rustc_const_stable( feature = "const_cttz" , since = "1.40.0" ) ]
1227
1254
pub fn cttz < T > ( x : T ) -> T ;
1228
1255
1229
1256
/// Like `cttz`, but extra-unsafe as it returns `undef` when
@@ -1240,30 +1267,36 @@ extern "rust-intrinsic" {
1240
1267
/// let num_trailing = unsafe { cttz_nonzero(x) };
1241
1268
/// assert_eq!(num_trailing, 3);
1242
1269
/// ```
1270
+ #[ rustc_const_unstable( feature = "const_cttz" , issue = "0" ) ]
1243
1271
pub fn cttz_nonzero < T > ( x : T ) -> T ;
1244
1272
1245
1273
/// Reverses the bytes in an integer type `T`.
1274
+ #[ rustc_const_stable( feature = "const_bswap" , since = "1.40.0" ) ]
1246
1275
pub fn bswap < T > ( x : T ) -> T ;
1247
1276
1248
1277
/// Reverses the bits in an integer type `T`.
1278
+ #[ rustc_const_stable( feature = "const_bitreverse" , since = "1.40.0" ) ]
1249
1279
pub fn bitreverse < T > ( x : T ) -> T ;
1250
1280
1251
1281
/// Performs checked integer addition.
1252
1282
/// The stabilized versions of this intrinsic are available on the integer
1253
1283
/// primitives via the `overflowing_add` method. For example,
1254
1284
/// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1285
+ #[ rustc_const_stable( feature = "const_int_overflow" , since = "1.40.0" ) ]
1255
1286
pub fn add_with_overflow < T > ( x : T , y : T ) -> ( T , bool ) ;
1256
1287
1257
1288
/// Performs checked integer subtraction
1258
1289
/// The stabilized versions of this intrinsic are available on the integer
1259
1290
/// primitives via the `overflowing_sub` method. For example,
1260
1291
/// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1292
+ #[ rustc_const_stable( feature = "const_int_overflow" , since = "1.40.0" ) ]
1261
1293
pub fn sub_with_overflow < T > ( x : T , y : T ) -> ( T , bool ) ;
1262
1294
1263
1295
/// Performs checked integer multiplication
1264
1296
/// The stabilized versions of this intrinsic are available on the integer
1265
1297
/// primitives via the `overflowing_mul` method. For example,
1266
1298
/// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1299
+ #[ rustc_const_stable( feature = "const_int_overflow" , since = "1.40.0" ) ]
1267
1300
pub fn mul_with_overflow < T > ( x : T , y : T ) -> ( T , bool ) ;
1268
1301
1269
1302
/// Performs an exact division, resulting in undefined behavior where
@@ -1279,9 +1312,11 @@ extern "rust-intrinsic" {
1279
1312
1280
1313
/// Performs an unchecked left shift, resulting in undefined behavior when
1281
1314
/// y < 0 or y >= N, where N is the width of T in bits.
1315
+ #[ rustc_const_stable( feature = "const_int_unchecked" , since = "1.40.0" ) ]
1282
1316
pub fn unchecked_shl < T > ( x : T , y : T ) -> T ;
1283
1317
/// Performs an unchecked right shift, resulting in undefined behavior when
1284
1318
/// y < 0 or y >= N, where N is the width of T in bits.
1319
+ #[ rustc_const_stable( feature = "const_int_unchecked" , since = "1.40.0" ) ]
1285
1320
pub fn unchecked_shr < T > ( x : T , y : T ) -> T ;
1286
1321
1287
1322
/// Returns the result of an unchecked addition, resulting in
@@ -1300,39 +1335,46 @@ extern "rust-intrinsic" {
1300
1335
/// The stabilized versions of this intrinsic are available on the integer
1301
1336
/// primitives via the `rotate_left` method. For example,
1302
1337
/// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1338
+ #[ rustc_const_stable( feature = "const_int_rotate" , since = "1.40.0" ) ]
1303
1339
pub fn rotate_left < T > ( x : T , y : T ) -> T ;
1304
1340
1305
1341
/// Performs rotate right.
1306
1342
/// The stabilized versions of this intrinsic are available on the integer
1307
1343
/// primitives via the `rotate_right` method. For example,
1308
1344
/// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1345
+ #[ rustc_const_stable( feature = "const_int_rotate" , since = "1.40.0" ) ]
1309
1346
pub fn rotate_right < T > ( x : T , y : T ) -> T ;
1310
1347
1311
1348
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1312
1349
/// The stabilized versions of this intrinsic are available on the integer
1313
1350
/// primitives via the `wrapping_add` method. For example,
1314
1351
/// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
1352
+ #[ rustc_const_stable( feature = "const_int_wrapping" , since = "1.40.0" ) ]
1315
1353
pub fn wrapping_add < T > ( a : T , b : T ) -> T ;
1316
1354
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1317
1355
/// The stabilized versions of this intrinsic are available on the integer
1318
1356
/// primitives via the `wrapping_sub` method. For example,
1319
1357
/// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
1358
+ #[ rustc_const_stable( feature = "const_int_wrapping" , since = "1.40.0" ) ]
1320
1359
pub fn wrapping_sub < T > ( a : T , b : T ) -> T ;
1321
1360
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1322
1361
/// The stabilized versions of this intrinsic are available on the integer
1323
1362
/// primitives via the `wrapping_mul` method. For example,
1324
1363
/// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
1364
+ #[ rustc_const_stable( feature = "const_int_wrapping" , since = "1.40.0" ) ]
1325
1365
pub fn wrapping_mul < T > ( a : T , b : T ) -> T ;
1326
1366
1327
1367
/// Computes `a + b`, while saturating at numeric bounds.
1328
1368
/// The stabilized versions of this intrinsic are available on the integer
1329
1369
/// primitives via the `saturating_add` method. For example,
1330
1370
/// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1371
+ #[ rustc_const_stable( feature = "const_int_saturating" , since = "1.40.0" ) ]
1331
1372
pub fn saturating_add < T > ( a : T , b : T ) -> T ;
1332
1373
/// Computes `a - b`, while saturating at numeric bounds.
1333
1374
/// The stabilized versions of this intrinsic are available on the integer
1334
1375
/// primitives via the `saturating_sub` method. For example,
1335
1376
/// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1377
+ #[ rustc_const_stable( feature = "const_int_saturating" , since = "1.40.0" ) ]
1336
1378
pub fn saturating_sub < T > ( a : T , b : T ) -> T ;
1337
1379
1338
1380
/// Returns the value of the discriminant for the variant in 'v',
@@ -1354,6 +1396,7 @@ extern "rust-intrinsic" {
1354
1396
pub fn nontemporal_store < T > ( ptr : * mut T , val : T ) ;
1355
1397
1356
1398
/// See documentation of `<*const T>::offset_from` for details.
1399
+ #[ rustc_const_unstable( feature = "const_ptr_offset_from" , issue = "0" ) ]
1357
1400
pub fn ptr_offset_from < T > ( ptr : * const T , base : * const T ) -> isize ;
1358
1401
1359
1402
/// Internal hook used by Miri to implement unwinding.
0 commit comments