Skip to content

Commit f537287

Browse files
committed
Inline attributes on async fn and async closures affect the poll impl instead of the desugared creator function.
1 parent 122cbd0 commit f537287

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_hir::attrs::{AttributeKind, InlineAttr, InstructionSetAttr, RtsanSetting, UsedBy};
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
9-
use rustc_hir::{self as hir, Attribute, LangItem, find_attr, lang_items};
9+
use rustc_hir::{
10+
self as hir, Attribute, CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem,
11+
find_attr, lang_items,
12+
};
1013
use rustc_middle::middle::codegen_fn_attrs::{
1114
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
1215
};
@@ -386,6 +389,15 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
386389
}
387390
}
388391

392+
// #129347: desugared async coutines inherit inline attrs from the async fn/closure
393+
if let Some(parent) = async_poll_inherit_inline(tcx, did.to_def_id()) {
394+
let parent_attrs = tcx.codegen_fn_attrs(parent);
395+
if matches!(parent_attrs.inline, InlineAttr::Never | InlineAttr::Hint | InlineAttr::Always)
396+
{
397+
codegen_fn_attrs.inline = parent_attrs.inline;
398+
}
399+
}
400+
389401
// When `no_builtins` is applied at the crate level, we should add the
390402
// `no-builtins` attribute to each function to ensure it takes effect in LTO.
391403
let crate_attrs = tcx.hir_attrs(rustc_hir::CRATE_HIR_ID);
@@ -647,6 +659,23 @@ fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Align> {
647659
tcx.codegen_fn_attrs(tcx.trait_item_of(def_id)?).alignment
648660
}
649661

662+
// Checks if the given DefId is a desugared async coroutine that should inherit inline attrs.
663+
fn async_poll_inherit_inline(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
664+
let Some(kind) = tcx.coroutine_kind(def_id) else {
665+
return None;
666+
};
667+
668+
if matches!(
669+
kind,
670+
CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Fn)
671+
| CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)
672+
) {
673+
Some(tcx.parent(def_id))
674+
} else {
675+
None
676+
}
677+
}
678+
650679
/// We now check the #\[rustc_autodiff\] attributes which we generated from the #[autodiff(...)]
651680
/// macros. There are two forms. The pure one without args to mark primal functions (the functions
652681
/// being differentiated). The other form is #[rustc_autodiff(Mode, ActivityList)] on top of the

0 commit comments

Comments
 (0)