Skip to content

Commit 0dfc4d7

Browse files
committed
Use a much simpler hack: just consult the flag inside cg_llvm
1 parent d2221bd commit 0dfc4d7

File tree

11 files changed

+29
-43
lines changed

11 files changed

+29
-43
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
367367
(InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint,
368368
(inline, _) => inline,
369369
};
370-
to_add.extend(inline_attr(cx, inline));
370+
if cx.tcx.has_inline_always_override(instance) {
371+
to_add.extend(inline_attr(cx, InlineAttr::Always));
372+
} else {
373+
to_add.extend(inline_attr(cx, inline));
374+
}
371375

372376
// The `uwtable` attribute according to LLVM is:
373377
//

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
5151
}
5252
}
5353

54-
fn codegen_fn_attrs_provider(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
54+
fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
5555
if cfg!(debug_assertions) {
5656
let def_kind = tcx.def_kind(did);
5757
assert!(
@@ -923,20 +923,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
923923
Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities })
924924
}
925925

926-
fn codegen_fn_attrs_overridden(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
927-
let mut attrs = tcx.codegen_fn_attrs_imp(did).clone();
928-
let overrides = tcx.sess.opts.unstable_opts.inline_always_overrides.as_ref().unwrap();
929-
if overrides.contains(&tcx.def_path_str(did)) {
930-
attrs.inline = InlineAttr::Always;
931-
}
932-
attrs
933-
}
934-
935926
pub(crate) fn provide(providers: &mut Providers) {
936-
*providers = Providers {
937-
codegen_fn_attrs_imp: codegen_fn_attrs_provider,
938-
codegen_fn_attrs_overridden,
939-
should_inherit_track_caller,
940-
..*providers
941-
};
927+
*providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers };
942928
}

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn intern_as_new_static<'tcx>(
131131
// These do not inherit the codegen attrs of the parent static allocation, since
132132
// it doesn't make sense for them to inherit their `#[no_mangle]` and `#[link_name = ..]`
133133
// and the like.
134-
feed.codegen_fn_attrs_imp(CodegenFnAttrs::new());
134+
feed.codegen_fn_attrs(CodegenFnAttrs::new());
135135

136136
feed.eval_static_initializer(Ok(alloc));
137137
feed.generics_of(tcx.generics_of(static_id).clone());

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
313313
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
314314
if let hir::ExprKind::Closure(closure) = expr.kind {
315315
self.tcx.ensure_ok().generics_of(closure.def_id);
316-
self.tcx.ensure_ok().codegen_fn_attrs_imp(closure.def_id);
316+
self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
317317
// We do not call `type_of` for closures here as that
318318
// depends on typecheck and would therefore hide
319319
// any further errors in case one typeck fails.
@@ -691,11 +691,11 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
691691
}
692692
match item.kind {
693693
hir::ForeignItemKind::Fn(..) => {
694-
tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id);
694+
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
695695
tcx.ensure_ok().fn_sig(item.owner_id)
696696
}
697697
hir::ForeignItemKind::Static(..) => {
698-
tcx.ensure_ok().codegen_fn_attrs_imp(item.owner_id);
698+
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
699699
let mut visitor = HirPlaceholderCollector::default();
700700
visitor.visit_foreign_item(item);
701701
placeholder_type_error(
@@ -782,7 +782,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
782782
tcx.ensure_ok().type_of(def_id);
783783
tcx.ensure_ok().predicates_of(def_id);
784784
tcx.ensure_ok().fn_sig(def_id);
785-
tcx.ensure_ok().codegen_fn_attrs_imp(def_id);
785+
tcx.ensure_ok().codegen_fn_attrs(def_id);
786786
}
787787
}
788788
}
@@ -795,7 +795,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
795795

