1
Fork 0

Make likely and unlikely const

They are gated by internal feature gate const_likely
This commit is contained in:
Gary Guo 2020-06-26 13:19:50 +01:00
parent 224bc05256
commit fc239e82fe
4 changed files with 10 additions and 0 deletions

View file

@ -952,6 +952,7 @@ extern "rust-intrinsic" {
/// Any use other than with `if` statements will probably not have an effect.
///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
pub fn likely(b: bool) -> bool;
/// Hints to the compiler that branch condition is likely to be false.
@ -960,6 +961,7 @@ extern "rust-intrinsic" {
/// Any use other than with `if` statements will probably not have an effect.
///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
pub fn unlikely(b: bool) -> bool;
/// Executes a breakpoint trap, for inspection by a debugger.

View file

@ -92,6 +92,7 @@
#![feature(const_slice_from_raw_parts)]
#![feature(const_slice_ptr_len)]
#![feature(const_type_name)]
#![feature(const_likely)]
#![feature(custom_inner_attributes)]
#![feature(decl_macro)]
#![feature(doc_cfg)]

View file

@ -399,6 +399,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
);
self.copy_op(self.operand_index(args[0], index)?, dest)?;
}
sym::likely | sym::unlikely => {
// These just return their argument
let a = self.read_immediate(args[0])?;
self.write_immediate(*a, dest)?;
}
// FIXME(#73156): Handle source code coverage in const eval
sym::count_code_region => (),
_ => return Ok(false),

View file

@ -427,6 +427,7 @@ symbols! {
lhs,
lib,
lifetime,
likely,
line,
link,
linkage,
@ -813,6 +814,7 @@ symbols! {
underscore_lifetimes,
uniform_paths,
universal_impl_trait,
unlikely,
unmarked_api,
unreachable_code,
unrestricted_attribute_tokens,