1
Fork 0

Stop interning stability.

This commit is contained in:
Camille GILLOT 2022-02-19 15:36:11 +01:00
parent cb4ee81ef5
commit 227d912489
7 changed files with 24 additions and 47 deletions

View file

@ -129,12 +129,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
def_ident_span => { cdata.opt_item_ident(def_id.index, &tcx.sess).map(|ident| ident.span) }
lookup_stability => {
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
}
lookup_const_stability => {
cdata.get_const_stability(def_id.index).map(|s| tcx.intern_const_stability(s))
}
lookup_stability => { cdata.get_stability(def_id.index) }
lookup_const_stability => { cdata.get_const_stability(def_id.index) }
lookup_deprecation_entry => {
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
}

View file

@ -1661,7 +1661,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let hir = tcx.hir();
let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied();
let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX));
let macros =
self.lazy(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans();

View file

@ -57,11 +57,11 @@ impl DeprecationEntry {
/// A stability index, giving the stability level for items and methods.
#[derive(HashStable, Debug)]
pub struct Index<'tcx> {
pub struct Index {
/// This is mostly a cache, except the stabilities of local items
/// are filled by the annotator.
pub stab_map: FxHashMap<LocalDefId, &'tcx Stability>,
pub const_stab_map: FxHashMap<LocalDefId, &'tcx ConstStability>,
pub stab_map: FxHashMap<LocalDefId, Stability>,
pub const_stab_map: FxHashMap<LocalDefId, ConstStability>,
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
/// Maps for each crate whether it is part of the staged API.
@ -71,12 +71,12 @@ pub struct Index<'tcx> {
pub active_features: FxHashSet<Symbol>,
}
impl<'tcx> Index<'tcx> {
pub fn local_stability(&self, def_id: LocalDefId) -> Option<&'tcx Stability> {
impl Index {
pub fn local_stability(&self, def_id: LocalDefId) -> Option<Stability> {
self.stab_map.get(&def_id).copied()
}
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<&'tcx ConstStability> {
pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<ConstStability> {
self.const_stab_map.get(&def_id).copied()
}
@ -416,7 +416,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
match stability {
Some(&Stability {
Some(Stability {
level: attr::Unstable { reason, issue, is_soft }, feature, ..
}) => {
if span.allows_unstable(feature) {

View file

@ -1010,12 +1010,12 @@ rustc_queries! {
separate_provide_extern
}
query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
@ -1626,7 +1626,7 @@ rustc_queries! {
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
}
query stability_index(_: ()) -> stability::Index<'tcx> {
query stability_index(_: ()) -> stability::Index {
storage(ArenaCacheSelector<'tcx>)
eval_always
desc { "calculating the stability index for the local crate" }

View file

@ -24,7 +24,6 @@ use crate::ty::{
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
};
use rustc_ast as ast;
use rustc_attr as attr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::intern::Interned;
use rustc_data_structures::memmap::Mmap;
@ -116,12 +115,6 @@ pub struct CtxtInterners<'tcx> {
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
layout: InternedSet<'tcx, Layout>,
adt_def: InternedSet<'tcx, AdtDef>,
/// `#[stable]` and `#[unstable]` attributes
stability: InternedSet<'tcx, attr::Stability>,
/// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes
const_stability: InternedSet<'tcx, attr::ConstStability>,
}
impl<'tcx> CtxtInterners<'tcx> {
@ -143,8 +136,6 @@ impl<'tcx> CtxtInterners<'tcx> {
bound_variable_kinds: Default::default(),
layout: Default::default(),
adt_def: Default::default(),
stability: Default::default(),
const_stability: Default::default(),
}
}
@ -1271,7 +1262,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did)
}
pub fn stability(self) -> &'tcx stability::Index<'tcx> {
pub fn stability(self) -> &'tcx stability::Index {
self.stability_index(())
}
@ -1981,12 +1972,6 @@ impl<'tcx> TyCtxt<'tcx> {
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
writeln!(fmt, "Stability interner: #{}", self.0.interners.stability.len())?;
writeln!(
fmt,
"Const Stability interner: #{}",
self.0.interners.const_stability.len()
)?;
writeln!(
fmt,
"Const Allocation interner: #{}",
@ -2174,8 +2159,6 @@ direct_interners_old! {
const_allocation: intern_const_alloc(Allocation),
layout: intern_layout(Layout),
adt_def: intern_adt_def(AdtDef),
stability: intern_stability(attr::Stability),
const_stability: intern_const_stability(attr::ConstStability),
}
macro_rules! slice_interners {

View file

@ -87,9 +87,9 @@ impl InheritStability {
// A private tree-walker for producing an Index.
struct Annotator<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
index: &'a mut Index<'tcx>,
parent_stab: Option<&'tcx Stability>,
parent_const_stab: Option<&'tcx ConstStability>,
index: &'a mut Index,
parent_stab: Option<Stability>,
parent_const_stab: Option<ConstStability>,
parent_depr: Option<DeprecationEntry>,
in_trait_impl: bool,
}
@ -171,7 +171,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
let mut const_span = None;
let const_stab = const_stab.map(|(const_stab, const_span_node)| {
let const_stab = self.tcx.intern_const_stability(const_stab);
self.index.const_stab_map.insert(def_id, const_stab);
const_span = Some(const_span_node);
const_stab
@ -228,7 +227,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
}
debug!("annotate: found {:?}", stab);
let stab = self.tcx.intern_stability(stab);
// Check if deprecated_since < stable_since. If it is,
// this is *almost surely* an accident.
@ -299,8 +297,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
fn recurse_with_stability_attrs(
&mut self,
depr: Option<DeprecationEntry>,
stab: Option<&'tcx Stability>,
const_stab: Option<&'tcx ConstStability>,
stab: Option<Stability>,
const_stab: Option<ConstStability>,
f: impl FnOnce(&mut Self),
) {
// These will be `Some` if this item changes the corresponding stability attribute.
@ -655,7 +653,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
// stable (assuming they have not inherited instability from their parent).
}
fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
let is_staged_api =
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
let mut staged_api = FxHashMap::default();
@ -698,14 +696,14 @@ fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
let reason = "this crate is being loaded from the sysroot, an \
unstable location; did you mean to load this crate \
from crates.io via `Cargo.toml` instead?";
let stability = tcx.intern_stability(Stability {
let stability = Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
issue: NonZeroU32::new(27812),
is_soft: false,
},
feature: sym::rustc_private,
});
};
annotator.parent_stab = Some(stability);
}

View file

@ -381,12 +381,12 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
}
impl Item {
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<&'tcx Stability> {
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
self.def_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
}
crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did)).map(|cs| *cs)
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
}
crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {