Skip to content

Commit 87fcd2f

Browse files
committed
Move a few intrinsics to use Rust abi
Move a few more intrinsic functions to the convention added in rust-lang#121192 where they have Rust abi but are tagged with `rustc_intrinsic`.
1 parent de4f5c2 commit 87fcd2f

File tree

1 file changed

+146
-57
lines changed

1 file changed

+146
-57
lines changed

core/src/intrinsics.rs

+146-57
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,6 @@ extern "rust-intrinsic" {
947947
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
948948
#[rustc_nounwind]
949949
pub fn unreachable() -> !;
950-
951950
}
952951

953952
/// Informs the optimizer that a condition is always true.
@@ -1018,78 +1017,40 @@ extern "rust-intrinsic" {
10181017
#[rustc_nounwind]
10191018
pub fn breakpoint();
10201019

1021-
/// The size of a type in bytes.
1022-
///
1023-
/// Note that, unlike most intrinsics, this is safe to call;
1024-
/// it does not require an `unsafe` block.
1025-
/// Therefore, implementations must not require the user to uphold
1026-
/// any safety invariants.
1027-
///
1028-
/// More specifically, this is the offset in bytes between successive
1029-
/// items of the same type, including alignment padding.
1030-
///
1031-
/// The stabilized version of this intrinsic is [`core::mem::size_of`].
1020+
#[cfg(bootstrap)]
10321021
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
10331022
#[rustc_safe_intrinsic]
10341023
#[rustc_nounwind]
10351024
pub fn size_of<T>() -> usize;
10361025

1037-
/// The minimum alignment of a type.
1038-
///
1039-
/// Note that, unlike most intrinsics, this is safe to call;
1040-
/// it does not require an `unsafe` block.
1041-
/// Therefore, implementations must not require the user to uphold
1042-
/// any safety invariants.
1043-
///
1044-
/// The stabilized version of this intrinsic is [`core::mem::align_of`].
1026+
#[cfg(bootstrap)]
10451027
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
10461028
#[rustc_safe_intrinsic]
10471029
#[rustc_nounwind]
10481030
pub fn min_align_of<T>() -> usize;
1049-
/// The preferred alignment of a type.
1050-
///
1051-
/// This intrinsic does not have a stable counterpart.
1052-
/// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
1031+
1032+
#[cfg(bootstrap)]
10531033
#[rustc_const_unstable(feature = "const_pref_align_of", issue = "91971")]
10541034
#[rustc_nounwind]
10551035
pub fn pref_align_of<T>() -> usize;
10561036

1057-
/// The size of the referenced value in bytes.
1058-
///
1059-
/// The stabilized version of this intrinsic is [`crate::mem::size_of_val`].
1037+
#[cfg(bootstrap)]
10601038
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
10611039
#[rustc_nounwind]
10621040
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
1063-
/// The required alignment of the referenced value.
1064-
///
1065-
/// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
1041+
1042+
#[cfg(bootstrap)]
10661043
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
10671044
#[rustc_nounwind]
10681045
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
10691046

1070-
/// Gets a static string slice containing the name of a type.
1071-
///
1072-
/// Note that, unlike most intrinsics, this is safe to call;
1073-
/// it does not require an `unsafe` block.
1074-
/// Therefore, implementations must not require the user to uphold
1075-
/// any safety invariants.
1076-
///
1077-
/// The stabilized version of this intrinsic is [`core::any::type_name`].
1047+
#[cfg(bootstrap)]
10781048
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
10791049
#[rustc_safe_intrinsic]
10801050
#[rustc_nounwind]
10811051
pub fn type_name<T: ?Sized>() -> &'static str;
10821052

1083-
/// Gets an identifier which is globally unique to the specified type. This
1084-
/// function will return the same value for a type regardless of whichever
1085-
/// crate it is invoked in.
1086-
///
1087-
/// Note that, unlike most intrinsics, this is safe to call;
1088-
/// it does not require an `unsafe` block.
1089-
/// Therefore, implementations must not require the user to uphold
1090-
/// any safety invariants.
1091-
///
1092-
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
1053+
#[cfg(bootstrap)]
10931054
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
10941055
#[rustc_safe_intrinsic]
10951056
#[rustc_nounwind]
@@ -2424,15 +2385,7 @@ extern "rust-intrinsic" {
24242385
#[rustc_nounwind]
24252386
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
24262387

2427-
/// Returns the number of variants of the type `T` cast to a `usize`;
2428-
/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
2429-
///
2430-
/// Note that, unlike most intrinsics, this is safe to call;
2431-
/// it does not require an `unsafe` block.
2432-
/// Therefore, implementations must not require the user to uphold
2433-
/// any safety invariants.
2434-
///
2435-
/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
2388+
#[cfg(bootstrap)]
24362389
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
24372390
#[rustc_safe_intrinsic]
24382391
#[rustc_nounwind]
@@ -2793,6 +2746,142 @@ pub unsafe fn vtable_align(_ptr: *const ()) -> usize {
27932746
unreachable!()
27942747
}
27952748

2749+
/// The size of a type in bytes.
2750+
///
2751+
/// Note that, unlike most intrinsics, this is safe to call;
2752+
/// it does not require an `unsafe` block.
2753+
/// Therefore, implementations must not require the user to uphold
2754+
/// any safety invariants.
2755+
///
2756+
/// More specifically, this is the offset in bytes between successive
2757+
/// items of the same type, including alignment padding.
2758+
///
2759+
/// The stabilized version of this intrinsic is [`core::mem::size_of`].
2760+
#[rustc_nounwind]
2761+
#[unstable(feature = "core_intrinsics", issue = "none")]
2762+
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
2763+
#[rustc_intrinsic]
2764+
#[rustc_intrinsic_must_be_overridden]
2765+
#[cfg(not(bootstrap))]
2766+
pub const fn size_of<T>() -> usize {
2767+
unreachable!()
2768+
}
2769+
2770+
/// The minimum alignment of a type.
2771+
///
2772+
/// Note that, unlike most intrinsics, this is safe to call;
2773+
/// it does not require an `unsafe` block.
2774+
/// Therefore, implementations must not require the user to uphold
2775+
/// any safety invariants.
2776+
///
2777+
/// The stabilized version of this intrinsic is [`core::mem::align_of`].
2778+
#[rustc_nounwind]
2779+
#[unstable(feature = "core_intrinsics", issue = "none")]
2780+
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
2781+
#[rustc_intrinsic]
2782+
#[rustc_intrinsic_must_be_overridden]
2783+
#[cfg(not(bootstrap))]
2784+
pub const fn min_align_of<T>() -> usize {
2785+
unreachable!()
2786+
}
2787+
2788+
/// The preferred alignment of a type.
2789+
///
2790+
/// This intrinsic does not have a stable counterpart.
2791+
/// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
2792+
#[rustc_nounwind]
2793+
#[unstable(feature = "core_intrinsics", issue = "none")]
2794+
#[rustc_const_unstable(feature = "const_pref_align_of", issue = "91971")]
2795+
#[rustc_intrinsic]
2796+
#[rustc_intrinsic_must_be_overridden]
2797+
#[cfg(not(bootstrap))]
2798+
pub const unsafe fn pref_align_of<T>() -> usize {
2799+
unreachable!()
2800+
}
2801+
2802+
/// Returns the number of variants of the type `T` cast to a `usize`;
2803+
/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
2804+
///
2805+
/// Note that, unlike most intrinsics, this is safe to call;
2806+
/// it does not require an `unsafe` block.
2807+
/// Therefore, implementations must not require the user to uphold
2808+
/// any safety invariants.
2809+
///
2810+
/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
2811+
#[rustc_nounwind]
2812+
#[unstable(feature = "core_intrinsics", issue = "none")]
2813+
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
2814+
#[rustc_intrinsic]
2815+
#[rustc_intrinsic_must_be_overridden]
2816+
#[cfg(not(bootstrap))]
2817+
pub const fn variant_count<T>() -> usize {
2818+
unreachable!()
2819+
}
2820+
2821+
/// The size of the referenced value in bytes.
2822+
///
2823+
/// The stabilized version of this intrinsic is [`crate::mem::size_of_val`].
2824+
#[rustc_nounwind]
2825+
#[unstable(feature = "core_intrinsics", issue = "none")]
2826+
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
2827+
#[rustc_intrinsic]
2828+
#[rustc_intrinsic_must_be_overridden]
2829+
#[cfg(not(bootstrap))]
2830+
pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
2831+
unreachable!()
2832+
}
2833+
2834+
/// The required alignment of the referenced value.
2835+
///
2836+
/// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
2837+
#[rustc_nounwind]
2838+
#[unstable(feature = "core_intrinsics", issue = "none")]
2839+
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
2840+
#[rustc_intrinsic]
2841+
#[rustc_intrinsic_must_be_overridden]
2842+
#[cfg(not(bootstrap))]
2843+
pub const unsafe fn min_align_of_val<T: ?Sized>(_ptr: *const T) -> usize {
2844+
unreachable!()
2845+
}
2846+
2847+
/// Gets a static string slice containing the name of a type.
2848+
///
2849+
/// Note that, unlike most intrinsics, this is safe to call;
2850+
/// it does not require an `unsafe` block.
2851+
/// Therefore, implementations must not require the user to uphold
2852+
/// any safety invariants.
2853+
///
2854+
/// The stabilized version of this intrinsic is [`core::any::type_name`].
2855+
#[rustc_nounwind]
2856+
#[unstable(feature = "core_intrinsics", issue = "none")]
2857+
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
2858+
#[rustc_intrinsic]
2859+
#[rustc_intrinsic_must_be_overridden]
2860+
#[cfg(not(bootstrap))]
2861+
pub const fn type_name<T: ?Sized>() -> &'static str {
2862+
unreachable!()
2863+
}
2864+
2865+
/// Gets an identifier which is globally unique to the specified type. This
2866+
/// function will return the same value for a type regardless of whichever
2867+
/// crate it is invoked in.
2868+
///
2869+
/// Note that, unlike most intrinsics, this is safe to call;
2870+
/// it does not require an `unsafe` block.
2871+
/// Therefore, implementations must not require the user to uphold
2872+
/// any safety invariants.
2873+
///
2874+
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
2875+
#[rustc_nounwind]
2876+
#[unstable(feature = "core_intrinsics", issue = "none")]
2877+
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
2878+
#[rustc_intrinsic]
2879+
#[rustc_intrinsic_must_be_overridden]
2880+
#[cfg(not(bootstrap))]
2881+
pub const fn type_id<T: ?Sized + 'static>() -> u128 {
2882+
unreachable!()
2883+
}
2884+
27962885
/// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`.
27972886
///
27982887
/// This is used to implement functions like `slice::from_raw_parts_mut` and

0 commit comments

Comments
 (0)