Skip to content

Commit fb6bd17

Browse files
authored
Unrolled build for #152168
Rollup merge of #152168 - jdonszelmann:port-rustc-intrinsic-const-stable-indirect, r=jonathanbrouwer Port `rustc_intrinsic_const_stable_indirect` and `rustc_intrinsic` to the new attribute parser r? @JonathanBrouwer
2 parents 8c5605e + c42a581 commit fb6bd17

10 files changed

Lines changed: 51 additions & 14 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13971397
// create a fake body so that the entire rest of the compiler doesn't have to deal with
13981398
// this as a special case.
13991399
return self.lower_fn_body(decl, contract, |this| {
1400-
if attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic))
1400+
if find_attr!(attrs, AttributeKind::RustcIntrinsic)
14011401
|| this.tcx.is_sdylib_interface_build()
14021402
{
14031403
let span = this.lower_span(span);

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcMirParser {
490490
.collect()
491491
}
492492
}
493+
493494
pub(crate) struct RustcNonConstTraitMethodParser;
494495

495496
impl<S: Stage> NoArgsAttributeParser<S> for RustcNonConstTraitMethodParser {
@@ -810,3 +811,21 @@ impl<S: Stage> SingleAttributeParser<S> for RustcDefPath {
810811
Some(AttributeKind::RustcDefPath(cx.attr_span))
811812
}
812813
}
814+
815+
pub(crate) struct RustcIntrinsicParser;
816+
817+
impl<S: Stage> NoArgsAttributeParser<S> for RustcIntrinsicParser {
818+
const PATH: &[Symbol] = &[sym::rustc_intrinsic];
819+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
820+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
821+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcIntrinsic;
822+
}
823+
824+
pub(crate) struct RustcIntrinsicConstStableIndirectParser;
825+
826+
impl<S: Stage> NoArgsAttributeParser<S> for RustcIntrinsicConstStableIndirectParser {
827+
const PATH: &'static [Symbol] = &[sym::rustc_intrinsic_const_stable_indirect];
828+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
829+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
830+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcIntrinsicConstStableIndirect;
831+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ attribute_parsers!(
264264
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
265265
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
266266
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
267+
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
268+
Single<WithoutArgs<RustcIntrinsicParser>>,
267269
Single<WithoutArgs<RustcLintOptTyParser>>,
268270
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
269271
Single<WithoutArgs<RustcLintUntrackedQueryInformationParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,12 @@ pub enum AttributeKind {
11201120
/// Represents `#[rustc_if_this_changed]`
11211121
RustcIfThisChanged(Span, Option<Symbol>),
11221122

1123+
/// Represents `#[rustc_intrinsic]`
1124+
RustcIntrinsic,
1125+
1126+
/// Represents `#[rustc_intrinsic_const_stable_indirect]`
1127+
RustcIntrinsicConstStableIndirect,
1128+
11231129
/// Represents `#[rustc_layout]`
11241130
RustcLayout(ThinVec<RustcLayoutType>),
11251131

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ impl AttributeKind {
118118
RustcHasIncoherentInherentImpls => Yes,
119119
RustcHiddenTypeOfOpaques => No,
120120
RustcIfThisChanged(..) => No,
121+
RustcIntrinsic => Yes,
122+
RustcIntrinsicConstStableIndirect => No,
121123
RustcLayout(..) => No,
122124
RustcLayoutScalarValidRangeEnd(..) => Yes,
123125
RustcLayoutScalarValidRangeStart(..) => Yes,

compiler/rustc_middle/src/ty/util.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1010
use rustc_data_structures::stack::ensure_sufficient_stack;
1111
use rustc_errors::ErrorGuaranteed;
1212
use rustc_hashes::Hash128;
13-
use rustc_hir as hir;
1413
use rustc_hir::attrs::AttributeKind;
1514
use rustc_hir::def::{CtorOf, DefKind, Res};
1615
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1716
use rustc_hir::limit::Limit;
17+
use rustc_hir::{self as hir, find_attr};
1818
use rustc_index::bit_set::GrowableBitSet;
1919
use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
2020
use rustc_span::sym;
@@ -1679,7 +1679,9 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
16791679
/// the compiler to make some assumptions about its shape; if the user doesn't use a feature gate, they may
16801680
/// cause an ICE that we otherwise may want to prevent.
16811681
pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
1682-
if tcx.features().intrinsics() && tcx.has_attr(def_id, sym::rustc_intrinsic) {
1682+
if tcx.features().intrinsics()
1683+
&& find_attr!(tcx.get_all_attrs(def_id), AttributeKind::RustcIntrinsic)
1684+
{
16831685
let must_be_overridden = match tcx.hir_node_by_def_id(def_id) {
16841686
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { has_body, .. }, .. }) => {
16851687
!has_body
@@ -1689,7 +1691,10 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Intrinsi
16891691
Some(ty::IntrinsicDef {
16901692
name: tcx.item_name(def_id),
16911693
must_be_overridden,
1692-
const_stable: tcx.has_attr(def_id, sym::rustc_intrinsic_const_stable_indirect),
1694+
const_stable: find_attr!(
1695+
tcx.get_all_attrs(def_id),
1696+
AttributeKind::RustcIntrinsicConstStableIndirect
1697+
),
16931698
})
16941699
} else {
16951700
None

compiler/rustc_mir_transform/src/check_inline.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Check that a body annotated with `#[rustc_force_inline]` will not fail to inline based on its
22
//! definition alone (irrespective of any specific caller).
33
4-
use rustc_hir::attrs::InlineAttr;
4+
use rustc_hir::attrs::{AttributeKind, InlineAttr};
55
use rustc_hir::def_id::DefId;
6+
use rustc_hir::find_attr;
67
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
78
use rustc_middle::mir::{Body, TerminatorKind};
89
use rustc_middle::ty;
@@ -62,7 +63,7 @@ pub(super) fn is_inline_valid_on_fn<'tcx>(
6263
// but at this stage we don't know whether codegen knows the intrinsic,
6364
// so just conservatively don't inline it. This also ensures that we do not
6465
// accidentally inline the body of an intrinsic that *must* be overridden.
65-
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
66+
if find_attr!(tcx.get_all_attrs(def_id), AttributeKind::RustcIntrinsic) {
6667
return Err("callee is an intrinsic");
6768
}
6869

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use rustc_hir::attrs::InlineAttr;
1+
use rustc_hir::attrs::{AttributeKind, InlineAttr};
22
use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::LocalDefId;
4+
use rustc_hir::find_attr;
45
use rustc_middle::bug;
56
use rustc_middle::mir::visit::Visitor;
67
use rustc_middle::mir::*;
@@ -43,7 +44,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
4344
return true;
4445
}
4546

46-
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
47+
if find_attr!(tcx.get_all_attrs(def_id), AttributeKind::RustcIntrinsic) {
4748
// Intrinsic fallback bodies are always cross-crate inlineable.
4849
// To ensure that the MIR inliner doesn't cluelessly try to inline fallback
4950
// bodies even when the backend would implement something better, we stop
@@ -157,7 +158,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
157158
// But intrinsics don't have a body that gets assigned to a CGU, so they are
158159
// ignored.
159160
if let Some((fn_def_id, _)) = func.const_fn_def()
160-
&& self.tcx.has_attr(fn_def_id, sym::rustc_intrinsic)
161+
&& find_attr!(tcx.get_all_attrs(fn_def_id), AttributeKind::RustcIntrinsic)
161162
{
162163
return;
163164
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
313313
| AttributeKind::RustcHasIncoherentInherentImpls
314314
| AttributeKind::RustcHiddenTypeOfOpaques
315315
| AttributeKind::RustcIfThisChanged(..)
316+
| AttributeKind::RustcIntrinsic
317+
| AttributeKind::RustcIntrinsicConstStableIndirect
316318
| AttributeKind::RustcLayout(..)
317319
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
318320
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
@@ -385,9 +387,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
385387
| sym::rustc_no_mir_inline
386388
| sym::rustc_insignificant_dtor
387389
| sym::rustc_nonnull_optimization_guaranteed
388-
| sym::rustc_intrinsic
389390
| sym::rustc_inherit_overflow_checks
390-
| sym::rustc_intrinsic_const_stable_indirect
391391
| sym::rustc_trivial_field_reads
392392
| sym::rustc_on_unimplemented
393393
| sym::rustc_do_not_const_check

src/tools/clippy/clippy_lints/src/loops/empty_loop.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use super::EMPTY_LOOP;
22
use clippy_utils::diagnostics::span_lint_and_help;
3-
use clippy_utils::{is_in_panic_handler, is_no_std_crate, sym};
3+
use clippy_utils::{is_in_panic_handler, is_no_std_crate};
44

5-
use rustc_hir::{Block, Expr, ItemKind, Node};
5+
use rustc_hir::attrs::AttributeKind;
6+
use rustc_hir::{Block, Expr, ItemKind, Node, find_attr};
67
use rustc_lint::LateContext;
78

89
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, loop_block: &Block<'_>) {
910
let parent_hir_id = cx.tcx.parent_hir_id(expr.hir_id);
1011
if let Node::Item(parent_node) = cx.tcx.hir_node(parent_hir_id)
1112
&& matches!(parent_node.kind, ItemKind::Fn { .. })
1213
&& let attrs = cx.tcx.hir_attrs(parent_hir_id)
13-
&& attrs.iter().any(|attr| attr.has_name(sym::rustc_intrinsic))
14+
&& find_attr!(attrs, AttributeKind::RustcIntrinsic)
1415
{
1516
// Intrinsic functions are expanded into an empty loop when lowering the AST
1617
// to simplify the job of later passes which might expect any function to have a body.

0 commit comments

Comments
 (0)