Skip to content

Commit 08f365c

Browse files
committed
validator: move force inline check
1 parent da261aa commit 08f365c

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

compiler/rustc_mir_transform/src/inline.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,6 @@ fn process_blocks<'tcx, I: Inliner<'tcx>>(
502502
let span = trace_span!("process_blocks", %callsite.callee, ?bb);
503503
let _guard = span.enter();
504504

505-
if !inliner.should_inline_for_callee(callsite.callee.def_id()) {
506-
debug!("not enabled");
507-
continue;
508-
}
509-
510505
match try_inlining(inliner, caller_body, &callsite) {
511506
Err(reason) => {
512507
debug!("not-inlined {} [{}]", callsite.callee, reason);
@@ -541,6 +536,11 @@ fn resolve_callsite<'tcx, I: Inliner<'tcx>>(
541536
if let TerminatorKind::Call { ref func, fn_span, .. } = terminator.kind {
542537
let func_ty = func.ty(caller_body, tcx);
543538
if let ty::FnDef(def_id, args) = *func_ty.kind() {
539+
if !inliner.should_inline_for_callee(def_id) {
540+
debug!("not enabled");
541+
return None;
542+
}
543+
544544
// To resolve an instance its args have to be fully normalized.
545545
let args = tcx.try_normalize_erasing_regions(inliner.typing_env(), args).ok()?;
546546
let callee =

compiler/rustc_mir_transform/src/validate.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
8080
cfg_checker.fail(location, msg);
8181
}
8282

83-
if let MirPhase::Runtime(phase) = body.phase {
83+
if let MirPhase::Runtime(_) = body.phase {
8484
if let ty::InstanceKind::Item(_) = body.source.instance {
8585
if body.has_free_regions() {
8686
cfg_checker.fail(
@@ -89,27 +89,6 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
8989
);
9090
}
9191
}
92-
93-
if phase >= RuntimePhase::Optimized
94-
&& body
95-
.basic_blocks
96-
.iter()
97-
.filter_map(|bb| match &bb.terminator().kind {
98-
TerminatorKind::Call { func, .. }
99-
| TerminatorKind::TailCall { func, .. } => Some(func),
100-
_ => None,
101-
})
102-
.filter_map(|func| match func.ty(&body.local_decls, tcx).kind() {
103-
ty::FnDef(did, ..) => Some(did),
104-
_ => None,
105-
})
106-
.any(|did| matches!(tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. }))
107-
{
108-
cfg_checker.fail(
109-
Location::START,
110-
"`#[rustc_force_inline]`-annotated function not inlined",
111-
);
112-
}
11392
}
11493
}
11594
}
@@ -388,7 +367,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
388367
self.check_edge(location, *target, EdgeKind::Normal);
389368
self.check_unwind_edge(location, *unwind);
390369
}
391-
TerminatorKind::Call { args, .. } | TerminatorKind::TailCall { args, .. } => {
370+
TerminatorKind::Call { func, args, .. }
371+
| TerminatorKind::TailCall { func, args, .. } => {
392372
// FIXME(explicit_tail_calls): refactor this & add tail-call specific checks
393373
if let TerminatorKind::Call { target, unwind, destination, .. } = terminator.kind {
394374
if let Some(target) = target {
@@ -441,6 +421,13 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
441421
}
442422
}
443423
}
424+
425+
if let ty::FnDef(did, ..) = func.ty(&self.body.local_decls, self.tcx).kind()
426+
&& self.body.phase >= MirPhase::Runtime(RuntimePhase::Optimized)
427+
&& matches!(self.tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. })
428+
{
429+
self.fail(location, "`#[rustc_force_inline]`-annotated function not inlined");
430+
}
444431
}
445432
TerminatorKind::Assert { target, unwind, .. } => {
446433
self.check_edge(location, *target, EdgeKind::Normal);

0 commit comments

Comments
 (0)