Auto merge of #123444 - saethlin:const-eval-inline-cycles, r=tmiasko
Teach MIR inliner query cycle avoidance about const_eval_select Fixes https://github.com/rust-lang/rust/issues/122659 r? tmiasko
This commit is contained in:
commit
c0ddaef075
2 changed files with 32 additions and 4 deletions
|
@ -5,6 +5,7 @@ use rustc_middle::mir::TerminatorKind;
|
||||||
use rustc_middle::ty::TypeVisitableExt;
|
use rustc_middle::ty::TypeVisitableExt;
|
||||||
use rustc_middle::ty::{self, GenericArgsRef, InstanceDef, TyCtxt};
|
use rustc_middle::ty::{self, GenericArgsRef, InstanceDef, TyCtxt};
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
// FIXME: check whether it is cheaper to precompute the entire call graph instead of invoking
|
// FIXME: check whether it is cheaper to precompute the entire call graph instead of invoking
|
||||||
// this query ridiculously often.
|
// this query ridiculously often.
|
||||||
|
@ -164,11 +165,20 @@ pub(crate) fn mir_inliner_callees<'tcx>(
|
||||||
let mut calls = FxIndexSet::default();
|
let mut calls = FxIndexSet::default();
|
||||||
for bb_data in body.basic_blocks.iter() {
|
for bb_data in body.basic_blocks.iter() {
|
||||||
let terminator = bb_data.terminator();
|
let terminator = bb_data.terminator();
|
||||||
if let TerminatorKind::Call { func, .. } = &terminator.kind {
|
if let TerminatorKind::Call { func, args: call_args, .. } = &terminator.kind {
|
||||||
let ty = func.ty(&body.local_decls, tcx);
|
let ty = func.ty(&body.local_decls, tcx);
|
||||||
let call = match ty.kind() {
|
let ty::FnDef(def_id, generic_args) = ty.kind() else {
|
||||||
ty::FnDef(def_id, args) => (*def_id, *args),
|
continue;
|
||||||
_ => continue,
|
};
|
||||||
|
let call = if tcx.is_intrinsic(*def_id, sym::const_eval_select) {
|
||||||
|
let func = &call_args[2].node;
|
||||||
|
let ty = func.ty(&body.local_decls, tcx);
|
||||||
|
let ty::FnDef(def_id, generic_args) = ty.kind() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
(*def_id, *generic_args)
|
||||||
|
} else {
|
||||||
|
(*def_id, *generic_args)
|
||||||
};
|
};
|
||||||
calls.insert(call);
|
calls.insert(call);
|
||||||
}
|
}
|
||||||
|
|
18
tests/ui/mir/const_eval_select_cycle.rs
Normal file
18
tests/ui/mir/const_eval_select_cycle.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Regression test for #122659
|
||||||
|
//@ build-pass
|
||||||
|
//@ compile-flags: -O --crate-type=lib
|
||||||
|
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
#![feature(const_eval_select)]
|
||||||
|
|
||||||
|
use std::intrinsics::const_eval_select;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub const fn f() {
|
||||||
|
const_eval_select((), g, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub const fn g() {
|
||||||
|
const_eval_select((), f, f)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue