Skip to content

Commit 5597f02

Browse files
committed
Auto merge of #143845 - cjgillot:stability-query, r=<try>
Split-up stability_index query r? `@ghost` for perf
2 parents 915e535 + 609a38d commit 5597f02

26 files changed

+729
-848
lines changed

compiler/rustc_hir/src/target.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum Target {
4141
Union,
4242
Trait,
4343
TraitAlias,
44-
Impl,
44+
Impl { of_trait: bool },
4545
Expression,
4646
Statement,
4747
Arm,
@@ -51,7 +51,7 @@ pub enum Target {
5151
ForeignFn,
5252
ForeignStatic,
5353
ForeignTy,
54-
GenericParam(GenericParamKind),
54+
GenericParam { kind: GenericParamKind, has_default: bool },
5555
MacroDef,
5656
Param,
5757
PatField,
@@ -86,14 +86,14 @@ impl Target {
8686
| Target::Union
8787
| Target::Trait
8888
| Target::TraitAlias
89-
| Target::Impl
89+
| Target::Impl { .. }
9090
| Target::Expression
9191
| Target::Statement
9292
| Target::Arm
9393
| Target::ForeignFn
9494
| Target::ForeignStatic
9595
| Target::ForeignTy
96-
| Target::GenericParam(_)
96+
| Target::GenericParam { .. }
9797
| Target::MacroDef
9898
| Target::Param
9999
| Target::PatField
@@ -119,7 +119,7 @@ impl Target {
119119
ItemKind::Union(..) => Target::Union,
120120
ItemKind::Trait(..) => Target::Trait,
121121
ItemKind::TraitAlias(..) => Target::TraitAlias,
122-
ItemKind::Impl { .. } => Target::Impl,
122+
ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
123123
}
124124
}
125125

@@ -141,7 +141,7 @@ impl Target {
141141
DefKind::Union => Target::Union,
142142
DefKind::Trait => Target::Trait,
143143
DefKind::TraitAlias => Target::TraitAlias,
144-
DefKind::Impl { .. } => Target::Impl,
144+
DefKind::Impl { of_trait } => Target::Impl { of_trait },
145145
_ => panic!("impossible case reached"),
146146
}
147147
}
@@ -169,11 +169,17 @@ impl Target {
169169

170170
pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
171171
match generic_param.kind {
172-
hir::GenericParamKind::Type { .. } => Target::GenericParam(GenericParamKind::Type),
172+
hir::GenericParamKind::Type { default, .. } => Target::GenericParam {
173+
kind: GenericParamKind::Type,
174+
has_default: default.is_some(),
175+
},
173176
hir::GenericParamKind::Lifetime { .. } => {
174-
Target::GenericParam(GenericParamKind::Lifetime)
177+
Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }
175178
}
176-
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
179+
hir::GenericParamKind::Const { default, .. } => Target::GenericParam {
180+
kind: GenericParamKind::Const,
181+
has_default: default.is_some(),
182+
},
177183
}
178184
}
179185

@@ -196,7 +202,8 @@ impl Target {
196202
Target::Union => "union",
197203
Target::Trait => "trait",
198204
Target::TraitAlias => "trait alias",
199-
Target::Impl => "implementation block",
205+
Target::Impl { of_trait: false } => "inherent implementation block",
206+
Target::Impl { of_trait: true } => "trait implementation block",
200207
Target::Expression => "expression",
201208
Target::Statement => "statement",
202209
Target::Arm => "match arm",
@@ -210,7 +217,7 @@ impl Target {
210217
Target::ForeignFn => "foreign function",
211218
Target::ForeignStatic => "foreign static item",
212219
Target::ForeignTy => "foreign type",
213-
Target::GenericParam(kind) => match kind {
220+
Target::GenericParam { kind, has_default: _ } => match kind {
214221
GenericParamKind::Type => "type parameter",
215222
GenericParamKind::Lifetime => "lifetime parameter",
216223
GenericParamKind::Const => "const parameter",

compiler/rustc_interface/src/passes.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,18 +1054,12 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10541054
tcx.ensure_ok().check_mod_unstable_api_usage(module);
10551055
});
10561056
},
1057-
{
1058-
sess.time("unused_lib_feature_checking", || {
1059-
rustc_passes::stability::check_unused_or_stable_features(tcx)
1060-
});
1061-
},
10621057
{
10631058
// We force these queries to run,
10641059
// since they might not otherwise get called.
10651060
// This marks the corresponding crate-level attributes
10661061
// as used, and ensures that their values are valid.
10671062
tcx.ensure_ok().limits(());
1068-
tcx.ensure_ok().stability_index(());
10691063
}
10701064
);
10711065
});

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ use rustc_ast::NodeId;
77
use rustc_attr_data_structures::{
88
self as attrs, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
99
};
10-
use rustc_data_structures::unord::UnordMap;
1110
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
1211
use rustc_feature::GateIssue;
13-
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1413
use rustc_hir::{self as hir, HirId};
1514
use rustc_macros::{Decodable, Encodable, HashStable, Subdiagnostic};
1615
use rustc_session::Session;
@@ -65,48 +64,6 @@ impl DeprecationEntry {
6564
}
6665
}
6766

