Stop interning stability.
This commit is contained in:
parent
cb4ee81ef5
commit
227d912489
7 changed files with 24 additions and 47 deletions
|
@ -129,12 +129,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
|
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
|
||||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
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) }
|
def_ident_span => { cdata.opt_item_ident(def_id.index, &tcx.sess).map(|ident| ident.span) }
|
||||||
lookup_stability => {
|
lookup_stability => { cdata.get_stability(def_id.index) }
|
||||||
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
|
lookup_const_stability => { cdata.get_const_stability(def_id.index) }
|
||||||
}
|
|
||||||
lookup_const_stability => {
|
|
||||||
cdata.get_const_stability(def_id.index).map(|s| tcx.intern_const_stability(s))
|
|
||||||
}
|
|
||||||
lookup_deprecation_entry => {
|
lookup_deprecation_entry => {
|
||||||
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
|
|
||||||
let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
|
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 =
|
let macros =
|
||||||
self.lazy(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
|
self.lazy(tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index));
|
||||||
let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans();
|
let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans();
|
||||||
|
|
|
@ -57,11 +57,11 @@ impl DeprecationEntry {
|
||||||
|
|
||||||
/// A stability index, giving the stability level for items and methods.
|
/// A stability index, giving the stability level for items and methods.
|
||||||
#[derive(HashStable, Debug)]
|
#[derive(HashStable, Debug)]
|
||||||
pub struct Index<'tcx> {
|
pub struct Index {
|
||||||
/// This is mostly a cache, except the stabilities of local items
|
/// This is mostly a cache, except the stabilities of local items
|
||||||
/// are filled by the annotator.
|
/// are filled by the annotator.
|
||||||
pub stab_map: FxHashMap<LocalDefId, &'tcx Stability>,
|
pub stab_map: FxHashMap<LocalDefId, Stability>,
|
||||||
pub const_stab_map: FxHashMap<LocalDefId, &'tcx ConstStability>,
|
pub const_stab_map: FxHashMap<LocalDefId, ConstStability>,
|
||||||
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
|
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
|
||||||
|
|
||||||
/// Maps for each crate whether it is part of the staged API.
|
/// 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>,
|
pub active_features: FxHashSet<Symbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Index<'tcx> {
|
impl Index {
|
||||||
pub fn local_stability(&self, def_id: LocalDefId) -> Option<&'tcx Stability> {
|
pub fn local_stability(&self, def_id: LocalDefId) -> Option<Stability> {
|
||||||
self.stab_map.get(&def_id).copied()
|
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()
|
self.const_stab_map.get(&def_id).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match stability {
|
match stability {
|
||||||
Some(&Stability {
|
Some(Stability {
|
||||||
level: attr::Unstable { reason, issue, is_soft }, feature, ..
|
level: attr::Unstable { reason, issue, is_soft }, feature, ..
|
||||||
}) => {
|
}) => {
|
||||||
if span.allows_unstable(feature) {
|
if span.allows_unstable(feature) {
|
||||||
|
|
|
@ -1010,12 +1010,12 @@ rustc_queries! {
|
||||||
separate_provide_extern
|
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) }
|
desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
|
||||||
separate_provide_extern
|
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) }
|
desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
|
||||||
separate_provide_extern
|
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()) }
|
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>)
|
storage(ArenaCacheSelector<'tcx>)
|
||||||
eval_always
|
eval_always
|
||||||
desc { "calculating the stability index for the local crate" }
|
desc { "calculating the stability index for the local crate" }
|
||||||
|
|
|
@ -24,7 +24,6 @@ use crate::ty::{
|
||||||
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
|
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
|
||||||
};
|
};
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_attr as attr;
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_data_structures::memmap::Mmap;
|
use rustc_data_structures::memmap::Mmap;
|
||||||
|
@ -116,12 +115,6 @@ pub struct CtxtInterners<'tcx> {
|
||||||
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
|
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
|
||||||
layout: InternedSet<'tcx, Layout>,
|
layout: InternedSet<'tcx, Layout>,
|
||||||
adt_def: InternedSet<'tcx, AdtDef>,
|
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> {
|
impl<'tcx> CtxtInterners<'tcx> {
|
||||||
|
@ -143,8 +136,6 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||||
bound_variable_kinds: Default::default(),
|
bound_variable_kinds: Default::default(),
|
||||||
layout: Default::default(),
|
layout: Default::default(),
|
||||||
adt_def: 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)
|
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(())
|
self.stability_index(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1981,12 +1972,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
|
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
|
||||||
writeln!(fmt, "Region interner: #{}", self.0.interners.region.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!(
|
writeln!(
|
||||||
fmt,
|
fmt,
|
||||||
"Const Allocation interner: #{}",
|
"Const Allocation interner: #{}",
|
||||||
|
@ -2174,8 +2159,6 @@ direct_interners_old! {
|
||||||
const_allocation: intern_const_alloc(Allocation),
|
const_allocation: intern_const_alloc(Allocation),
|
||||||
layout: intern_layout(Layout),
|
layout: intern_layout(Layout),
|
||||||
adt_def: intern_adt_def(AdtDef),
|
adt_def: intern_adt_def(AdtDef),
|
||||||
stability: intern_stability(attr::Stability),
|
|
||||||
const_stability: intern_const_stability(attr::ConstStability),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! slice_interners {
|
macro_rules! slice_interners {
|
||||||
|
|
|
@ -87,9 +87,9 @@ impl InheritStability {
|
||||||
// A private tree-walker for producing an Index.
|
// A private tree-walker for producing an Index.
|
||||||
struct Annotator<'a, 'tcx> {
|
struct Annotator<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
index: &'a mut Index<'tcx>,
|
index: &'a mut Index,
|
||||||
parent_stab: Option<&'tcx Stability>,
|
parent_stab: Option<Stability>,
|
||||||
parent_const_stab: Option<&'tcx ConstStability>,
|
parent_const_stab: Option<ConstStability>,
|
||||||
parent_depr: Option<DeprecationEntry>,
|
parent_depr: Option<DeprecationEntry>,
|
||||||
in_trait_impl: bool,
|
in_trait_impl: bool,
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
let mut const_span = None;
|
let mut const_span = None;
|
||||||
|
|
||||||
let const_stab = const_stab.map(|(const_stab, const_span_node)| {
|
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);
|
self.index.const_stab_map.insert(def_id, const_stab);
|
||||||
const_span = Some(const_span_node);
|
const_span = Some(const_span_node);
|
||||||
const_stab
|
const_stab
|
||||||
|
@ -228,7 +227,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("annotate: found {:?}", stab);
|
debug!("annotate: found {:?}", stab);
|
||||||
let stab = self.tcx.intern_stability(stab);
|
|
||||||
|
|
||||||
// Check if deprecated_since < stable_since. If it is,
|
// Check if deprecated_since < stable_since. If it is,
|
||||||
// this is *almost surely* an accident.
|
// this is *almost surely* an accident.
|
||||||
|
@ -299,8 +297,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
fn recurse_with_stability_attrs(
|
fn recurse_with_stability_attrs(
|
||||||
&mut self,
|
&mut self,
|
||||||
depr: Option<DeprecationEntry>,
|
depr: Option<DeprecationEntry>,
|
||||||
stab: Option<&'tcx Stability>,
|
stab: Option<Stability>,
|
||||||
const_stab: Option<&'tcx ConstStability>,
|
const_stab: Option<ConstStability>,
|
||||||
f: impl FnOnce(&mut Self),
|
f: impl FnOnce(&mut Self),
|
||||||
) {
|
) {
|
||||||
// These will be `Some` if this item changes the corresponding stability attribute.
|
// 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).
|
// 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 =
|
let is_staged_api =
|
||||||
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
|
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
|
||||||
let mut staged_api = FxHashMap::default();
|
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 \
|
let reason = "this crate is being loaded from the sysroot, an \
|
||||||
unstable location; did you mean to load this crate \
|
unstable location; did you mean to load this crate \
|
||||||
from crates.io via `Cargo.toml` instead?";
|
from crates.io via `Cargo.toml` instead?";
|
||||||
let stability = tcx.intern_stability(Stability {
|
let stability = Stability {
|
||||||
level: attr::StabilityLevel::Unstable {
|
level: attr::StabilityLevel::Unstable {
|
||||||
reason: Some(Symbol::intern(reason)),
|
reason: Some(Symbol::intern(reason)),
|
||||||
issue: NonZeroU32::new(27812),
|
issue: NonZeroU32::new(27812),
|
||||||
is_soft: false,
|
is_soft: false,
|
||||||
},
|
},
|
||||||
feature: sym::rustc_private,
|
feature: sym::rustc_private,
|
||||||
});
|
};
|
||||||
annotator.parent_stab = Some(stability);
|
annotator.parent_stab = Some(stability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -381,12 +381,12 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item {
|
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))
|
self.def_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
|
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> {
|
crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue