Skip to content

Commit 7ccfe2f

Browse files
committed
Auto merge of #94129 - cjgillot:rmeta-table, r=petrochenkov
Back more metadata using per-query tables r? `@ghost`
2 parents 1204400 + 7afcf9f commit 7ccfe2f

File tree

9 files changed

+342
-490
lines changed

9 files changed

+342
-490
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+128-244
Large diffs are not rendered by default.

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

+77-67
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::LazyQueryDecodable;
12
use crate::creader::{CStore, LoadedMacro};
23
use crate::foreign_modules;
34
use crate::native_libs;
@@ -8,7 +9,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}
89
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
910
use rustc_middle::metadata::ModChild;
1011
use rustc_middle::middle::exported_symbols::ExportedSymbol;
11-
use rustc_middle::middle::stability::DeprecationEntry;
1212
use rustc_middle::ty::fast_reject::SimplifiedType;
1313
use rustc_middle::ty::query::{ExternProviders, Providers};
1414
use rustc_middle::ty::{self, TyCtxt, Visibility};
@@ -23,32 +23,51 @@ use rustc_data_structures::sync::Lrc;
2323
use smallvec::SmallVec;
2424
use std::any::Any;
2525

26+
macro_rules! provide_one {
27+
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
28+
provide_one! {
29+
<$lt> $tcx, $def_id, $other, $cdata, $name => {
30+
$cdata.root.tables.$name.get($cdata, $def_id.index).decode_query(
31+
$cdata,
32+
$tcx,
33+
|| panic!("{:?} does not have a {:?}", $def_id, stringify!($name)),
34+
)
35+
}
36+
}
37+
};
38+
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
39+
fn $name<$lt>(
40+
$tcx: TyCtxt<$lt>,
41+
def_id_arg: ty::query::query_keys::$name<$lt>,
42+
) -> ty::query::query_values::$name<$lt> {
43+
let _prof_timer =
44+
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
45+
46+
#[allow(unused_variables)]
47+
let ($def_id, $other) = def_id_arg.into_args();
48+
assert!(!$def_id.is_local());
49+
50+
// External query providers call `crate_hash` in order to register a dependency
51+
// on the crate metadata. The exception is `crate_hash` itself, which obviously
52+
// doesn't need to do this (and can't, as it would cause a query cycle).
53+
use rustc_middle::dep_graph::DepKind;
54+
if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() {
55+
$tcx.ensure().crate_hash($def_id.krate);
56+
}
57+
58+
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
59+
60+
$compute
61+
}
62+
};
63+
}
64+
2665
macro_rules! provide {
2766
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
28-
$($name:ident => $compute:block)*) => {
67+
$($name:ident => { $($compute:tt)* })*) => {
2968
pub fn provide_extern(providers: &mut ExternProviders) {
30-
$(fn $name<$lt>(
31-
$tcx: TyCtxt<$lt>,
32-
def_id_arg: ty::query::query_keys::$name<$lt>,
33-
) -> ty::query::query_values::$name<$lt> {
34-
let _prof_timer =
35-
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
36-
37-
#[allow(unused_variables)]
38-
let ($def_id, $other) = def_id_arg.into_args();
39-
assert!(!$def_id.is_local());
40-
41-
// External query providers call `crate_hash` in order to register a dependency
42-
// on the crate metadata. The exception is `crate_hash` itself, which obviously
43-
// doesn't need to do this (and can't, as it would cause a query cycle).
44-
use rustc_middle::dep_graph::DepKind;
45-
if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() {
46-
$tcx.ensure().crate_hash($def_id.krate);
47-
}
48-
49-
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
50-
51-
$compute
69+
$(provide_one! {
70+
<$lt> $tcx, $def_id, $other, $cdata, $name => { $($compute)* }
5271
})*
5372

5473
*providers = ExternProviders {
@@ -90,58 +109,52 @@ impl<'tcx> IntoArgs for ty::InstanceDef<'tcx> {
90109
}
91110

92111
provide! { <'tcx> tcx, def_id, other, cdata,
93-
type_of => { cdata.get_type(def_id.index, tcx) }
94-
generics_of => { cdata.get_generics(def_id.index, tcx.sess) }
95-
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
96-
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
97-
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
98-
explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) }
112+
explicit_item_bounds => { table }
113+
explicit_predicates_of => { table }
114+
generics_of => { table }
115+
inferred_outlives_of => { table }
116+
super_predicates_of => { table }
117+
type_of => { table }
118+
variances_of => { table }
119+
fn_sig => { table }
120+
impl_trait_ref => { table }
121+
const_param_default => { table }
122+
thir_abstract_const => { table }
123+
optimized_mir => { table }
124+
mir_for_ctfe => { table }
125+
promoted_mir => { table }
126+
def_span => { table }
127+
def_ident_span => { table }
128+
lookup_stability => { table }
129+
lookup_const_stability => { table }
130+
lookup_deprecation_entry => { table }
131+
visibility => { table }
132+
unused_generic_params => { table }
133+
opt_def_kind => { table }
134+
impl_parent => { table }
135+
impl_polarity => { table }
136+
impl_defaultness => { table }
137+
impl_constness => { table }
138+
coerce_unsized_info => { table }
139+
mir_const_qualif => { table }
140+
rendered_const => { table }
141+
asyncness => { table }
142+
fn_arg_names => { table }
143+
generator_kind => { table }
144+
99145
trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
100146
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
101147
adt_destructor => {
102148
let _ = cdata;
103149
tcx.calculate_dtor(def_id, |_,_| Ok(()))
104150
}
105-
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
106151
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
107-
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
108-
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
109-
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
110-
coerce_unsized_info => {
111-
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
112-
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
113-
})
114-
}
115-
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
116-
mir_for_ctfe => { tcx.arena.alloc(cdata.get_mir_for_ctfe(tcx, def_id.index)) }
117-
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
118-
thir_abstract_const => { cdata.get_thir_abstract_const(tcx, def_id.index) }
119-
unused_generic_params => { cdata.get_unused_generic_params(def_id.index) }
120-
const_param_default => { cdata.get_const_param_default(tcx, def_id.index) }
121-
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
122-
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
152+
associated_item => { cdata.get_associated_item(def_id.index) }
123153
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
124154
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
125-
asyncness => { cdata.asyncness(def_id.index) }
126155
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
127156
static_mutability => { cdata.static_mutability(def_id.index) }
128-
generator_kind => { cdata.generator_kind(def_id.index) }
129-
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
130-
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
131-
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-
}
138-
lookup_deprecation_entry => {
139-
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
140-
}
141157
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
142-
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
143-
rendered_const => { cdata.get_rendered_const(def_id.index) }
144-
impl_parent => { cdata.get_parent_impl(def_id.index) }
145158
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
146159
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
147160
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
@@ -161,8 +174,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
161174
}
162175
is_no_builtins => { cdata.root.no_builtins }
163176
symbol_mangling_version => { cdata.root.symbol_mangling_version }
164-
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
165-
impl_constness => { cdata.get_impl_constness(def_id.index) }
166177
reachable_non_generics => {
167178
let reachable_non_generics = tcx
168179
.exported_symbols(cdata.cnum)
@@ -189,7 +200,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
189200
traits_in_crate => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
190201
implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
191202

192-
visibility => { cdata.get_visibility(def_id.index) }
193203
dep_kind => {
194204
let r = *cdata.dep_kind.lock();
195205
r

0 commit comments

Comments
 (0)