796796
match trait_item.kind {
797797
hir::TraitItemKind::Fn(..) => {
798-
tcx.ensure_ok().codegen_fn_attrs_imp(def_id);
798+
tcx.ensure_ok().codegen_fn_attrs(def_id);
799799
tcx.ensure_ok().type_of(def_id);
800800
tcx.ensure_ok().fn_sig(def_id);
801801
}
@@ -867,7 +867,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
867867
let icx = ItemCtxt::new(tcx, def_id.def_id);
868868
match impl_item.kind {
869869
hir::ImplItemKind::Fn(..) => {
870-
tcx.ensure_ok().codegen_fn_attrs_imp(def_id);
870+
tcx.ensure_ok().codegen_fn_attrs(def_id);
871871
tcx.ensure_ok().fn_sig(def_id);
872872
}
873873
hir::ImplItemKind::Type(_) => {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ provide! { tcx, def_id, other, cdata,
251251
type_alias_is_lazy => { table_direct }
252252
variances_of => { table }
253253
fn_sig => { table }
254-
codegen_fn_attrs_imp => { table }
254+
codegen_fn_attrs => { table }
255255
impl_trait_header => { table }
256256
const_param_default => { table }
257257
object_lifetime_default => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14311431
record!(self.tables.def_ident_span[def_id] <- ident_span);
14321432
}
14331433
if def_kind.has_codegen_attrs() {
1434-
record!(self.tables.codegen_fn_attrs_imp[def_id] <- self.tcx.codegen_fn_attrs(def_id));
1434+
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
14351435
}
14361436
if should_encode_visibility(def_kind) {
14371437
let vis =

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ define_tables! {
431431
type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, Ty<'static>>>>,
432432
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
433433
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,
434-
codegen_fn_attrs_imp: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
434+
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
435435
impl_trait_header: Table<DefIndex, LazyValue<ty::ImplTraitHeader<'static>>>,
436436
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>>>,
437437
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ impl<'tcx> MonoItem<'tcx> {
209209
if codegen_fn_attrs.inline.always() {
210210
return InstantiationMode::LocalCopy;
211211
}
212+
// FIXME: Ideally we'd check has_inline_always_override here, but we can't because symbol names
213+
// depend on instantiation mode so instantiation mode can't depend on symbol name.
212214

213215
// #[inline(never)] functions in general are poor candidates for inlining and thus since
214216
// LocalCopy generally increases code size for the benefit of optimizations from inlining,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,19 +1443,14 @@ rustc_queries! {
14431443
separate_provide_extern
14441444
}
14451445

1446-
query codegen_fn_attrs_imp(def_id: DefId) -> &'tcx CodegenFnAttrs {
1446+
query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs {
14471447
desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
14481448
arena_cache
14491449
cache_on_disk_if { def_id.is_local() }
14501450
separate_provide_extern
14511451
feedable
14521452
}
14531453

1454-
query codegen_fn_attrs_overridden(def_id: DefId) -> &'tcx CodegenFnAttrs {
1455-
desc { |tcx| "computing codegen attributes of `{}` (with overrides)", tcx.def_path_str(def_id) }
1456-
arena_cache
1457-
}
1458-
14591454
query asm_target_features(def_id: DefId) -> &'tcx FxIndexSet<Symbol> {
14601455
desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
14611456
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ use crate::traits::solve::{
7878
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
7979
use crate::ty::{
8080
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
81-
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, ParamTy,
82-
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
81+
GenericArgsRef, GenericParamDefKind, Instance, List, ListWithCachedTypeInfo, ParamConst,
82+
ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
8383
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
8484
ValTree, ValTreeKind, Visibility,
8585
};
@@ -3396,13 +3396,12 @@ impl<'tcx> TyCtxt<'tcx> {
33963396
self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some()
33973397
}
33983398

3399-
pub fn codegen_fn_attrs(self, def_id: impl IntoQueryParam<DefId>) -> &'tcx CodegenFnAttrs {
3400-
let def_id = def_id.into_query_param();
3401-
if self.sess.opts.unstable_opts.inline_always_overrides.is_some() {
3402-
self.codegen_fn_attrs_overridden(def_id)
3403-
} else {
3404-
self.codegen_fn_attrs_imp(def_id)
3405-
}
3399+
pub fn has_inline_always_override(self, instance: Instance<'tcx>) -> bool {
3400+
let Some(overrides) = &self.sess.opts.unstable_opts.inline_always_overrides else {
3401+
return false;
3402+
};
3403+
let symbol_name = self.symbol_name(instance).name;
3404+
overrides.iter().any(|o| o == symbol_name)
34063405
}
34073406
}
34083407

0 commit comments

Comments
 (0)