1
Fork 0

Give the (un)likely intrinsics fallback bodies

This commit is contained in:
Oli Scherer 2024-02-16 17:45:46 +00:00
parent 6a671bdbf1
commit dd40a80102
6 changed files with 62 additions and 57 deletions

View file

@ -408,8 +408,8 @@ pub fn check_intrinsic_type(
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)), sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),
sym::assume => (0, 1, vec![tcx.types.bool], Ty::new_unit(tcx)), sym::assume => (0, 1, vec![tcx.types.bool], Ty::new_unit(tcx)),
sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool), sym::likely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool), sym::unlikely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)), sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
sym::write_via_move => { sym::write_via_move => {

View file

@ -960,7 +960,6 @@ pub const unsafe fn assume(b: bool) {
} }
} }
extern "rust-intrinsic" {
/// Hints to the compiler that branch condition is likely to be true. /// Hints to the compiler that branch condition is likely to be true.
/// Returns the value passed to it. /// Returns the value passed to it.
/// ///
@ -973,9 +972,12 @@ extern "rust-intrinsic" {
/// ///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_likely", issue = "none")] #[rustc_const_unstable(feature = "const_likely", issue = "none")]
#[rustc_safe_intrinsic] #[unstable(feature = "core_intrinsics", issue = "none")]
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
#[rustc_nounwind] #[rustc_nounwind]
pub fn likely(b: bool) -> bool; pub const fn likely(b: bool) -> bool {
b
}
/// Hints to the compiler that branch condition is likely to be false. /// Hints to the compiler that branch condition is likely to be false.
/// Returns the value passed to it. /// Returns the value passed to it.
@ -989,10 +991,14 @@ extern "rust-intrinsic" {
/// ///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_likely", issue = "none")] #[rustc_const_unstable(feature = "const_likely", issue = "none")]
#[rustc_safe_intrinsic] #[unstable(feature = "core_intrinsics", issue = "none")]
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
#[rustc_nounwind] #[rustc_nounwind]
pub fn unlikely(b: bool) -> bool; pub const fn unlikely(b: bool) -> bool {
b
}
extern "rust-intrinsic" {
/// Executes a breakpoint trap, for inspection by a debugger. /// Executes a breakpoint trap, for inspection by a debugger.
/// ///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.

View file

@ -5,12 +5,12 @@
extern "rust-intrinsic" { extern "rust-intrinsic" {
fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch
//~^ ERROR intrinsic safety mismatch //~^ ERROR intrinsic safety mismatch
#[rustc_safe_intrinsic]
fn assume(b: bool); //~ ERROR intrinsic safety mismatch
//~^ ERROR intrinsic safety mismatch
} }
#[rustc_intrinsic]
const fn assume(_b: bool) {} //~ ERROR intrinsic safety mismatch
//~| ERROR intrinsic has wrong type
#[rustc_intrinsic] #[rustc_intrinsic]
const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
//~^ ERROR intrinsic safety mismatch //~^ ERROR intrinsic safety mismatch

View file

@ -4,12 +4,6 @@ error: intrinsic safety mismatch between list of intrinsics within the compiler
LL | fn size_of<T>() -> usize; LL | fn size_of<T>() -> usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
--> $DIR/safe-intrinsic-mismatch.rs:10:5
|
LL | fn assume(b: bool);
| ^^^^^^^^^^^^^^^^^^
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of` error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
--> $DIR/safe-intrinsic-mismatch.rs:6:5 --> $DIR/safe-intrinsic-mismatch.rs:6:5
| |
@ -19,12 +13,19 @@ LL | fn size_of<T>() -> usize;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume` error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
--> $DIR/safe-intrinsic-mismatch.rs:10:5 --> $DIR/safe-intrinsic-mismatch.rs:11:1
| |
LL | fn assume(b: bool); LL | const fn assume(_b: bool) {}
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: intrinsic has wrong type
--> $DIR/safe-intrinsic-mismatch.rs:11:16
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` LL | const fn assume(_b: bool) {}
| ^ expected unsafe fn, found normal fn
|
= note: expected signature `unsafe fn(_)`
found signature `fn(_)`
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate` error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate`
--> $DIR/safe-intrinsic-mismatch.rs:15:1 --> $DIR/safe-intrinsic-mismatch.rs:15:1

View file

@ -13,10 +13,9 @@ fn b() {
} }
fn c() { fn c() {
let _ = [ let _: [unsafe extern "rust-intrinsic" fn(bool) -> bool; 2] = [
std::intrinsics::likely, std::intrinsics::likely, //~ ERROR cannot coerce
std::intrinsics::unlikely, std::intrinsics::unlikely,
//~^ ERROR cannot coerce
]; ];
} }

View file

@ -16,14 +16,13 @@ LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: cannot coerce intrinsics to function pointers error[E0308]: cannot coerce intrinsics to function pointers
--> $DIR/reify-intrinsic.rs:18:9 --> $DIR/reify-intrinsic.rs:17:9
| |
LL | std::intrinsics::unlikely, LL | std::intrinsics::likely,
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers | ^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
| |
= note: expected fn item `extern "rust-intrinsic" fn(_) -> _ {likely}` = note: expected fn pointer `unsafe extern "rust-intrinsic" fn(_) -> _`
found fn item `extern "rust-intrinsic" fn(_) -> _ {unlikely}` found fn item `fn(_) -> _ {likely}`
= note: different fn items have unique types, even if their signatures are the same
error: aborting due to 3 previous errors error: aborting due to 3 previous errors