Skip to content

Commit 86cbec1

Browse files
authored
Unrolled build for rust-lang#121192
Rollup merge of rust-lang#121192 - oli-obk:intrinsics2.0, r=WaffleLapkin Give some intrinsics fallback bodies cc rust-lang#93145
2 parents dfdbe30 + dd40a80 commit 86cbec1

File tree

6 files changed

+84
-69
lines changed

6 files changed

+84
-69
lines changed

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ pub fn check_intrinsic_type(
407407
}
408408
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),
409409

410-
sym::assume => (0, 0, vec![tcx.types.bool], Ty::new_unit(tcx)),
411-
sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
412-
sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
410+
sym::assume => (0, 1, vec![tcx.types.bool], Ty::new_unit(tcx)),
411+
sym::likely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
412+
sym::unlikely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
413413

414414
sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
415415
sym::write_via_move => {

library/core/src/intrinsics.rs

+59-43
Original file line numberDiff line numberDiff line change
@@ -937,52 +937,68 @@ extern "rust-intrinsic" {
937937
#[rustc_nounwind]
938938
pub fn unreachable() -> !;
939939

940-
/// Informs the optimizer that a condition is always true.
941-
/// If the condition is false, the behavior is undefined.
942-
///
943-
/// No code is generated for this intrinsic, but the optimizer will try
944-
/// to preserve it (and its condition) between passes, which may interfere
945-
/// with optimization of surrounding code and reduce performance. It should
946-
/// not be used if the invariant can be discovered by the optimizer on its
947-
/// own, or if it does not enable any significant optimizations.
948-
///
949-
/// This intrinsic does not have a stable counterpart.
950-
#[rustc_const_stable(feature = "const_assume", since = "1.77.0")]
951-
#[rustc_nounwind]
952-
pub fn assume(b: bool);
940+
}
953941

954-
/// Hints to the compiler that branch condition is likely to be true.
955-
/// Returns the value passed to it.
956-
///
957-
/// Any use other than with `if` statements will probably not have an effect.
958-
///
959-
/// Note that, unlike most intrinsics, this is safe to call;
960-
/// it does not require an `unsafe` block.
961-
/// Therefore, implementations must not require the user to uphold
962-
/// any safety invariants.
963-
///
964-
/// This intrinsic does not have a stable counterpart.
965-
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
966-
#[rustc_safe_intrinsic]
967-
#[rustc_nounwind]
968-
pub fn likely(b: bool) -> bool;
942+
/// Informs the optimizer that a condition is always true.
943+
/// If the condition is false, the behavior is undefined.
944+
///
945+
/// No code is generated for this intrinsic, but the optimizer will try
946+
/// to preserve it (and its condition) between passes, which may interfere
947+
/// with optimization of surrounding code and reduce performance. It should
948+
/// not be used if the invariant can be discovered by the optimizer on its
949+
/// own, or if it does not enable any significant optimizations.
950+
///
951+
/// This intrinsic does not have a stable counterpart.
952+
#[rustc_const_stable(feature = "const_assume", since = "1.77.0")]
953+
#[rustc_nounwind]
954+
#[unstable(feature = "core_intrinsics", issue = "none")]
955+
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
956+
pub const unsafe fn assume(b: bool) {
957+
if !b {
958+
// SAFETY: the caller must guarantee the argument is never `false`
959+
unsafe { unreachable() }
960+
}
961+
}
969962

970-
/// Hints to the compiler that branch condition is likely to be false.
971-
/// Returns the value passed to it.
972-
///
973-
/// Any use other than with `if` statements will probably not have an effect.
974-
///
975-
/// Note that, unlike most intrinsics, this is safe to call;
976-
/// it does not require an `unsafe` block.
977-
/// Therefore, implementations must not require the user to uphold
978-
/// any safety invariants.
979-
///
980-
/// This intrinsic does not have a stable counterpart.
981-
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
982-
#[rustc_safe_intrinsic]
983-
#[rustc_nounwind]
984-
pub fn unlikely(b: bool) -> bool;
963+
/// Hints to the compiler that branch condition is likely to be true.
964+
/// Returns the value passed to it.
965+
///
966+
/// Any use other than with `if` statements will probably not have an effect.
967+
///
968+
/// Note that, unlike most intrinsics, this is safe to call;
969+
/// it does not require an `unsafe` block.
970+
/// Therefore, implementations must not require the user to uphold
971+
/// any safety invariants.
972+
///
973+
/// This intrinsic does not have a stable counterpart.
974+
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
975+
#[unstable(feature = "core_intrinsics", issue = "none")]
976+
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
977+
#[rustc_nounwind]
978+
pub const fn likely(b: bool) -> bool {
979+
b
980+
}
981+
982+
/// Hints to the compiler that branch condition is likely to be false.
983+
/// Returns the value passed to it.
984+
///
985+
/// Any use other than with `if` statements will probably not have an effect.
986+
///
987+
/// Note that, unlike most intrinsics, this is safe to call;
988+
/// it does not require an `unsafe` block.
989+
/// Therefore, implementations must not require the user to uphold
990+
/// any safety invariants.
991+
///
992+
/// This intrinsic does not have a stable counterpart.
993+
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
994+
#[unstable(feature = "core_intrinsics", issue = "none")]
995+
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
996+
#[rustc_nounwind]
997+
pub const fn unlikely(b: bool) -> bool {
998+
b
999+
}
9851000

1001+
extern "rust-intrinsic" {
9861002
/// Executes a breakpoint trap, for inspection by a debugger.
9871003
///
9881004
/// This intrinsic does not have a stable counterpart.

tests/ui/intrinsics/safe-intrinsic-mismatch.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
extern "rust-intrinsic" {
66
fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch
77
//~^ ERROR intrinsic safety mismatch
8-
9-
#[rustc_safe_intrinsic]
10-
fn assume(b: bool); //~ ERROR intrinsic safety mismatch
11-
//~^ ERROR intrinsic safety mismatch
128
}
139

10+
#[rustc_intrinsic]
11+
const fn assume(_b: bool) {} //~ ERROR intrinsic safety mismatch
12+
//~| ERROR intrinsic has wrong type
13+
1414
#[rustc_intrinsic]
1515
const fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
1616
//~^ ERROR intrinsic safety mismatch

tests/ui/intrinsics/safe-intrinsic-mismatch.stderr

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ error: intrinsic safety mismatch between list of intrinsics within the compiler
44
LL | fn size_of<T>() -> usize;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
8-
--> $DIR/safe-intrinsic-mismatch.rs:10:5
9-
|
10-
LL | fn assume(b: bool);
11-
| ^^^^^^^^^^^^^^^^^^
12-
137
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
148
--> $DIR/safe-intrinsic-mismatch.rs:6:5
159
|
@@ -19,12 +13,19 @@ LL | fn size_of<T>() -> usize;
1913
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2014

2115
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
22-
--> $DIR/safe-intrinsic-mismatch.rs:10:5
16+
--> $DIR/safe-intrinsic-mismatch.rs:11:1
2317
|
24-
LL | fn assume(b: bool);
25-
| ^^^^^^^^^^^^^^^^^^
18+
LL | const fn assume(_b: bool) {}
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
error[E0308]: intrinsic has wrong type
22+
--> $DIR/safe-intrinsic-mismatch.rs:11:16
2623
|
27-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
24+
LL | const fn assume(_b: bool) {}
25+
| ^ expected unsafe fn, found normal fn
26+
|
27+
= note: expected signature `unsafe fn(_)`
28+
found signature `fn(_)`
2829

2930
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `const_deallocate`
3031
--> $DIR/safe-intrinsic-mismatch.rs:15:1

tests/ui/reify-intrinsic.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ fn b() {
1313
}
1414

1515
fn c() {
16-
let _ = [
17-
std::intrinsics::likely,
16+
let _: [unsafe extern "rust-intrinsic" fn(bool) -> bool; 2] = [
17+
std::intrinsics::likely, //~ ERROR cannot coerce
1818
std::intrinsics::unlikely,
19-
//~^ ERROR cannot coerce
2019
];
2120
}
2221

tests/ui/reify-intrinsic.stderr

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize)
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error[E0308]: cannot coerce intrinsics to function pointers
19-
--> $DIR/reify-intrinsic.rs:18:9
19+
--> $DIR/reify-intrinsic.rs:17:9
2020
|
21-
LL | std::intrinsics::unlikely,
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
21+
LL | std::intrinsics::likely,
22+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
2323
|
24-
= note: expected fn item `extern "rust-intrinsic" fn(_) -> _ {likely}`
25-
found fn item `extern "rust-intrinsic" fn(_) -> _ {unlikely}`
26-
= note: different fn items have unique types, even if their signatures are the same
24+
= note: expected fn pointer `unsafe extern "rust-intrinsic" fn(_) -> _`
25+
found fn item `fn(_) -> _ {likely}`
2726

2827
error: aborting due to 3 previous errors
2928

0 commit comments

Comments
 (0)