From d2221bdfa4c9e8a1ee3ff4775e51345dc226d27d Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 15 May 2025 21:27:02 +0000 Subject: [PATCH 1/3] Hack together inline-always-overrides --- .../rustc_codegen_ssa/src/codegen_attrs.rs | 18 ++++++++++++++++-- .../rustc_const_eval/src/interpret/intern.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 12 ++++++------ .../src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 7 ++++++- compiler/rustc_middle/src/ty/context.rs | 9 +++++++++ .../src/coroutine/by_move_body.rs | 2 +- compiler/rustc_session/src/options.rs | 3 +++ 10 files changed, 45 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 835ffb7d4fc6b..857415980017c 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -51,7 +51,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { } } -fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { +fn codegen_fn_attrs_provider(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if cfg!(debug_assertions) { let def_kind = tcx.def_kind(did); assert!( @@ -923,6 +923,20 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option { Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities }) } +fn codegen_fn_attrs_overridden(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs { + let mut attrs = tcx.codegen_fn_attrs_imp(did).clone(); + let overrides = tcx.sess.opts.unstable_opts.inline_always_overrides.as_ref().unwrap(); + if overrides.contains(&tcx.def_path_str(did)) { + attrs.inline = InlineAttr::Always; + } + attrs +} + pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers }; + *providers = Providers { + codegen_fn_attrs_imp: codegen_fn_attrs_provider, + codegen_fn_attrs_overridden, + should_inherit_track_caller, + ..*providers + }; } diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 1dd96297d1fda..b15abb8771af7 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -131,7 +131,7 @@ fn intern_as_new_static<'tcx>( // These do not inherit the codegen attrs of the parent static allocation, since // it doesn't make sense for them to inherit their `#[no_mangle]` and `#[link_name = ..]` // and the like. - feed.codegen_fn_attrs(CodegenFnAttrs::new()); + feed.codegen_fn_attrs_imp(CodegenFnAttrs::new()); feed.eval_static_initializer(Ok(alloc)); feed.generics_of(tcx.generics_of(static_id).clone()); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 4520fbe352cea..b8880092fbe68 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -313,7 +313,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if let hir::ExprKind::Closure(closure) = expr.kind { self.tcx.ensure_ok().generics_of(closure.def_id); - self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id); + self.tcx.ensure_ok().codegen_fn_attrs_imp(closure.def_id); // We do not call `type_of` for closures here as that // depends on typecheck and would therefore hide // any further errors in case one typeck fails. @@ -691,11 +691,11 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } match item.kind { hir::ForeignItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs(item.owner_id); + tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id); tcx.ensure_ok().fn_sig(item.owner_id) } hir::ForeignItemKind::Static(..) => { - tcx.ensure_ok().codegen_fn_attrs(item.owner_id); + tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id); let mut visitor = HirPlaceholderCollector::default(); visitor.visit_foreign_item(item); placeholder_type_error( @@ -782,7 +782,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); tcx.ensure_ok().fn_sig(def_id); - tcx.ensure_ok().codegen_fn_attrs(def_id); + tcx.ensure_ok().codegen_fn_attrs_imp(def_id); } } } @@ -795,7 +795,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { match trait_item.kind { hir::TraitItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs(def_id); + tcx.ensure_ok().codegen_fn_attrs_imp(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().fn_sig(def_id); } @@ -867,7 +867,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let icx = ItemCtxt::new(tcx, def_id.def_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs(def_id); + tcx.ensure_ok().codegen_fn_attrs_imp(def_id); tcx.ensure_ok().fn_sig(def_id); } hir::ImplItemKind::Type(_) => { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 76bae39ef8c00..2efadc4a5c6f6 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -251,7 +251,7 @@ provide! { tcx, def_id, other, cdata, type_alias_is_lazy => { table_direct } variances_of => { table } fn_sig => { table } - codegen_fn_attrs => { table } + codegen_fn_attrs_imp => { table } impl_trait_header => { table } const_param_default => { table } object_lifetime_default => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 7ac72ef814a9c..b636be5458c46 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1431,7 +1431,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.def_ident_span[def_id] <- ident_span); } if def_kind.has_codegen_attrs() { - record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id)); + record!(self.tables.codegen_fn_attrs_imp[def_id] <- self.tcx.codegen_fn_attrs(def_id)); } if should_encode_visibility(def_kind) { let vis = diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index c86cf567283fe..bcc07b9bd676e 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -431,7 +431,7 @@ define_tables! { type_of: Table>>>, variances_of: Table>, fn_sig: Table>>>, - codegen_fn_attrs: Table>, + codegen_fn_attrs_imp: Table>, impl_trait_header: Table>>, const_param_default: Table>>>, object_lifetime_default: Table>, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index b2133fea08cc3..c19668fab261d 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1443,7 +1443,7 @@ rustc_queries! { separate_provide_extern } - query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs { + query codegen_fn_attrs_imp(def_id: DefId) -> &'tcx CodegenFnAttrs { desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) } arena_cache cache_on_disk_if { def_id.is_local() } @@ -1451,6 +1451,11 @@ rustc_queries! { feedable } + query codegen_fn_attrs_overridden(def_id: DefId) -> &'tcx CodegenFnAttrs { + desc { |tcx| "computing codegen attributes of `{}` (with overrides)", tcx.def_path_str(def_id) } + arena_cache + } + query asm_target_features(def_id: DefId) -> &'tcx FxIndexSet { desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 0759fa3da428a..18feaa020a2c5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -3395,6 +3395,15 @@ impl<'tcx> TyCtxt<'tcx> { pub fn do_not_recommend_impl(self, def_id: DefId) -> bool { self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some() } + + pub fn codegen_fn_attrs(self, def_id: impl IntoQueryParam) -> &'tcx CodegenFnAttrs { + let def_id = def_id.into_query_param(); + if self.sess.opts.unstable_opts.inline_always_overrides.is_some() { + self.codegen_fn_attrs_overridden(def_id) + } else { + self.codegen_fn_attrs_imp(def_id) + } + } } /// Parameter attributes that can only be determined by examining the body of a function instead diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index 0a839d91404ec..4cd0914b0eae1 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -230,7 +230,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>( // Feed HIR because we try to access this body's attrs in the inliner. body_def.feed_hir(); // Inherited from the by-ref coroutine. - body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone()); + body_def.codegen_fn_attrs_imp(tcx.codegen_fn_attrs(coroutine_def_id).clone()); body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id)); body_def.constness(tcx.constness(coroutine_def_id)); body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 5b4068740a159..3e917b680203e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2249,6 +2249,9 @@ options! { - hashes of green query instances - hash collisions of query keys - hash collisions when creating dep-nodes"), + inline_always_overrides: Option> = (None, parse_opt_comma_list, [TRACKED], + "comma-separated list of full paths to functions to treat as if they are inline(always)" + ), inline_llvm: bool = (true, parse_bool, [TRACKED], "enable LLVM inlining (default: yes)"), inline_mir: Option = (None, parse_opt_bool, [TRACKED], From 0dfc4d76b2a6db97c1a5b78b742d712c85d91f7d Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 20 May 2025 17:22:30 -0400 Subject: [PATCH 2/3] Use a much simpler hack: just consult the flag inside cg_llvm --- compiler/rustc_codegen_llvm/src/attributes.rs | 6 +++++- .../rustc_codegen_ssa/src/codegen_attrs.rs | 18 ++---------------- .../rustc_const_eval/src/interpret/intern.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 12 ++++++------ .../src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/src/mir/mono.rs | 2 ++ compiler/rustc_middle/src/query/mod.rs | 7 +------ compiler/rustc_middle/src/ty/context.rs | 17 ++++++++--------- .../src/coroutine/by_move_body.rs | 2 +- 11 files changed, 29 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 176fb72dfdc5e..7c66a40f38827 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -367,7 +367,11 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( (InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint, (inline, _) => inline, }; - to_add.extend(inline_attr(cx, inline)); + if cx.tcx.has_inline_always_override(instance) { + to_add.extend(inline_attr(cx, InlineAttr::Always)); + } else { + to_add.extend(inline_attr(cx, inline)); + } // The `uwtable` attribute according to LLVM is: // diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 857415980017c..835ffb7d4fc6b 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -51,7 +51,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { } } -fn codegen_fn_attrs_provider(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { +fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if cfg!(debug_assertions) { let def_kind = tcx.def_kind(did); assert!( @@ -923,20 +923,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option { Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities }) } -fn codegen_fn_attrs_overridden(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs { - let mut attrs = tcx.codegen_fn_attrs_imp(did).clone(); - let overrides = tcx.sess.opts.unstable_opts.inline_always_overrides.as_ref().unwrap(); - if overrides.contains(&tcx.def_path_str(did)) { - attrs.inline = InlineAttr::Always; - } - attrs -} - pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { - codegen_fn_attrs_imp: codegen_fn_attrs_provider, - codegen_fn_attrs_overridden, - should_inherit_track_caller, - ..*providers - }; + *providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers }; } diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index b15abb8771af7..1dd96297d1fda 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -131,7 +131,7 @@ fn intern_as_new_static<'tcx>( // These do not inherit the codegen attrs of the parent static allocation, since // it doesn't make sense for them to inherit their `#[no_mangle]` and `#[link_name = ..]` // and the like. - feed.codegen_fn_attrs_imp(CodegenFnAttrs::new()); + feed.codegen_fn_attrs(CodegenFnAttrs::new()); feed.eval_static_initializer(Ok(alloc)); feed.generics_of(tcx.generics_of(static_id).clone()); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index b8880092fbe68..4520fbe352cea 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -313,7 +313,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if let hir::ExprKind::Closure(closure) = expr.kind { self.tcx.ensure_ok().generics_of(closure.def_id); - self.tcx.ensure_ok().codegen_fn_attrs_imp(closure.def_id); + self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id); // We do not call `type_of` for closures here as that // depends on typecheck and would therefore hide // any further errors in case one typeck fails. @@ -691,11 +691,11 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } match item.kind { hir::ForeignItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id); + tcx.ensure_ok().codegen_fn_attrs(item.owner_id); tcx.ensure_ok().fn_sig(item.owner_id) } hir::ForeignItemKind::Static(..) => { - tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id); + tcx.ensure_ok().codegen_fn_attrs(item.owner_id); let mut visitor = HirPlaceholderCollector::default(); visitor.visit_foreign_item(item); placeholder_type_error( @@ -782,7 +782,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); tcx.ensure_ok().fn_sig(def_id); - tcx.ensure_ok().codegen_fn_attrs_imp(def_id); + tcx.ensure_ok().codegen_fn_attrs(def_id); } } } @@ -795,7 +795,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { match trait_item.kind { hir::TraitItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs_imp(def_id); + tcx.ensure_ok().codegen_fn_attrs(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().fn_sig(def_id); } @@ -867,7 +867,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let icx = ItemCtxt::new(tcx, def_id.def_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs_imp(def_id); + tcx.ensure_ok().codegen_fn_attrs(def_id); tcx.ensure_ok().fn_sig(def_id); } hir::ImplItemKind::Type(_) => { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 2efadc4a5c6f6..76bae39ef8c00 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -251,7 +251,7 @@ provide! { tcx, def_id, other, cdata, type_alias_is_lazy => { table_direct } variances_of => { table } fn_sig => { table } - codegen_fn_attrs_imp => { table } + codegen_fn_attrs => { table } impl_trait_header => { table } const_param_default => { table } object_lifetime_default => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index b636be5458c46..7ac72ef814a9c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1431,7 +1431,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.def_ident_span[def_id] <- ident_span); } if def_kind.has_codegen_attrs() { - record!(self.tables.codegen_fn_attrs_imp[def_id] <- self.tcx.codegen_fn_attrs(def_id)); + record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id)); } if should_encode_visibility(def_kind) { let vis = diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index bcc07b9bd676e..c86cf567283fe 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -431,7 +431,7 @@ define_tables! { type_of: Table>>>, variances_of: Table>, fn_sig: Table>>>, - codegen_fn_attrs_imp: Table>, + codegen_fn_attrs: Table>, impl_trait_header: Table>>, const_param_default: Table>>>, object_lifetime_default: Table>, diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 7243f87ee6380..6ef5cb1ab5fad 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -209,6 +209,8 @@ impl<'tcx> MonoItem<'tcx> { if codegen_fn_attrs.inline.always() { return InstantiationMode::LocalCopy; } + // FIXME: Ideally we'd check has_inline_always_override here, but we can't because symbol names + // depend on instantiation mode so instantiation mode can't depend on symbol name. // #[inline(never)] functions in general are poor candidates for inlining and thus since // LocalCopy generally increases code size for the benefit of optimizations from inlining, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index c19668fab261d..b2133fea08cc3 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1443,7 +1443,7 @@ rustc_queries! { separate_provide_extern } - query codegen_fn_attrs_imp(def_id: DefId) -> &'tcx CodegenFnAttrs { + query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs { desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) } arena_cache cache_on_disk_if { def_id.is_local() } @@ -1451,11 +1451,6 @@ rustc_queries! { feedable } - query codegen_fn_attrs_overridden(def_id: DefId) -> &'tcx CodegenFnAttrs { - desc { |tcx| "computing codegen attributes of `{}` (with overrides)", tcx.def_path_str(def_id) } - arena_cache - } - query asm_target_features(def_id: DefId) -> &'tcx FxIndexSet { desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 18feaa020a2c5..60748027a6e73 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -78,8 +78,8 @@ use crate::traits::solve::{ use crate::ty::predicate::ExistentialPredicateStableCmpExt as _; use crate::ty::{ self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs, - GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, ParamTy, - Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, + GenericArgsRef, GenericParamDefKind, Instance, List, ListWithCachedTypeInfo, ParamConst, + ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, ValTree, ValTreeKind, Visibility, }; @@ -3396,13 +3396,12 @@ impl<'tcx> TyCtxt<'tcx> { self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some() } - pub fn codegen_fn_attrs(self, def_id: impl IntoQueryParam) -> &'tcx CodegenFnAttrs { - let def_id = def_id.into_query_param(); - if self.sess.opts.unstable_opts.inline_always_overrides.is_some() { - self.codegen_fn_attrs_overridden(def_id) - } else { - self.codegen_fn_attrs_imp(def_id) - } + pub fn has_inline_always_override(self, instance: Instance<'tcx>) -> bool { + let Some(overrides) = &self.sess.opts.unstable_opts.inline_always_overrides else { + return false; + }; + let symbol_name = self.symbol_name(instance).name; + overrides.iter().any(|o| o == symbol_name) } } diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index 4cd0914b0eae1..0a839d91404ec 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -230,7 +230,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>( // Feed HIR because we try to access this body's attrs in the inliner. body_def.feed_hir(); // Inherited from the by-ref coroutine. - body_def.codegen_fn_attrs_imp(tcx.codegen_fn_attrs(coroutine_def_id).clone()); + body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone()); body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id)); body_def.constness(tcx.constness(coroutine_def_id)); body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id)); From d94c483070f858718b4a9fd1ffbab60244d882e8 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 20 May 2025 17:47:48 -0400 Subject: [PATCH 3/3] Make overrides a prefix and add a debug print --- compiler/rustc_codegen_llvm/src/attributes.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 7c66a40f38827..7b2cc58ce42c9 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -368,6 +368,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( (inline, _) => inline, }; if cx.tcx.has_inline_always_override(instance) { + eprintln!("Applying override"); to_add.extend(inline_attr(cx, InlineAttr::Always)); } else { to_add.extend(inline_attr(cx, inline)); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 60748027a6e73..a3b2850a334a7 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -3401,7 +3401,7 @@ impl<'tcx> TyCtxt<'tcx> { return false; }; let symbol_name = self.symbol_name(instance).name; - overrides.iter().any(|o| o == symbol_name) + overrides.iter().any(|o| symbol_name.starts_with(o)) } }