68-
/// A stability index, giving the stability level for items and methods.
69-
#[derive(HashStable, Debug)]
70-
pub struct Index {
71-
/// This is mostly a cache, except the stabilities of local items
72-
/// are filled by the annotator.
73-
pub stab_map: LocalDefIdMap<Stability>,
74-
pub const_stab_map: LocalDefIdMap<ConstStability>,
75-
pub default_body_stab_map: LocalDefIdMap<DefaultBodyStability>,
76-
pub depr_map: LocalDefIdMap<DeprecationEntry>,
77-
/// Mapping from feature name to feature name based on the `implied_by` field of `#[unstable]`
78-
/// attributes. If a `#[unstable(feature = "implier", implied_by = "impliee")]` attribute
79-
/// exists, then this map will have a `impliee -> implier` entry.
80-
///
81-
/// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should
82-
/// specify their implications (both `implies` and `implied_by`). If only one of the two
83-
/// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this
84-
/// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is
85-
/// reported, only the `#[stable]` attribute information is available, so the map is necessary
86-
/// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
87-
/// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
88-
/// unstable feature" error for a feature that was implied.
89-
pub implications: UnordMap<Symbol, Symbol>,
90-
}
91-
92-
impl Index {
93-
pub fn local_stability(&self, def_id: LocalDefId) -> Option<Stability> {
94-
self.stab_map.get(&def_id).copied()
95-
}
96-
97-
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<ConstStability> {
98-
self.const_stab_map.get(&def_id).copied()
99-
}
100-
101-
pub fn local_default_body_stability(&self, def_id: LocalDefId) -> Option<DefaultBodyStability> {
102-
self.default_body_stab_map.get(&def_id).copied()
103-
}
104-
105-
pub fn local_deprecation_entry(&self, def_id: LocalDefId) -> Option<DeprecationEntry> {
106-
self.depr_map.get(&def_id).cloned()
107-
}
108-
}
109-
11067
pub fn report_unstable(
11168
sess: &Session,
11269
feature: Symbol,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
112112
use crate::middle::lib_features::LibFeatures;
113113
use crate::middle::privacy::EffectiveVisibilities;
114114
use crate::middle::resolve_bound_vars::{ObjectLifetimeDefault, ResolveBoundVars, ResolvedArg};
115-
use crate::middle::stability::{self, DeprecationEntry};
115+
use crate::middle::stability::DeprecationEntry;
116116
use crate::mir::interpret::{
117117
EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult,
118118
EvalToValTreeResult, GlobalId, LitToConstInput,
@@ -2166,6 +2166,18 @@ rustc_queries! {
21662166
separate_provide_extern
21672167
arena_cache
21682168
}
2169+
/// Mapping from feature name to feature name based on the `implied_by` field of `#[unstable]`
2170+
/// attributes. If a `#[unstable(feature = "implier", implied_by = "impliee")]` attribute
2171+
/// exists, then this map will have a `impliee -> implier` entry.
2172+
///
2173+
/// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should
2174+
/// specify their implications (both `implies` and `implied_by`). If only one of the two
2175+
/// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this
2176+
/// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is
2177+
/// reported, only the `#[stable]` attribute information is available, so the map is necessary
2178+
/// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
2179+
/// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
2180+
/// unstable feature" error for a feature that was implied.
21692181
query stability_implications(_: CrateNum) -> &'tcx UnordMap<Symbol, Symbol> {
21702182
arena_cache
21712183
desc { "calculating the implications between `#[unstable]` features defined in a crate" }
@@ -2272,11 +2284,6 @@ rustc_queries! {
22722284
desc { "fetching potentially unused trait imports" }
22732285
}
22742286

2275-
query stability_index(_: ()) -> &'tcx stability::Index {
2276-
arena_cache
2277-
eval_always
2278-
desc { "calculating the stability index for the local crate" }
2279-
}
22802287
/// All available crates in the graph, including those that should not be user-facing
22812288
/// (such as private crates).
22822289
query crates(_: ()) -> &'tcx [CrateNum] {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind, Canonica
6565
use crate::lint::lint_level;
6666
use crate::metadata::ModChild;
6767
use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature};
68-
use crate::middle::{resolve_bound_vars, stability};
68+
use crate::middle::resolve_bound_vars;
6969
use crate::mir::interpret::{self, Allocation, ConstAllocation};
7070
use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted};
7171
use crate::query::plumbing::QuerySystem;
@@ -1799,10 +1799,6 @@ impl<'tcx> TyCtxt<'tcx> {
17991799
)
18001800
}
18011801

