about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src/rmeta/decoder
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-02-24 10:02:26 +0000
committerbors <bors@rust-lang.org>2022-02-24 10:02:26 +0000
commit7ccfe2ff1d59666dc0188dfd5847304fec257565 (patch)
tree48ab85a723d1398aa894f6fe89e88d01986b8f57 /compiler/rustc_metadata/src/rmeta/decoder
parent1204400ab8da9830f6f77a5e40e7ad3ea459676a (diff)
parent7afcf9fcd14af52e53e38ffe60b1eac9b3232b21 (diff)
downloadrust-7ccfe2ff1d59666dc0188dfd5847304fec257565.tar.gz
rust-7ccfe2ff1d59666dc0188dfd5847304fec257565.zip
Auto merge of #94129 - cjgillot:rmeta-table, r=petrochenkov
Back more metadata using per-query tables

r? `@ghost`
Diffstat (limited to 'compiler/rustc_metadata/src/rmeta/decoder')
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs144
1 files changed, 77 insertions, 67 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index ce61fd20a7b..5ae965ff7fa 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -1,3 +1,4 @@
+use super::LazyQueryDecodable;
 use crate::creader::{CStore, LoadedMacro};
 use crate::foreign_modules;
 use crate::native_libs;
@@ -8,7 +9,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}
 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 rustc_data_structures::sync::Lrc;
 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 @@ impl<'tcx> IntoArgs for ty::InstanceDef<'tcx> {
 }
 
 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 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     }
     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 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     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