Make const_eval_select
a rustc_intrinsic
This commit is contained in:
parent
196ff446d2
commit
7f9830b16c
5 changed files with 95 additions and 71 deletions
|
@ -579,7 +579,7 @@ pub fn check_intrinsic_type(
|
|||
|
||||
sym::is_val_statically_known => (1, 1, vec![param(0)], tcx.types.bool),
|
||||
|
||||
sym::const_eval_select => (4, 0, vec![param(0), param(1), param(2)], param(3)),
|
||||
sym::const_eval_select => (4, 1, vec![param(0), param(1), param(2)], param(3)),
|
||||
|
||||
sym::vtable_size | sym::vtable_align => {
|
||||
(0, 0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
|
||||
|
|
|
@ -1704,12 +1704,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
{
|
||||
for &local_def_id in tcx.mir_keys(()) {
|
||||
if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
|
||||
if tcx.intrinsic(local_def_id).map_or(true, |i| !i.must_be_overridden) {
|
||||
record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <-
|
||||
self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn encode_stability(&mut self, def_id: DefId) {
|
||||
|
|
|
@ -1365,8 +1365,10 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
|
|||
|
||||
fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) {
|
||||
if associated_body(Node::ImplItem(item)).is_some() {
|
||||
if !self.tcx.has_attr(item.owner_id.def_id, sym::rustc_intrinsic_must_be_overridden) {
|
||||
self.body_owners.push(item.owner_id.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
self.impl_items.push(item.impl_item_id());
|
||||
intravisit::walk_impl_item(self, item)
|
||||
|
|
|
@ -2508,6 +2508,19 @@ extern "rust-intrinsic" {
|
|||
#[rustc_nounwind]
|
||||
pub fn vtable_align(ptr: *const ()) -> usize;
|
||||
|
||||
#[cfg(bootstrap)]
|
||||
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
|
||||
#[cfg_attr(not(bootstrap), rustc_safe_intrinsic)]
|
||||
pub fn const_eval_select<ARG: Tuple, F, G, RET>(
|
||||
arg: ARG,
|
||||
called_in_const: F,
|
||||
called_at_rt: G,
|
||||
) -> RET
|
||||
where
|
||||
G: FnOnce<ARG, Output = RET>,
|
||||
F: FnOnce<ARG, Output = RET>;
|
||||
}
|
||||
|
||||
/// Selects which function to call depending on the context.
|
||||
///
|
||||
/// If this function is evaluated at compile-time, then a call to this
|
||||
|
@ -2565,15 +2578,20 @@ extern "rust-intrinsic" {
|
|||
/// Currently such an assertion would always succeed; until Rust decides
|
||||
/// otherwise, that principle should not be violated.
|
||||
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
|
||||
#[cfg_attr(not(bootstrap), rustc_safe_intrinsic)]
|
||||
pub fn const_eval_select<ARG: Tuple, F, G, RET>(
|
||||
arg: ARG,
|
||||
called_in_const: F,
|
||||
called_at_rt: G,
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[cfg(not(bootstrap))]
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_intrinsic_must_be_overridden]
|
||||
pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
|
||||
_arg: ARG,
|
||||
_called_in_const: F,
|
||||
_called_at_rt: G,
|
||||
) -> RET
|
||||
where
|
||||
G: FnOnce<ARG, Output = RET>,
|
||||
F: FnOnce<ARG, Output = RET>;
|
||||
F: FnOnce<ARG, Output = RET>,
|
||||
{
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
/// Returns whether the argument's value is statically known at
|
||||
|
|
|
@ -509,17 +509,19 @@ trait StructuralPartialEq {}
|
|||
|
||||
const fn drop<T: ~const Destruct>(_: T) {}
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
#[rustc_const_stable(feature = "const_eval_select", since = "1.0.0")]
|
||||
#[rustc_safe_intrinsic]
|
||||
fn const_eval_select<ARG: Tuple, F, G, RET>(
|
||||
#[rustc_intrinsic_must_be_overridden]
|
||||
#[rustc_intrinsic]
|
||||
const fn const_eval_select<ARG: Tuple, F, G, RET>(
|
||||
arg: ARG,
|
||||
called_in_const: F,
|
||||
called_at_rt: G,
|
||||
) -> RET
|
||||
where
|
||||
F: const FnOnce<ARG, Output = RET>,
|
||||
G: FnOnce<ARG, Output = RET>;
|
||||
G: FnOnce<ARG, Output = RET>,
|
||||
{
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn test_const_eval_select() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue