Skip to content

Commit

Permalink
validator: move force inline check
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtwco committed Dec 12, 2024
1 parent da261aa commit 08f365c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,6 @@ fn process_blocks<'tcx, I: Inliner<'tcx>>(
let span = trace_span!("process_blocks", %callsite.callee, ?bb);
let _guard = span.enter();

if !inliner.should_inline_for_callee(callsite.callee.def_id()) {
debug!("not enabled");
continue;
}

match try_inlining(inliner, caller_body, &callsite) {
Err(reason) => {
debug!("not-inlined {} [{}]", callsite.callee, reason);
Expand Down Expand Up @@ -541,6 +536,11 @@ fn resolve_callsite<'tcx, I: Inliner<'tcx>>(
if let TerminatorKind::Call { ref func, fn_span, .. } = terminator.kind {
let func_ty = func.ty(caller_body, tcx);
if let ty::FnDef(def_id, args) = *func_ty.kind() {
if !inliner.should_inline_for_callee(def_id) {
debug!("not enabled");
return None;
}

// To resolve an instance its args have to be fully normalized.
let args = tcx.try_normalize_erasing_regions(inliner.typing_env(), args).ok()?;
let callee =
Expand Down
33 changes: 10 additions & 23 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
cfg_checker.fail(location, msg);
}

if let MirPhase::Runtime(phase) = body.phase {
if let MirPhase::Runtime(_) = body.phase {
if let ty::InstanceKind::Item(_) = body.source.instance {
if body.has_free_regions() {
cfg_checker.fail(
Expand All @@ -89,27 +89,6 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
);
}
}

if phase >= RuntimePhase::Optimized
&& body
.basic_blocks
.iter()
.filter_map(|bb| match &bb.terminator().kind {
TerminatorKind::Call { func, .. }
| TerminatorKind::TailCall { func, .. } => Some(func),
_ => None,
})
.filter_map(|func| match func.ty(&body.local_decls, tcx).kind() {
ty::FnDef(did, ..) => Some(did),
_ => None,
})
.any(|did| matches!(tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. }))
{
cfg_checker.fail(
Location::START,
"`#[rustc_force_inline]`-annotated function not inlined",
);
}
}
}
}
Expand Down Expand Up @@ -388,7 +367,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
self.check_edge(location, *target, EdgeKind::Normal);
self.check_unwind_edge(location, *unwind);
}
TerminatorKind::Call { args, .. } | TerminatorKind::TailCall { args, .. } => {
TerminatorKind::Call { func, args, .. }
| TerminatorKind::TailCall { func, args, .. } => {
// FIXME(explicit_tail_calls): refactor this & add tail-call specific checks
if let TerminatorKind::Call { target, unwind, destination, .. } = terminator.kind {
if let Some(target) = target {
Expand Down Expand Up @@ -441,6 +421,13 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
}
}
}

if let ty::FnDef(did, ..) = func.ty(&self.body.local_decls, self.tcx).kind()
&& self.body.phase >= MirPhase::Runtime(RuntimePhase::Optimized)
&& matches!(self.tcx.codegen_fn_attrs(did).inline, InlineAttr::Force { .. })
{
self.fail(location, "`#[rustc_force_inline]`-annotated function not inlined");
}
}
TerminatorKind::Assert { target, unwind, .. } => {
self.check_edge(location, *target, EdgeKind::Normal);
Expand Down

0 comments on commit 08f365c

Please sign in to comment.