Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 227d912

Browse files
committed
Stop interning stability.
1 parent cb4ee81 commit 227d912

File tree

7 files changed

+24
-47
lines changed

7 files changed

+24
-47
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
129129
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
130130
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
131131
def_ident_span => { cdata.opt_item_ident(def_id.index, &tcx.sess).map(|ident| ident.span) }
132-
lookup_stability => {
133-
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
134-
}
135-
lookup_const_stability => {
136-
cdata.get_const_stability(def_id.index).map(|s| tcx.intern_const_stability(s))
137-
}
132+
lookup_stability => { cdata.get_stability(def_id.index) }
133+
lookup_const_stability => { cdata.get_const_stability(def_id.index) }
138134
lookup_deprecation_entry => {
139135
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
140136
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16611661
let hir = tcx.hir();
16621662

16631663
let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
1664-
let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied();
1664+
let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX));
16651665
let macros =
16661666
self.lazy(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
16671667
let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans();

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl DeprecationEntry {
5757

5858
/// A stability index, giving the stability level for items and methods.
5959
#[derive(HashStable, Debug)]
60-
pub struct Index<'tcx> {
60+
pub struct Index {
6161
/// This is mostly a cache, except the stabilities of local items
6262
/// are filled by the annotator.
63-
pub stab_map: FxHashMap<LocalDefId, &'tcx Stability>,
64-
pub const_stab_map: FxHashMap<LocalDefId, &'tcx ConstStability>,
63+
pub stab_map: FxHashMap<LocalDefId, Stability>,
64+
pub const_stab_map: FxHashMap<LocalDefId, ConstStability>,
6565
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
6666

6767
/// Maps for each crate whether it is part of the staged API.
@@ -71,12 +71,12 @@ pub struct Index<'tcx> {
7171
pub active_features: FxHashSet<Symbol>,
7272
}
7373

74-
impl<'tcx> Index<'tcx> {
75-
pub fn local_stability(&self, def_id: LocalDefId) -> Option<&'tcx Stability> {
74+
impl Index {
75+
pub fn local_stability(&self, def_id: LocalDefId) -> Option<Stability> {
7676
self.stab_map.get(&def_id).copied()
7777
}
7878

79-
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<&'tcx ConstStability> {
79+
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<ConstStability> {
8080
self.const_stab_map.get(&def_id).copied()
8181
}
8282

@@ -416,7 +416,7 @@ impl<'tcx> TyCtxt<'tcx> {
416416
}
417417

418418
match stability {
419-
Some(&Stability {
419+
Some(Stability {
420420
level: attr::Unstable { reason, issue, is_soft }, feature, ..
421421
}) => {
422422
if span.allows_unstable(feature) {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,12 @@ rustc_queries! {
10101010
separate_provide_extern
10111011
}
10121012

1013-
query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
1013+
query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
10141014
desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
10151015
separate_provide_extern
10161016
}
10171017

1018-
query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
1018+
query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
10191019
desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
10201020
separate_provide_extern
10211021
}
@@ -1626,7 +1626,7 @@ rustc_queries! {
16261626
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
16271627
}
16281628

1629-
query stability_index(_: ()) -> stability::Index<'tcx> {
1629+
query stability_index(_: ()) -> stability::Index {
16301630
storage(ArenaCacheSelector<'tcx>)
16311631
eval_always
16321632
desc { "calculating the stability index for the local crate" }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::ty::{
2424
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
2525
};
2626
use rustc_ast as ast;
27-
use rustc_attr as attr;
2827
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2928
use rustc_data_structures::intern::Interned;
3029
use rustc_data_structures::memmap::Mmap;
@@ -116,12 +115,6 @@ pub struct CtxtInterners<'tcx> {
116115
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
117116
layout: InternedSet<'tcx, Layout>,
118117
adt_def: InternedSet<'tcx, AdtDef>,
119-
120-
/// `#[stable]` and `#[unstable]` attributes
121-
stability: InternedSet<'tcx, attr::Stability>,
122-
123-
/// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes
124-
const_stability: InternedSet<'tcx, attr::ConstStability>,
125118
}
126119

127120
impl<'tcx> CtxtInterners<'tcx> {
@@ -143,8 +136,6 @@ impl<'tcx> CtxtInterners<'tcx> {
143136
bound_variable_kinds: Default::default(),
144137
layout: Default::default(),
145138
adt_def: Default::default(),
146-
stability: Default::default(),
147-
const_stability: Default::default(),
148139
}
149140
}
150141

@@ -1271,7 +1262,7 @@ impl<'tcx> TyCtxt<'tcx> {
12711262
self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did)
12721263
}
12731264

1274-
pub fn stability(self) -> &'tcx stability::Index<'tcx> {
1265+
pub fn stability(self) -> &'tcx stability::Index {
12751266
self.stability_index(())
12761267
}
12771268

@@ -1981,12 +1972,6 @@ impl<'tcx> TyCtxt<'tcx> {
19811972

19821973
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
19831974
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
1984-
writeln!(fmt, "Stability interner: #{}", self.0.interners.stability.len())?;
1985-
writeln!(
1986-
fmt,
1987-
"Const Stability interner: #{}",
1988-
self.0.interners.const_stability.len()
1989-
)?;
19901975
writeln!(
19911976
fmt,
19921977
"Const Allocation interner: #{}",
@@ -2174,8 +2159,6 @@ direct_interners_old! {
21742159
const_allocation: intern_const_alloc(Allocation),
21752160
layout: intern_layout(Layout),
21762161
adt_def: intern_adt_def(AdtDef),
2177-
stability: intern_stability(attr::Stability),
2178-
const_stability: intern_const_stability(attr::ConstStability),
21792162
}
21802163

21812164
macro_rules! slice_interners {

compiler/rustc_passes/src/stability.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ impl InheritStability {
8787
// A private tree-walker for producing an Index.
8888
struct Annotator<'a, 'tcx> {
8989
tcx: TyCtxt<'tcx>,
90-
index: &'a mut Index<'tcx>,
91-
parent_stab: Option<&'tcx Stability>,
92-
parent_const_stab: Option<&'tcx ConstStability>,
90+
index: &'a mut Index,
91+
parent_stab: Option<Stability>,
92+
parent_const_stab: Option<ConstStability>,
9393
parent_depr: Option<DeprecationEntry>,
9494
in_trait_impl: bool,
9595
}
@@ -171,7 +171,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
171171
let mut const_span = None;
172172

173173
let const_stab = const_stab.map(|(const_stab, const_span_node)| {
174-
let const_stab = self.tcx.intern_const_stability(const_stab);
175174
self.index.const_stab_map.insert(def_id, const_stab);
176175
const_span = Some(const_span_node);
177176
const_stab
@@ -228,7 +227,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
228227
}
229228

230229
debug!("annotate: found {:?}", stab);
231-
let stab = self.tcx.intern_stability(stab);
232230

233231
// Check if deprecated_since < stable_since. If it is,
234232
// this is *almost surely* an accident.
@@ -299,8 +297,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
299297
fn recurse_with_stability_attrs(
300298
&mut self,
301299
depr: Option<DeprecationEntry>,
302-
stab: Option<&'tcx Stability>,
303-
const_stab: Option<&'tcx ConstStability>,
300+
stab: Option<Stability>,
301+
const_stab: Option<ConstStability>,
304302
f: impl FnOnce(&mut Self),
305303
) {
306304
// These will be `Some` if this item changes the corresponding stability attribute.
@@ -655,7 +653,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
655653
// stable (assuming they have not inherited instability from their parent).
656654
}
657655

658-
fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
656+
fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
659657
let is_staged_api =
660658
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
661659
let mut staged_api = FxHashMap::default();
@@ -698,14 +696,14 @@ fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
698696
let reason = "this crate is being loaded from the sysroot, an \
699697
unstable location; did you mean to load this crate \
700698
from crates.io via `Cargo.toml` instead?";
701-
let stability = tcx.intern_stability(Stability {
699+
let stability = Stability {
702700
level: attr::StabilityLevel::Unstable {
703701
reason: Some(Symbol::intern(reason)),
704702
issue: NonZeroU32::new(27812),
705703
is_soft: false,
706704
},
707705
feature: sym::rustc_private,
708-
});
706+
};
709707
annotator.parent_stab = Some(stability);
710708
}
711709

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
381381
}
382382

383383
impl Item {
384-
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<&'tcx Stability> {
384+
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
385385
self.def_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
386386
}
387387

388388
crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
389-
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did)).map(|cs| *cs)
389+
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
390390
}
391391

392392
crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {

0 commit comments

Comments
 (0)