提交 7ccfe2ff 编写于 作者: B bors

Auto merge of #94129 - cjgillot:rmeta-table, r=petrochenkov

Back more metadata using per-query tables

r? `@ghost`
......@@ -11,7 +11,6 @@
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell};
use rustc_data_structures::unhash::UnhashMap;
use rustc_errors::ErrorReported;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive};
use rustc_hir as hir;
......@@ -21,10 +20,11 @@
use rustc_hir::diagnostic_items::DiagnosticItems;
use rustc_hir::lang_items;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use rustc_middle::middle::stability::DeprecationEntry;
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::mir::{self, Body, Promoted};
use rustc_middle::thir;
use rustc_middle::ty::codec::TyDecoder;
use rustc_middle::ty::fast_reject::SimplifiedType;
......@@ -278,6 +278,99 @@ fn decode<M: Metadata<'a, 'tcx>>(
}
}
trait LazyQueryDecodable<'a, 'tcx, T> {
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
err: impl FnOnce() -> !,
) -> T;
}
impl<'a, 'tcx, T> LazyQueryDecodable<'a, 'tcx, T> for Option<Lazy<T>>
where
T: Decodable<DecodeContext<'a, 'tcx>>,
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
err: impl FnOnce() -> !,
) -> T {
if let Some(l) = self { l.decode((cdata, tcx)) } else { err() }
}
}
impl<'a, 'tcx, T> LazyQueryDecodable<'a, 'tcx, &'tcx T> for Option<Lazy<T>>
where
T: Decodable<DecodeContext<'a, 'tcx>>,
T: ArenaAllocatable<'tcx>,
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
err: impl FnOnce() -> !,
) -> &'tcx T {
if let Some(l) = self { tcx.arena.alloc(l.decode((cdata, tcx))) } else { err() }
}
}
impl<'a, 'tcx, T> LazyQueryDecodable<'a, 'tcx, Option<T>> for Option<Lazy<T>>
where
T: Decodable<DecodeContext<'a, 'tcx>>,
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
_err: impl FnOnce() -> !,
) -> Option<T> {
self.map(|l| l.decode((cdata, tcx)))
}
}
impl<'a, 'tcx, T, E> LazyQueryDecodable<'a, 'tcx, Result<Option<T>, E>> for Option<Lazy<T>>
where
T: Decodable<DecodeContext<'a, 'tcx>>,
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
_err: impl FnOnce() -> !,
) -> Result<Option<T>, E> {
Ok(self.map(|l| l.decode((cdata, tcx))))
}
}
impl<'a, 'tcx, T> LazyQueryDecodable<'a, 'tcx, &'tcx [T]> for Option<Lazy<[T], usize>>
where
T: Decodable<DecodeContext<'a, 'tcx>> + Copy,
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
_err: impl FnOnce() -> !,
) -> &'tcx [T] {
if let Some(l) = self { tcx.arena.alloc_from_iter(l.decode((cdata, tcx))) } else { &[] }
}
}
impl<'a, 'tcx> LazyQueryDecodable<'a, 'tcx, Option<DeprecationEntry>>
for Option<Lazy<attr::Deprecation>>
{
fn decode_query(
self,
cdata: CrateMetadataRef<'a>,
tcx: TyCtxt<'tcx>,
_err: impl FnOnce() -> !,
) -> Option<DeprecationEntry> {
self.map(|l| l.decode((cdata, tcx))).map(DeprecationEntry::external)
}
}
impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
......@@ -714,9 +807,17 @@ fn raw_proc_macro(self, id: DefIndex) -> &'a ProcMacro {
&self.raw_proc_macros.unwrap()[pos]
}
fn opt_item_name(self, item_index: DefIndex) -> Option<Symbol> {
self.def_key(item_index).disambiguated_data.data.get_opt_name()
}
fn item_name(self, item_index: DefIndex) -> Symbol {
self.opt_item_name(item_index).expect("no encoded ident for item")
}
fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?;
let span = match self.root.tables.ident_span.get(self, item_index) {
let name = self.opt_item_name(item_index)?;
let span = match self.root.tables.def_ident_span.get(self, item_index) {
Some(lazy_span) => lazy_span.decode((self, sess)),
None => {
// FIXME: this weird case of a name with no span is specific to `extern crate`
......@@ -750,20 +851,22 @@ fn kind(self, item_id: DefIndex) -> EntryKind {
}
fn def_kind(self, item_id: DefIndex) -> DefKind {
self.root.tables.def_kind.get(self, item_id).map(|k| k.decode(self)).unwrap_or_else(|| {
bug!(
"CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}",
item_id,
self.root.name,
self.cnum,
)
})
self.root.tables.opt_def_kind.get(self, item_id).map(|k| k.decode(self)).unwrap_or_else(
|| {
bug!(
"CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}",
item_id,
self.root.name,
self.cnum,
)
},
)
}
fn get_span(self, index: DefIndex, sess: &Session) -> Span {
self.root
.tables
.span
.def_span
.get(self, index)
.unwrap_or_else(|| panic!("Missing span for {:?}", index))
.decode((self, sess))
......@@ -831,13 +934,7 @@ fn get_trait_def(self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
}
}
fn get_variant(
self,
kind: &EntryKind,
index: DefIndex,
parent_did: DefId,
sess: &Session,
) -> ty::VariantDef {
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
let data = match kind {
EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => {
data.decode(self)
......@@ -857,7 +954,7 @@ fn get_variant(
let ctor_did = data.ctor.map(|index| self.local_def_id(index));
ty::VariantDef::new(
self.item_ident(index, sess).name,
self.item_name(index),
variant_did,
ctor_did,
data.discr,
......@@ -869,7 +966,7 @@ fn get_variant(
.decode(self)
.map(|index| ty::FieldDef {
did: self.local_def_id(index),
name: self.item_ident(index, sess).name,
name: self.item_name(index),
vis: self.get_visibility(index),
})
.collect(),
......@@ -899,133 +996,31 @@ fn get_adt_def(self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> &'tcx ty::AdtDef {
.get(self, item_id)
.unwrap_or_else(Lazy::empty)
.decode(self)
.map(|index| self.get_variant(&self.kind(index), index, did, tcx.sess))
.map(|index| self.get_variant(&self.kind(index), index, did))
.collect()
} else {
std::iter::once(self.get_variant(&kind, item_id, did, tcx.sess)).collect()
std::iter::once(self.get_variant(&kind, item_id, did)).collect()
};
tcx.alloc_adt_def(did, adt_kind, variants, repr)
}
fn get_explicit_predicates(
self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.tables.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
}
fn get_inferred_outlives(
self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
self.root
.tables
.inferred_outlives
.get(self, item_id)
.map(|predicates| tcx.arena.alloc_from_iter(predicates.decode((self, tcx))))
.unwrap_or_default()
}
fn get_super_predicates(
self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.tables.super_predicates.get(self, item_id).unwrap().decode((self, tcx))
}
fn get_explicit_item_bounds(
self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
self.root
.tables
.explicit_item_bounds
.get(self, item_id)
.map(|bounds| tcx.arena.alloc_from_iter(bounds.decode((self, tcx))))
.unwrap_or_default()
}
fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics {
self.root.tables.generics.get(self, item_id).unwrap().decode((self, sess))
}
fn get_type(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
self.root
.tables
.ty
.get(self, id)
.unwrap_or_else(|| panic!("Not a type: {:?}", id))
.decode((self, tcx))
}
fn get_stability(self, id: DefIndex) -> Option<attr::Stability> {
self.root.tables.stability.get(self, id).map(|stab| stab.decode(self))
}
fn get_const_stability(self, id: DefIndex) -> Option<attr::ConstStability> {
self.root.tables.const_stability.get(self, id).map(|stab| stab.decode(self))
}
fn get_deprecation(self, id: DefIndex) -> Option<attr::Deprecation> {
self.root.tables.deprecation.get(self, id).map(|depr| depr.decode(self))
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
}
fn get_visibility(self, id: DefIndex) -> ty::Visibility {
self.root.tables.visibility.get(self, id).unwrap().decode(self)
}
fn get_impl_data(self, id: DefIndex) -> ImplData {
match self.kind(id) {
EntryKind::Impl(data) => data.decode(self),
_ => bug!(),
}
}
fn get_parent_impl(self, id: DefIndex) -> Option<DefId> {
self.get_impl_data(id).parent_impl
}
fn get_impl_polarity(self, id: DefIndex) -> ty::ImplPolarity {
self.get_impl_data(id).polarity
}
fn get_impl_defaultness(self, id: DefIndex) -> hir::Defaultness {
self.get_impl_data(id).defaultness
}
fn get_impl_constness(self, id: DefIndex) -> hir::Constness {
self.get_impl_data(id).constness
}
fn get_trait_item_def_id(self, id: DefIndex) -> Option<DefId> {
self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode(self))
}
fn get_coerce_unsized_info(self, id: DefIndex) -> Option<ty::adjustment::CoerceUnsizedInfo> {
self.get_impl_data(id).coerce_unsized_info
}
fn get_impl_trait(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
}
fn get_expn_that_defined(self, id: DefIndex, sess: &Session) -> ExpnId {
self.root.tables.expn_that_defined.get(self, id).unwrap().decode((self, sess))
}
fn get_const_param_default(
self,
tcx: TyCtxt<'tcx>,
id: DefIndex,
) -> rustc_middle::ty::Const<'tcx> {
self.root.tables.const_defaults.get(self, id).unwrap().decode((self, tcx))
}
/// Iterates over all the stability attributes in the given crate.
fn get_lib_features(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] {
tcx.arena.alloc_from_iter(self.root.lib_features.decode(self))
......@@ -1163,7 +1158,7 @@ fn is_ctfe_mir_available(self, id: DefIndex) -> bool {
}
fn is_item_mir_available(self, id: DefIndex) -> bool {
self.root.tables.mir.get(self, id).is_some()
self.root.tables.optimized_mir.get(self, id).is_some()
}
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
......@@ -1175,75 +1170,6 @@ fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
}
}
fn get_optimized_mir(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
self.root
.tables
.mir
.get(self, id)
.unwrap_or_else(|| {
bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
})
.decode((self, tcx))
}
fn get_mir_for_ctfe(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
self.root
.tables
.mir_for_ctfe
.get(self, id)
.unwrap_or_else(|| {
bug!("get_mir_for_ctfe: missing MIR for `{:?}`", self.local_def_id(id))
})
.decode((self, tcx))
}
fn get_thir_abstract_const(
self,
tcx: TyCtxt<'tcx>,
id: DefIndex,
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
self.root
.tables
.thir_abstract_consts
.get(self, id)
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
}
fn get_unused_generic_params(self, id: DefIndex) -> FiniteBitSet<u32> {
self.root
.tables
.unused_generic_params
.get(self, id)
.map(|params| params.decode(self))
.unwrap_or_default()
}
fn get_promoted_mir(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted, Body<'tcx>> {
self.root
.tables
.promoted_mir
.get(self, id)
.unwrap_or_else(|| {
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
})
.decode((self, tcx))
}
fn mir_const_qualif(self, id: DefIndex) -> mir::ConstQualifs {
match self.kind(id) {
EntryKind::AnonConst(qualif, _)
| EntryKind::Const(qualif, _)
| EntryKind::AssocConst(
AssocContainer::ImplDefault
| AssocContainer::ImplFinal
| AssocContainer::TraitWithDefault,
qualif,
_,
) => qualif,
_ => bug!("mir_const_qualif: unexpected kind"),
}
}
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
match self.kind(id) {
EntryKind::AssocFn(data) => data.decode(self).has_self,
......@@ -1261,13 +1187,13 @@ fn get_associated_item_def_ids(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [
}
}
fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
let def_key = self.def_key(id);
let parent = self.local_def_id(def_key.parent.unwrap());
let ident = self.item_ident(id, sess);
let name = self.item_name(id);
let (kind, container, has_self) = match self.kind(id) {
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
EntryKind::AssocFn(data) => {
let data = data.decode(self);
(ty::AssocKind::Fn, data.container, data.has_self)
......@@ -1277,7 +1203,7 @@ fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
};
ty::AssocItem {
name: ident.name,
name,
kind,
vis: self.get_visibility(id),
defaultness: container.defaultness(),
......@@ -1288,10 +1214,6 @@ fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
}
}
fn get_item_variances(self, id: DefIndex) -> impl Iterator<Item = ty::Variance> + 'a {
self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self)
}
fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> {
match self.kind(node_id) {
EntryKind::Struct(data, _) | EntryKind::Variant(data) => {
......@@ -1338,7 +1260,7 @@ fn get_struct_field_names(
.get(self, id)
.unwrap_or_else(Lazy::empty)
.decode(self)
.map(move |index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
.map(move |index| respan(self.get_span(index, sess), self.item_name(index)))
}
fn get_struct_field_visibilities(self, id: DefIndex) -> impl Iterator<Item = Visibility> + 'a {
......@@ -1473,15 +1395,6 @@ fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangIte
tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self))
}
fn get_fn_param_names(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] {
let param_names = match self.kind(id) {
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
_ => Lazy::empty(),
};
tcx.arena.alloc_from_iter(param_names.decode((self, tcx)))
}
fn exported_symbols(
self,
tcx: TyCtxt<'tcx>,
......@@ -1489,15 +1402,6 @@ fn exported_symbols(
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
}
fn get_rendered_const(self, id: DefIndex) -> String {
match self.kind(id) {
EntryKind::AnonConst(_, data)
| EntryKind::Const(_, data)
| EntryKind::AssocConst(_, _, data) => data.decode(self).0,
_ => bug!(),
}
}
fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
match self.kind(id) {
EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),
......@@ -1518,15 +1422,6 @@ fn is_const_fn_raw(self, id: DefIndex) -> bool {
constness == hir::Constness::Const
}
fn asyncness(self, id: DefIndex) -> hir::IsAsync {
match self.kind(id) {
EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness,
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
_ => bug!("asyncness: expected function kind"),
}
}
fn is_foreign_item(self, id: DefIndex) -> bool {
match self.kind(id) {
EntryKind::ForeignImmStatic | EntryKind::ForeignMutStatic | EntryKind::ForeignFn(_) => {
......@@ -1544,17 +1439,6 @@ fn static_mutability(self, id: DefIndex) -> Option<hir::Mutability> {
}
}
fn generator_kind(self, id: DefIndex) -> Option<hir::GeneratorKind> {
match self.kind(id) {
EntryKind::Generator(data) => Some(data),
_ => None,
}
}
fn fn_sig(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
self.root.tables.fn_sig.get(self, id).unwrap().decode((self, tcx))
}
#[inline]
fn def_key(self, index: DefIndex) -> DefKey {
*self
......
use super::LazyQueryDecodable;
use crate::creader::{CStore, LoadedMacro};
use crate::foreign_modules;
use crate::native_libs;
......@@ -8,7 +9,6 @@
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::ExportedSymbol;
use rustc_middle::middle::stability::DeprecationEntry;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_middle::ty::{self, TyCtxt, Visibility};
......@@ -23,32 +23,51 @@
use smallvec::SmallVec;
use std::any::Any;
macro_rules! provide_one {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
provide_one! {
<$lt> $tcx, $def_id, $other, $cdata, $name => {
$cdata.root.tables.$name.get($cdata, $def_id.index).decode_query(
$cdata,
$tcx,
|| panic!("{:?} does not have a {:?}", $def_id, stringify!($name)),
)
}
}
};
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
fn $name<$lt>(
$tcx: TyCtxt<$lt>,
def_id_arg: ty::query::query_keys::$name<$lt>,
) -> ty::query::query_values::$name<$lt> {
let _prof_timer =
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
#[allow(unused_variables)]
let ($def_id, $other) = def_id_arg.into_args();
assert!(!$def_id.is_local());
// External query providers call `crate_hash` in order to register a dependency
// on the crate metadata. The exception is `crate_hash` itself, which obviously
// doesn't need to do this (and can't, as it would cause a query cycle).
use rustc_middle::dep_graph::DepKind;
if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() {
$tcx.ensure().crate_hash($def_id.krate);
}
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
$compute
}
};
}
macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
$($name:ident => $compute:block)*) => {
$($name:ident => { $($compute:tt)* })*) => {
pub fn provide_extern(providers: &mut ExternProviders) {
$(fn $name<$lt>(
$tcx: TyCtxt<$lt>,
def_id_arg: ty::query::query_keys::$name<$lt>,
) -> ty::query::query_values::$name<$lt> {
let _prof_timer =
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
#[allow(unused_variables)]
let ($def_id, $other) = def_id_arg.into_args();
assert!(!$def_id.is_local());
// External query providers call `crate_hash` in order to register a dependency
// on the crate metadata. The exception is `crate_hash` itself, which obviously
// doesn't need to do this (and can't, as it would cause a query cycle).
use rustc_middle::dep_graph::DepKind;
if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() {
$tcx.ensure().crate_hash($def_id.krate);
}
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
$compute
$(provide_one! {
<$lt> $tcx, $def_id, $other, $cdata, $name => { $($compute)* }
})*
*providers = ExternProviders {
......@@ -90,58 +109,52 @@ fn into_args(self) -> (DefId, DefId) {
}
provide! { <'tcx> tcx, def_id, other, cdata,
type_of => { cdata.get_type(def_id.index, tcx) }
generics_of => { cdata.get_generics(def_id.index, tcx.sess) }
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) }
explicit_item_bounds => { table }
explicit_predicates_of => { table }
generics_of => { table }
inferred_outlives_of => { table }
super_predicates_of => { table }
type_of => { table }
variances_of => { table }
fn_sig => { table }
impl_trait_ref => { table }
const_param_default => { table }
thir_abstract_const => { table }
optimized_mir => { table }
mir_for_ctfe => { table }
promoted_mir => { table }
def_span => { table }
def_ident_span => { table }
lookup_stability => { table }
lookup_const_stability => { table }
lookup_deprecation_entry => { table }
visibility => { table }
unused_generic_params => { table }
opt_def_kind => { table }
impl_parent => { table }
impl_polarity => { table }
impl_defaultness => { table }
impl_constness => { table }
coerce_unsized_info => { table }
mir_const_qualif => { table }
rendered_const => { table }
asyncness => { table }
fn_arg_names => { table }
generator_kind => { table }
trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
adt_destructor => {
let _ = cdata;
tcx.calculate_dtor(def_id, |_,_| Ok(()))
}
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
coerce_unsized_info => {
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
})
}
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
mir_for_ctfe => { tcx.arena.alloc(cdata.get_mir_for_ctfe(tcx, def_id.index)) }
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
thir_abstract_const => { cdata.get_thir_abstract_const(tcx, def_id.index) }
unused_generic_params => { cdata.get_unused_generic_params(def_id.index) }
const_param_default => { cdata.get_const_param_default(tcx, def_id.index) }
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
associated_item => { cdata.get_associated_item(def_id.index) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
asyncness => { cdata.asyncness(def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
static_mutability => { cdata.static_mutability(def_id.index) }
generator_kind => { cdata.generator_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_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_deprecation_entry => {
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
}
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
rendered_const => { cdata.get_rendered_const(def_id.index) }
impl_parent => { cdata.get_parent_impl(def_id.index) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
......@@ -161,8 +174,6 @@ fn into_args(self) -> (DefId, DefId) {
}
is_no_builtins => { cdata.root.no_builtins }
symbol_mangling_version => { cdata.root.symbol_mangling_version }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
impl_constness => { cdata.get_impl_constness(def_id.index) }
reachable_non_generics => {
let reachable_non_generics = tcx
.exported_symbols(cdata.cnum)
......@@ -189,7 +200,6 @@ fn into_args(self) -> (DefId, DefId) {
traits_in_crate => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
visibility => { cdata.get_visibility(def_id.index) }
dep_kind => {
let r = *cdata.dep_kind.lock();
r
......
......@@ -275,35 +275,48 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
}
define_tables! {
def_kind: Table<DefIndex, Lazy<DefKind>>,
kind: Table<DefIndex, Lazy<EntryKind>>,
visibility: Table<DefIndex, Lazy<ty::Visibility>>,
span: Table<DefIndex, Lazy<Span>>,
ident_span: Table<DefIndex, Lazy<Span>>,
attributes: Table<DefIndex, Lazy<[ast::Attribute]>>,
children: Table<DefIndex, Lazy<[DefIndex]>>,
stability: Table<DefIndex, Lazy<attr::Stability>>,
const_stability: Table<DefIndex, Lazy<attr::ConstStability>>,
deprecation: Table<DefIndex, Lazy<attr::Deprecation>>,
ty: Table<DefIndex, Lazy!(Ty<'tcx>)>,
opt_def_kind: Table<DefIndex, Lazy<DefKind>>,
visibility: Table<DefIndex, Lazy<ty::Visibility>>,
def_span: Table<DefIndex, Lazy<Span>>,
def_ident_span: Table<DefIndex, Lazy<Span>>,
lookup_stability: Table<DefIndex, Lazy<attr::Stability>>,
lookup_const_stability: Table<DefIndex, Lazy<attr::ConstStability>>,
lookup_deprecation_entry: Table<DefIndex, Lazy<attr::Deprecation>>,
// As an optimization, a missing entry indicates an empty `&[]`.
explicit_item_bounds: Table<DefIndex, Lazy!([(ty::Predicate<'tcx>, Span)])>,
explicit_predicates_of: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
generics_of: Table<DefIndex, Lazy<ty::Generics>>,
// As an optimization, a missing entry indicates an empty `&[]`.
inferred_outlives_of: Table<DefIndex, Lazy!([(ty::Predicate<'tcx>, Span)])>,
super_predicates_of: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
type_of: Table<DefIndex, Lazy!(Ty<'tcx>)>,
variances_of: Table<DefIndex, Lazy<[ty::Variance]>>,
fn_sig: Table<DefIndex, Lazy!(ty::PolyFnSig<'tcx>)>,
impl_trait_ref: Table<DefIndex, Lazy!(ty::TraitRef<'tcx>)>,
const_param_default: Table<DefIndex, Lazy<rustc_middle::ty::Const<'tcx>>>,
optimized_mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
mir_for_ctfe: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
thir_abstract_const: Table<DefIndex, Lazy!(&'tcx [thir::abstract_const::Node<'tcx>])>,
impl_parent: Table<DefIndex, Lazy!(DefId)>,
impl_polarity: Table<DefIndex, Lazy!(ty::ImplPolarity)>,
impl_constness: Table<DefIndex, Lazy!(hir::Constness)>,
impl_defaultness: Table<DefIndex, Lazy!(hir::Defaultness)>,
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
coerce_unsized_info: Table<DefIndex, Lazy!(ty::adjustment::CoerceUnsizedInfo)>,
mir_const_qualif: Table<DefIndex, Lazy!(mir::ConstQualifs)>,
rendered_const: Table<DefIndex, Lazy!(String)>,
asyncness: Table<DefIndex, Lazy!(hir::IsAsync)>,
fn_arg_names: Table<DefIndex, Lazy!([Ident])>,
generator_kind: Table<DefIndex, Lazy!(hir::GeneratorKind)>,
trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
variances: Table<DefIndex, Lazy<[ty::Variance]>>,
generics: Table<DefIndex, Lazy<ty::Generics>>,
explicit_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
// As an optimization, a missing entry indicates an empty `&[]`.
inferred_outlives: Table<DefIndex, Lazy!([(ty::Predicate<'tcx>, Span)])>,
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
// As an optimization, a missing entry indicates an empty `&[]`.
explicit_item_bounds: Table<DefIndex, Lazy!([(ty::Predicate<'tcx>, Span)])>,
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
mir_for_ctfe: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
thir_abstract_consts: Table<DefIndex, Lazy!(&'tcx [thir::abstract_const::Node<'tcx>])>,
const_defaults: Table<DefIndex, Lazy<rustc_middle::ty::Const<'tcx>>>,
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
// `def_keys` and `def_path_hashes` represent a lazy version of a
// `DefPathTable`. This allows us to avoid deserializing an entire
......@@ -316,8 +329,8 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
enum EntryKind {
AnonConst(mir::ConstQualifs, Lazy<RenderedConst>),
Const(mir::ConstQualifs, Lazy<RenderedConst>),
AnonConst,
Const,
ImmStatic,
MutStatic,
ForeignImmStatic,
......@@ -340,25 +353,18 @@ enum EntryKind {
MacroDef(Lazy<MacroDef>),
ProcMacro(MacroKind),
Closure,
Generator(hir::GeneratorKind),
Generator,
Trait(Lazy<TraitData>),
Impl(Lazy<ImplData>),
Impl,
AssocFn(Lazy<AssocFnData>),
AssocType(AssocContainer),
AssocConst(AssocContainer, mir::ConstQualifs, Lazy<RenderedConst>),
AssocConst(AssocContainer),
TraitAlias,
}
/// Contains a constant which has been rendered to a String.
/// Used by rustdoc.
#[derive(Encodable, Decodable)]
struct RenderedConst(String);
#[derive(MetadataEncodable, MetadataDecodable)]
struct FnData {
asyncness: hir::IsAsync,
constness: hir::Constness,
param_names: Lazy<[Ident]>,
}
#[derive(TyEncodable, TyDecodable)]
......@@ -381,18 +387,6 @@ struct TraitData {
must_implement_one_of: Option<Box<[Ident]>>,
}
#[derive(TyEncodable, TyDecodable)]
struct ImplData {
polarity: ty::ImplPolarity,
constness: hir::Constness,
defaultness: hir::Defaultness,
parent_impl: Option<DefId>,
/// This is `Some` only for impls of `CoerceUnsized`.
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
}
/// Describes whether the container of an associated item
/// is a trait or an impl and whether, in a trait, it has
/// a default, or an in impl, whether it's marked "default".
......
......@@ -57,11 +57,11 @@ pub fn same_origin(&self, other: &DeprecationEntry) -> bool {
/// 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 @@ pub fn eval_stability(
}
match stability {
Some(&Stability {
Some(Stability {
level: attr::Unstable { reason, issue, is_soft }, feature, ..
}) => {
if span.allows_unstable(feature) {
......
......@@ -1016,12 +1016,12 @@
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
}
......@@ -1636,7 +1636,7 @@
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" }
......
......@@ -24,7 +24,6 @@
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;
......@@ -115,12 +114,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> {
......@@ -141,8 +134,6 @@ fn new(arena: &'tcx WorkerLocal<Arena<'tcx>>) -> CtxtInterners<'tcx> {
bound_variable_kinds: Default::default(),
layout: Default::default(),
adt_def: Default::default(),
stability: Default::default(),
const_stability: Default::default(),
}
}
......@@ -1268,7 +1259,7 @@ pub fn is_diagnostic_item(self, name: Symbol, did: DefId) -> bool {
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(())
}
......@@ -1997,12 +1988,6 @@ fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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: #{}",
......@@ -2190,8 +2175,6 @@ pub fn $method(self, v: $ty) -> &'tcx $ty {
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 {
......
......@@ -87,9 +87,9 @@ fn yes(&self) -> bool {
// 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 @@ fn annotate<F>(
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 @@ fn annotate<F>(
}
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 @@ fn annotate<F>(
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 @@ fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'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);
}
......
......@@ -381,12 +381,12 @@ fn to_remote(url: impl ToString) -> ExternalLocation {
}
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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册