mir_transform: implement forced inlining
Adds `#[rustc_force_inline]` which is similar to always inlining but reports an error if the inlining was not possible, and which always attempts to inline annotated items, regardless of optimisation levels. It can only be applied to free functions to guarantee that the MIR inliner will be able to resolve calls.
This commit is contained in:
parent
336209eef1
commit
f86169a58f
47 changed files with 2130 additions and 709 deletions
|
@ -207,6 +207,7 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_attr_parsing::InlineAttr;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sync::{LRef, MTLock, par_for_each_in};
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
|
@ -959,6 +960,14 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
|
|||
return false;
|
||||
}
|
||||
|
||||
if tcx.def_kind(def_id).has_codegen_attrs()
|
||||
&& matches!(tcx.codegen_fn_attrs(def_id).inline, InlineAttr::Force { .. })
|
||||
{
|
||||
// `#[rustc_force_inline]` items should never be codegened. This should be caught by
|
||||
// the MIR validator.
|
||||
return false;
|
||||
}
|
||||
|
||||
if def_id.is_local() {
|
||||
// Local items cannot be referred to locally without monomorphizing them locally.
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue