Skip to content

Commit c0ddaef

Browse files
committed
Auto merge of #123444 - saethlin:const-eval-inline-cycles, r=tmiasko
Teach MIR inliner query cycle avoidance about const_eval_select Fixes #122659 r? tmiasko
2 parents 3d7e881 + b0b7c86 commit c0ddaef

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

compiler/rustc_mir_transform/src/inline/cycle.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_middle::mir::TerminatorKind;
55
use rustc_middle::ty::TypeVisitableExt;
66
use rustc_middle::ty::{self, GenericArgsRef, InstanceDef, TyCtxt};
77
use rustc_session::Limit;
8+
use rustc_span::sym;
89

910
// FIXME: check whether it is cheaper to precompute the entire call graph instead of invoking
1011
// this query ridiculously often.
@@ -164,11 +165,20 @@ pub(crate) fn mir_inliner_callees<'tcx>(
164165
let mut calls = FxIndexSet::default();
165166
for bb_data in body.basic_blocks.iter() {
166167
let terminator = bb_data.terminator();
167-
if let TerminatorKind::Call { func, .. } = &terminator.kind {
168+
if let TerminatorKind::Call { func, args: call_args, .. } = &terminator.kind {
168169
let ty = func.ty(&body.local_decls, tcx);
169-
let call = match ty.kind() {
170-
ty::FnDef(def_id, args) => (*def_id, *args),
171-
_ => continue,
170+
let ty::FnDef(def_id, generic_args) = ty.kind() else {
171+
continue;
172+
};
173+
let call = if tcx.is_intrinsic(*def_id, sym::const_eval_select) {
174+
let func = &call_args[2].node;
175+
let ty = func.ty(&body.local_decls, tcx);
176+
let ty::FnDef(def_id, generic_args) = ty.kind() else {
177+
continue;
178+
};
179+
(*def_id, *generic_args)
180+
} else {
181+
(*def_id, *generic_args)
172182
};
173183
calls.insert(call);
174184
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for #122659
2+
//@ build-pass
3+
//@ compile-flags: -O --crate-type=lib
4+
5+
#![feature(core_intrinsics)]
6+
#![feature(const_eval_select)]
7+
8+
use std::intrinsics::const_eval_select;
9+
10+
#[inline]
11+
pub const fn f() {
12+
const_eval_select((), g, g)
13+
}
14+
15+
#[inline]
16+
pub const fn g() {
17+
const_eval_select((), f, f)
18+
}

0 commit comments

Comments
 (0)