Skip to content

Commit 5be0607

Browse files
Auto merge of #143965 - tiif:perf_unstable_impl, r=<try>
[Perf] Remove call to hir_attrs in predicates_of <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end --> Test how much regression we still have if we remove the call to ``hir_attrs`` in ``predicates_of`` for #140399 r? ghost
2 parents a9fb610 + 1c5e8b7 commit 5be0607

File tree

82 files changed

+1050
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1050
-13
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ pub enum AttributeKind {
417417
/// Represents `#[rustc_unsafe_specialization_marker]`.
418418
UnsafeSpecializationMarker(Span),
419419

420+
/// Represents `#[unstable_feature_bound]`.
421+
UnstableFeatureBound(ThinVec<(Symbol, Span)>),
422+
420423
/// Represents `#[used]`
421424
Used { used_by: UsedBy, span: Span },
422425
// tidy-alphabetical-end

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl AttributeKind {
7070
TrackCaller(..) => Yes,
7171
TypeConst(..) => Yes,
7272
UnsafeSpecializationMarker(..) => No,
73+
UnstableFeatureBound(..) => No,
7374
Used { .. } => No,
7475
// tidy-alphabetical-end
7576
}

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ attr_parsing_unrecognized_repr_hint =
136136
attr_parsing_unstable_cfg_target_compact =
137137
compact `cfg(target(..))` is experimental and subject to change
138138
139+
attr_parsing_unstable_feature_bound_incompatible_stability = Item annotated with `#[unstable_feature_bound]` should not be stable
140+
.help = If this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
141+
139142
attr_parsing_unsupported_literal_cfg_boolean =
140143
literal in `cfg` predicate value must be a boolean
141144
attr_parsing_unsupported_literal_cfg_string =

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
2727
}
2828
}
2929

30+
pub(crate) struct UnstableFeatureBoundParser;
31+
impl<S: Stage> CombineAttributeParser<S> for UnstableFeatureBoundParser {
32+
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound];
33+
type Item = (Symbol, Span);
34+
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items);
35+
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
36+
37+
fn extend<'c>(
38+
cx: &'c mut AcceptContext<'_, '_, S>,
39+
args: &'c ArgParser<'_>,
40+
) -> impl IntoIterator<Item = Self::Item> {
41+
if !cx.features().staged_api() {
42+
cx.emit_err(session_diagnostics::StabilityOutsideStd { span: cx.attr_span });
43+
}
44+
parse_unstable(cx, args, <Self as CombineAttributeParser<S>>::PATH[0])
45+
.into_iter()
46+
.zip(iter::repeat(cx.attr_span))
47+
}
48+
}
49+
3050
pub(crate) struct AllowConstFnUnstableParser;
3151
impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
3252
const PATH: &[Symbol] = &[sym::rustc_allow_const_fn_unstable];

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ impl<S: Stage> AttributeParser<S> for StabilityParser {
9898
}
9999
}
100100

101+
if let Some((Stability { level: StabilityLevel::Stable { .. }, .. }, _)) = self.stability {
102+
for other_attr in cx.all_attrs {
103+
if other_attr.word_is(sym::unstable_feature_bound) {
104+
cx.emit_err(session_diagnostics::UnstableFeatureBoundIncompatibleStability {
105+
span: cx.target_span,
106+
});
107+
}
108+
}
109+
}
110+
101111
let (stability, span) = self.stability?;
102112

103113
Some(AttributeKind::Stability { stability, span })

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, HirI
1313
use rustc_session::Session;
1414
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1515

16-
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
16+
use crate::attributes::allow_unstable::{
17+
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
18+
};
1719
use crate::attributes::codegen_attrs::{
1820
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
1921
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
@@ -133,6 +135,7 @@ attribute_parsers!(
133135
Combine<AllowInternalUnstableParser>,
134136
Combine<ReprParser>,
135137
Combine<TargetFeatureParser>,
138+
Combine<UnstableFeatureBoundParser>,
136139
// tidy-alphabetical-end
137140

138141
// tidy-alphabetical-start

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ pub(crate) struct UnrecognizedReprHint {
503503
pub span: Span,
504504
}
505505

506+
#[derive(Diagnostic)]
507+
#[diag(attr_parsing_unstable_feature_bound_incompatible_stability)]
508+
#[help]
509+
pub(crate) struct UnstableFeatureBoundIncompatibleStability {
510+
#[primary_span]
511+
pub span: Span,
512+
}
513+
506514
#[derive(Diagnostic)]
507515
#[diag(attr_parsing_naked_functions_incompatible_attribute, code = E0736)]
508516
pub(crate) struct NakedFunctionIncompatibleAttribute {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
683683
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
684684
EncodeCrossCrate::Yes
685685
),
686+
ungated!(
687+
unstable_feature_bound, Normal, template!(Word, List: "feat1, feat2, ..."),
688+
DuplicatesOk, EncodeCrossCrate::No,
689+
),
686690
ungated!(
687691
rustc_const_unstable, Normal, template!(List: r#"feature = "name""#),
688692
DuplicatesOk, EncodeCrossCrate::Yes

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,12 +2212,16 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22122212
let implied_obligations = traits::elaborate(tcx, predicates_with_span);
22132213

22142214
for (pred, obligation_span) in implied_obligations {
2215-
// We lower empty bounds like `Vec<dyn Copy>:` as
2216-
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2217-
// regular WF checking
2218-
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
2219-
continue;
2215+
match pred.kind().skip_binder() {
2216+
// We lower empty bounds like `Vec<dyn Copy>:` as
2217+
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
2218+
// regular WF checking
2219+
ty::ClauseKind::WellFormed(..)
2220+
// Unstable feature goals cannot be proven in an empty environment so skip them
2221+
| ty::ClauseKind::UnstableFeature(..) => continue,
2222+
_ => {}
22202223
}
2224+
22212225
// Match the existing behavior.
22222226
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
22232227
let pred = self.normalize(span, None, pred);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
764764
ty::ClauseKind::RegionOutlives(_)
765765
| ty::ClauseKind::ConstArgHasType(_, _)
766766
| ty::ClauseKind::WellFormed(_)
767+
| ty::ClauseKind::UnstableFeature(_)
767768
| ty::ClauseKind::ConstEvaluatable(_) => {
768769
bug!(
769770
"unexpected non-`Self` predicate when computing \
@@ -791,6 +792,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
791792
| ty::ClauseKind::ConstArgHasType(_, _)
792793
| ty::ClauseKind::WellFormed(_)
793794
| ty::ClauseKind::ConstEvaluatable(_)
795+
| ty::ClauseKind::UnstableFeature(_)
794796
| ty::ClauseKind::HostEffect(..) => {
795797
bug!(
796798
"unexpected non-`Self` predicate when computing \

0 commit comments

Comments
 (0)