1802-
pub fn stability(self) -> &'tcx stability::Index {
1803-
self.stability_index(())
1804-
}
1805-
18061802
pub fn features(self) -> &'tcx rustc_feature::Features {
18071803
self.features_query(())
18081804
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_session::config::CrateType;
3333
use rustc_session::lint;
3434
use rustc_session::lint::builtin::{
3535
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
36-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
36+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES, USELESS_DEPRECATED,
3737
};
3838
use rustc_session::parse::feature_err;
3939
use rustc_span::edition::Edition;
@@ -336,7 +336,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
336336
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn)
337337
}
338338
[sym::automatically_derived, ..] => {
339-
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Impl)
339+
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Impl{of_trait:true})
340340
}
341341
[sym::proc_macro, ..] => {
342342
self.check_proc_macro(hir_id, target, ProcMacroKind::FunctionLike)
@@ -469,7 +469,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
469469
attr: &Attribute,
470470
item: Option<ItemLike<'_>>,
471471
) {
472-
if !matches!(target, Target::Impl)
472+
if !matches!(target, Target::Impl { .. })
473473
|| matches!(
474474
item,
475475
Some(ItemLike::Item(hir::Item { kind: hir::ItemKind::Impl(_impl),.. }))
@@ -573,7 +573,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
573573
Target::Fn
574574
| Target::Closure
575575
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
576-
| Target::Impl
576+
| Target::Impl { .. }
577577
| Target::Mod => return,
578578

579579
// These are "functions", but they aren't allowed because they don't
@@ -964,9 +964,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
964964
let span = meta.span();
965965
if let Some(location) = match target {
966966
Target::AssocTy => {
967-
let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id;
968-
let containing_item = self.tcx.hir_expect_item(parent_def_id);
969-
if Target::from_item(containing_item) == Target::Impl {
967+
if let DefKind::Impl { .. } =
968+
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id))
969+
{
970970
Some("type alias in implementation block")
971971
} else {
972972
None
@@ -989,7 +989,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
989989
| Target::Arm
990990
| Target::ForeignMod
991991
| Target::Closure
992-
| Target::Impl
992+
| Target::Impl { .. }
993993
| Target::WherePredicate => Some(target.name()),
994994
Target::ExternCrate
995995
| Target::Use
@@ -1010,7 +1010,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10101010
| Target::ForeignFn
10111011
| Target::ForeignStatic
10121012
| Target::ForeignTy
1013-
| Target::GenericParam(..)
1013+
| Target::GenericParam { .. }
10141014
| Target::MacroDef
10151015
| Target::PatField
10161016
| Target::ExprField => None,
@@ -1565,7 +1565,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15651565
let article = match target {
15661566
Target::ExternCrate
15671567
| Target::Enum
1568-
| Target::Impl
1568+
| Target::Impl { .. }
15691569
| Target::Expression
15701570
| Target::Arm
15711571
| Target::AssocConst
@@ -2273,6 +2273,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22732273
errors::Deprecated,
22742274
);
22752275
}
2276+
Target::Impl { of_trait: true }
2277+
| Target::GenericParam { has_default: false, kind: _ } => {
2278+
self.tcx.emit_node_span_lint(
2279+
USELESS_DEPRECATED,
2280+
hir_id,
2281+
attr.span(),
2282+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2283+
);
2284+
}
2285+
Target::AssocConst | Target::Method(..) | Target::AssocTy
2286+
if matches!(
2287+
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
2288+
DefKind::Impl { of_trait: true }
2289+
) =>
2290+
{
2291+
self.tcx.emit_node_span_lint(
2292+
USELESS_DEPRECATED,
2293+
hir_id,
2294+
attr.span(),
2295+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2296+
);
2297+
}
22762298
_ => {}
22772299
}
22782300
}

compiler/rustc_passes/src/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
287287
ast::ItemKind::Union(..) => Target::Union,
288288
ast::ItemKind::Trait(_) => Target::Trait,
289289
ast::ItemKind::TraitAlias(..) => Target::TraitAlias,
290-
ast::ItemKind::Impl(_) => Target::Impl,
290+
ast::ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
291291
ast::ItemKind::MacroDef(..) => Target::MacroDef,
292292
ast::ItemKind::MacCall(_) | ast::ItemKind::DelegationMac(_) => {
293293
unreachable!("macros should have been expanded")

0 commit comments

Comments
 (0)