1
Fork 0

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:
David Wood 2024-09-23 18:46:23 +01:00
parent 336209eef1
commit f86169a58f
No known key found for this signature in database
47 changed files with 2130 additions and 709 deletions

View file

@ -251,7 +251,9 @@ trait_selection_no_value_in_rustc_on_unimplemented = this attribute must have a
trait_selection_nothing = {""}
trait_selection_oc_cant_coerce = cannot coerce intrinsics to function pointers
trait_selection_oc_cant_coerce_force_inline =
cannot coerce functions which must be inlined to function pointers
trait_selection_oc_cant_coerce_intrinsic = cannot coerce intrinsics to function pointers
trait_selection_oc_closure_selfref = closure/coroutine type that references itself
trait_selection_oc_const_compat = const not compatible with trait
trait_selection_oc_fn_lang_correct_type = {$lang_item_name ->

View file

@ -2294,7 +2294,7 @@ impl<'tcx> ObligationCause<'tcx> {
{
FailureCode::Error0644
}
TypeError::IntrinsicCast => FailureCode::Error0308,
TypeError::IntrinsicCast | TypeError::ForceInlineCast => FailureCode::Error0308,
_ => FailureCode::Error0308,
},
}
@ -2360,8 +2360,11 @@ impl<'tcx> ObligationCause<'tcx> {
{
ObligationCauseFailureCode::ClosureSelfref { span }
}
TypeError::ForceInlineCast => {
ObligationCauseFailureCode::CantCoerceForceInline { span, subdiags }
}
TypeError::IntrinsicCast => {
ObligationCauseFailureCode::CantCoerce { span, subdiags }
ObligationCauseFailureCode::CantCoerceIntrinsic { span, subdiags }
}
_ => ObligationCauseFailureCode::Generic { span, subdiags },
},

View file

@ -1729,8 +1729,15 @@ pub enum ObligationCauseFailureCode {
#[primary_span]
span: Span,
},
#[diag(trait_selection_oc_cant_coerce, code = E0308)]
CantCoerce {
#[diag(trait_selection_oc_cant_coerce_force_inline, code = E0308)]
CantCoerceForceInline {
#[primary_span]
span: Span,
#[subdiagnostic]
subdiags: Vec<TypeErrorAdditionalDiags>,
},
#[diag(trait_selection_oc_cant_coerce_intrinsic, code = E0308)]
CantCoerceIntrinsic {
#[primary_span]
span: Span,
#[subdiagnostic]