diff options
| author | bors <bors@rust-lang.org> | 2024-04-05 04:34:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-05 04:34:05 +0000 |
| commit | c0ddaef075748674140263840a185082f44458e9 (patch) | |
| tree | 05868dc091e71c12ae8eec464268f2a755949110 /compiler | |
| parent | 3d7e88148a00c99e444c8f287d73ebe1846bc7aa (diff) | |
| parent | b0b7c860e13858cbc344dcf2baf860752e3a2dd3 (diff) | |
| download | rust-c0ddaef075748674140263840a185082f44458e9.tar.gz rust-c0ddaef075748674140263840a185082f44458e9.zip | |
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
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_transform/src/inline/cycle.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index 7a1340f3a55..99c7b616f1b 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -5,6 +5,7 @@ use rustc_middle::mir::TerminatorKind; use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::{self, GenericArgsRef, InstanceDef, TyCtxt}; use rustc_session::Limit; +use rustc_span::sym; // FIXME: check whether it is cheaper to precompute the entire call graph instead of invoking // this query ridiculously often. @@ -164,11 +165,20 @@ pub(crate) fn mir_inliner_callees<'tcx>( let mut calls = FxIndexSet::default(); for bb_data in body.basic_blocks.iter() { 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 call = match ty.kind() { - ty::FnDef(def_id, args) => (*def_id, *args), - _ => continue, + let ty::FnDef(def_id, generic_args) = ty.kind() else { + 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); } |
