]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Rollup merge of #105419 - YC:issue-41731, r=petrochenkov
[rust.git] / compiler / rustc_metadata / src / rmeta / decoder / cstore_impl.rs
1 use crate::creader::{CStore, LoadedMacro};
2 use crate::foreign_modules;
3 use crate::native_libs;
4
5 use rustc_ast as ast;
6 use rustc_attr::Deprecation;
7 use rustc_hir::def::{CtorKind, DefKind, Res};
8 use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
9 use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
10 use rustc_middle::arena::ArenaAllocatable;
11 use rustc_middle::metadata::ModChild;
12 use rustc_middle::middle::exported_symbols::ExportedSymbol;
13 use rustc_middle::middle::stability::DeprecationEntry;
14 use rustc_middle::ty::fast_reject::SimplifiedType;
15 use rustc_middle::ty::query::{ExternProviders, Providers};
16 use rustc_middle::ty::{self, TyCtxt, Visibility};
17 use rustc_session::cstore::{CrateSource, CrateStore};
18 use rustc_session::{Session, StableCrateId};
19 use rustc_span::hygiene::{ExpnHash, ExpnId};
20 use rustc_span::source_map::{Span, Spanned};
21 use rustc_span::symbol::{kw, Symbol};
22
23 use rustc_data_structures::sync::Lrc;
24 use std::any::Any;
25
26 use super::{Decodable, DecodeContext, DecodeIterator};
27
28 trait ProcessQueryValue<'tcx, T> {
29     fn process_decoded(self, _tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> T;
30 }
31
32 impl<T> ProcessQueryValue<'_, Option<T>> for Option<T> {
33     #[inline(always)]
34     fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<T> {
35         self
36     }
37 }
38
39 impl<T> ProcessQueryValue<'_, T> for Option<T> {
40     #[inline(always)]
41     fn process_decoded(self, _tcx: TyCtxt<'_>, err: impl Fn() -> !) -> T {
42         if let Some(value) = self { value } else { err() }
43     }
44 }
45
46 impl<'tcx, T: ArenaAllocatable<'tcx>> ProcessQueryValue<'tcx, &'tcx T> for Option<T> {
47     #[inline(always)]
48     fn process_decoded(self, tcx: TyCtxt<'tcx>, err: impl Fn() -> !) -> &'tcx T {
49         if let Some(value) = self { tcx.arena.alloc(value) } else { err() }
50     }
51 }
52
53 impl<T, E> ProcessQueryValue<'_, Result<Option<T>, E>> for Option<T> {
54     #[inline(always)]
55     fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Result<Option<T>, E> {
56         Ok(self)
57     }
58 }
59
60 impl<'a, 'tcx, T: Copy + Decodable<DecodeContext<'a, 'tcx>>> ProcessQueryValue<'tcx, &'tcx [T]>
61     for Option<DecodeIterator<'a, 'tcx, T>>
62 {
63     #[inline(always)]
64     fn process_decoded(self, tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> &'tcx [T] {
65         if let Some(iter) = self { tcx.arena.alloc_from_iter(iter) } else { &[] }
66     }
67 }
68
69 impl ProcessQueryValue<'_, Option<DeprecationEntry>> for Option<Deprecation> {
70     #[inline(always)]
71     fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<DeprecationEntry> {
72         self.map(DeprecationEntry::external)
73     }
74 }
75
76 macro_rules! provide_one {
77     ($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
78         provide_one! {
79             $tcx, $def_id, $other, $cdata, $name => {
80                 $cdata
81                     .root
82                     .tables
83                     .$name
84                     .get($cdata, $def_id.index)
85                     .map(|lazy| lazy.decode(($cdata, $tcx)))
86                     .process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
87             }
88         }
89     };
90     ($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_direct }) => {
91         provide_one! {
92             $tcx, $def_id, $other, $cdata, $name => {
93                 // We don't decode `table_direct`, since it's not a Lazy, but an actual value
94                 $cdata
95                     .root
96                     .tables
97                     .$name
98                     .get($cdata, $def_id.index)
99                     .process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
100             }
101         }
102     };
103     ($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
104         fn $name<'tcx>(
105             $tcx: TyCtxt<'tcx>,
106             def_id_arg: ty::query::query_keys::$name<'tcx>,
107         ) -> ty::query::query_values::$name<'tcx> {
108             let _prof_timer =
109                 $tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
110
111             #[allow(unused_variables)]
112             let ($def_id, $other) = def_id_arg.into_args();
113             assert!(!$def_id.is_local());
114
115             // External query providers call `crate_hash` in order to register a dependency
116             // on the crate metadata. The exception is `crate_hash` itself, which obviously
117             // doesn't need to do this (and can't, as it would cause a query cycle).
118             use rustc_middle::dep_graph::DepKind;
119             if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() {
120                 $tcx.ensure().crate_hash($def_id.krate);
121             }
122
123             let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
124
125             $compute
126         }
127     };
128 }
129
130 macro_rules! provide {
131     ($tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
132       $($name:ident => { $($compute:tt)* })*) => {
133         pub fn provide_extern(providers: &mut ExternProviders) {
134             $(provide_one! {
135                 $tcx, $def_id, $other, $cdata, $name => { $($compute)* }
136             })*
137
138             *providers = ExternProviders {
139                 $($name,)*
140                 ..*providers
141             };
142         }
143     }
144 }
145
146 // small trait to work around different signature queries all being defined via
147 // the macro above.
148 trait IntoArgs {
149     type Other;
150     fn into_args(self) -> (DefId, Self::Other);
151 }
152
153 impl IntoArgs for DefId {
154     type Other = ();
155     fn into_args(self) -> (DefId, ()) {
156         (self, ())
157     }
158 }
159
160 impl IntoArgs for CrateNum {
161     type Other = ();
162     fn into_args(self) -> (DefId, ()) {
163         (self.as_def_id(), ())
164     }
165 }
166
167 impl IntoArgs for (CrateNum, DefId) {
168     type Other = DefId;
169     fn into_args(self) -> (DefId, DefId) {
170         (self.0.as_def_id(), self.1)
171     }
172 }
173
174 impl<'tcx> IntoArgs for ty::InstanceDef<'tcx> {
175     type Other = ();
176     fn into_args(self) -> (DefId, ()) {
177         (self.def_id(), ())
178     }
179 }
180
181 impl IntoArgs for (CrateNum, SimplifiedType) {
182     type Other = SimplifiedType;
183     fn into_args(self) -> (DefId, SimplifiedType) {
184         (self.0.as_def_id(), self.1)
185     }
186 }
187
188 provide! { tcx, def_id, other, cdata,
189     explicit_item_bounds => { table }
190     explicit_predicates_of => { table }
191     generics_of => { table }
192     inferred_outlives_of => { table }
193     super_predicates_of => { table }
194     type_of => { table }
195     variances_of => { table }
196     fn_sig => { table }
197     codegen_fn_attrs => { table }
198     impl_trait_ref => { table }
199     const_param_default => { table }
200     object_lifetime_default => { table }
201     thir_abstract_const => { table }
202     optimized_mir => { table }
203     mir_for_ctfe => { table }
204     promoted_mir => { table }
205     def_span => { table }
206     def_ident_span => { table }
207     lookup_stability => { table }
208     lookup_const_stability => { table }
209     lookup_default_body_stability => { table }
210     lookup_deprecation_entry => { table }
211     params_in_repr => { table }
212     unused_generic_params => { table }
213     opt_def_kind => { table_direct }
214     impl_parent => { table }
215     impl_polarity => { table_direct }
216     impl_defaultness => { table_direct }
217     constness => { table_direct }
218     coerce_unsized_info => { table }
219     mir_const_qualif => { table }
220     rendered_const => { table }
221     asyncness => { table_direct }
222     fn_arg_names => { table }
223     generator_kind => { table }
224     trait_def => { table }
225     deduced_param_attrs => { table }
226     collect_trait_impl_trait_tys => {
227         Ok(cdata
228             .root
229             .tables
230             .trait_impl_trait_tys
231             .get(cdata, def_id.index)
232             .map(|lazy| lazy.decode((cdata, tcx)))
233             .process_decoded(tcx, || panic!("{:?} does not have trait_impl_trait_tys", def_id)))
234      }
235
236     visibility => { cdata.get_visibility(def_id.index) }
237     adt_def => { cdata.get_adt_def(def_id.index, tcx) }
238     adt_destructor => {
239         let _ = cdata;
240         tcx.calculate_dtor(def_id, |_,_| Ok(()))
241     }
242     associated_item_def_ids => {
243         tcx.arena.alloc_from_iter(cdata.get_associated_item_def_ids(def_id.index, tcx.sess))
244     }
245     associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
246     inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
247     is_foreign_item => { cdata.is_foreign_item(def_id.index) }
248     item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
249     is_mir_available => { cdata.is_item_mir_available(def_id.index) }
250     is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
251
252     dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
253     is_private_dep => { cdata.private_dep }
254     is_panic_runtime => { cdata.root.panic_runtime }
255     is_compiler_builtins => { cdata.root.compiler_builtins }
256     has_global_allocator => { cdata.root.has_global_allocator }
257     has_alloc_error_handler => { cdata.root.has_alloc_error_handler }
258     has_panic_handler => { cdata.root.has_panic_handler }
259     is_profiler_runtime => { cdata.root.profiler_runtime }
260     required_panic_strategy => { cdata.root.required_panic_strategy }
261     panic_in_drop_strategy => { cdata.root.panic_in_drop_strategy }
262     extern_crate => {
263         let r = *cdata.extern_crate.lock();
264         r.map(|c| &*tcx.arena.alloc(c))
265     }
266     is_no_builtins => { cdata.root.no_builtins }
267     symbol_mangling_version => { cdata.root.symbol_mangling_version }
268     reachable_non_generics => {
269         let reachable_non_generics = tcx
270             .exported_symbols(cdata.cnum)
271             .iter()
272             .filter_map(|&(exported_symbol, export_info)| {
273                 if let ExportedSymbol::NonGeneric(def_id) = exported_symbol {
274                     Some((def_id, export_info))
275                 } else {
276                     None
277                 }
278             })
279             .collect();
280
281         reachable_non_generics
282     }
283     native_libraries => { cdata.get_native_libraries(tcx.sess).collect() }
284     foreign_modules => { cdata.get_foreign_modules(tcx.sess).map(|m| (m.def_id, m)).collect() }
285     crate_hash => { cdata.root.hash }
286     crate_host_hash => { cdata.host_hash }
287     crate_name => { cdata.root.name }
288
289     extra_filename => { cdata.root.extra_filename.clone() }
290
291     traits_in_crate => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
292     implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
293     crate_incoherent_impls => { cdata.get_incoherent_impls(tcx, other) }
294
295     dep_kind => {
296         let r = *cdata.dep_kind.lock();
297         r
298     }
299     module_children => {
300         tcx.arena.alloc_from_iter(cdata.get_module_children(def_id.index, tcx.sess))
301     }
302     defined_lib_features => { cdata.get_lib_features(tcx) }
303     stability_implications => {
304         cdata.get_stability_implications(tcx).iter().copied().collect()
305     }
306     is_intrinsic => { cdata.get_is_intrinsic(def_id.index) }
307     defined_lang_items => { cdata.get_lang_items(tcx) }
308     diagnostic_items => { cdata.get_diagnostic_items() }
309     missing_lang_items => { cdata.get_missing_lang_items(tcx) }
310
311     missing_extern_crate_item => {
312         let r = matches!(*cdata.extern_crate.borrow(), Some(extern_crate) if !extern_crate.is_direct());
313         r
314     }
315
316     used_crate_source => { Lrc::clone(&cdata.source) }
317     debugger_visualizers => { cdata.get_debugger_visualizers() }
318
319     exported_symbols => {
320         let syms = cdata.exported_symbols(tcx);
321
322         // FIXME rust-lang/rust#64319, rust-lang/rust#64872: We want
323         // to block export of generics from dylibs, but we must fix
324         // rust-lang/rust#65890 before we can do that robustly.
325
326         syms
327     }
328
329     crate_extern_paths => { cdata.source().paths().cloned().collect() }
330     expn_that_defined => { cdata.get_expn_that_defined(def_id.index, tcx.sess) }
331     generator_diagnostic_data => { cdata.get_generator_diagnostic_data(tcx, def_id.index) }
332 }
333
334 pub(in crate::rmeta) fn provide(providers: &mut Providers) {
335     // FIXME(#44234) - almost all of these queries have no sub-queries and
336     // therefore no actual inputs, they're just reading tables calculated in
337     // resolve! Does this work? Unsure! That's what the issue is about
338     *providers = Providers {
339         allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
340         alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(),
341         is_private_dep: |_tcx, cnum| {
342             assert_eq!(cnum, LOCAL_CRATE);
343             false
344         },
345         native_library: |tcx, id| {
346             tcx.native_libraries(id.krate)
347                 .iter()
348                 .filter(|lib| native_libs::relevant_lib(&tcx.sess, lib))
349                 .find(|lib| {
350                     let Some(fm_id) = lib.foreign_module else {
351                         return false;
352                     };
353                     let map = tcx.foreign_modules(id.krate);
354                     map.get(&fm_id)
355                         .expect("failed to find foreign module")
356                         .foreign_items
357                         .contains(&id)
358                 })
359         },
360         native_libraries: |tcx, cnum| {
361             assert_eq!(cnum, LOCAL_CRATE);
362             native_libs::collect(tcx)
363         },
364         foreign_modules: |tcx, cnum| {
365             assert_eq!(cnum, LOCAL_CRATE);
366             foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect()
367         },
368
369         // Returns a map from a sufficiently visible external item (i.e., an
370         // external item that is visible from at least one local module) to a
371         // sufficiently visible parent (considering modules that re-export the
372         // external item to be parents).
373         visible_parent_map: |tcx, ()| {
374             use std::collections::hash_map::Entry;
375             use std::collections::vec_deque::VecDeque;
376
377             let mut visible_parent_map: DefIdMap<DefId> = Default::default();
378             // This is a secondary visible_parent_map, storing the DefId of
379             // parents that re-export the child as `_` or module parents
380             // which are `#[doc(hidden)]`. Since we prefer paths that don't
381             // do this, merge this map at the end, only if we're missing
382             // keys from the former.
383             // This is a rudimentary check that does not catch all cases,
384             // just the easiest.
385             let mut fallback_map: DefIdMap<DefId> = Default::default();
386
387             // Issue 46112: We want the map to prefer the shortest
388             // paths when reporting the path to an item. Therefore we
389             // build up the map via a breadth-first search (BFS),
390             // which naturally yields minimal-length paths.
391             //
392             // Note that it needs to be a BFS over the whole forest of
393             // crates, not just each individual crate; otherwise you
394             // only get paths that are locally minimal with respect to
395             // whatever crate we happened to encounter first in this
396             // traversal, but not globally minimal across all crates.
397             let bfs_queue = &mut VecDeque::new();
398
399             for &cnum in tcx.crates(()) {
400                 // Ignore crates without a corresponding local `extern crate` item.
401                 if tcx.missing_extern_crate_item(cnum) {
402                     continue;
403                 }
404
405                 bfs_queue.push_back(cnum.as_def_id());
406             }
407
408             let mut add_child = |bfs_queue: &mut VecDeque<_>, child: &ModChild, parent: DefId| {
409                 if !child.vis.is_public() {
410                     return;
411                 }
412
413                 if let Some(def_id) = child.res.opt_def_id() {
414                     if child.ident.name == kw::Underscore {
415                         fallback_map.insert(def_id, parent);
416                         return;
417                     }
418
419                     if ty::util::is_doc_hidden(tcx, parent) {
420                         fallback_map.insert(def_id, parent);
421                         return;
422                     }
423
424                     match visible_parent_map.entry(def_id) {
425                         Entry::Occupied(mut entry) => {
426                             // If `child` is defined in crate `cnum`, ensure
427                             // that it is mapped to a parent in `cnum`.
428                             if def_id.is_local() && entry.get().is_local() {
429                                 entry.insert(parent);
430                             }
431                         }
432                         Entry::Vacant(entry) => {
433                             entry.insert(parent);
434                             if matches!(
435                                 child.res,
436                                 Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, _)
437                             ) {
438                                 bfs_queue.push_back(def_id);
439                             }
440                         }
441                     }
442                 }
443             };
444
445             while let Some(def) = bfs_queue.pop_front() {
446                 for child in tcx.module_children(def).iter() {
447                     add_child(bfs_queue, child, def);
448                 }
449             }
450
451             // Fill in any missing entries with the less preferable path.
452             // If this path re-exports the child as `_`, we still use this
453             // path in a diagnostic that suggests importing `::*`.
454             for (child, parent) in fallback_map {
455                 visible_parent_map.entry(child).or_insert(parent);
456             }
457
458             visible_parent_map
459         },
460
461         dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
462         has_global_allocator: |tcx, cnum| {
463             assert_eq!(cnum, LOCAL_CRATE);
464             CStore::from_tcx(tcx).has_global_allocator()
465         },
466         has_alloc_error_handler: |tcx, cnum| {
467             assert_eq!(cnum, LOCAL_CRATE);
468             CStore::from_tcx(tcx).has_alloc_error_handler()
469         },
470         postorder_cnums: |tcx, ()| {
471             tcx.arena
472                 .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
473         },
474         crates: |tcx, ()| tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).crates_untracked()),
475         ..*providers
476     };
477 }
478
479 impl CStore {
480     pub fn struct_field_names_untracked<'a>(
481         &'a self,
482         def: DefId,
483         sess: &'a Session,
484     ) -> impl Iterator<Item = Spanned<Symbol>> + 'a {
485         self.get_crate_data(def.krate).get_struct_field_names(def.index, sess)
486     }
487
488     pub fn struct_field_visibilities_untracked(
489         &self,
490         def: DefId,
491     ) -> impl Iterator<Item = Visibility<DefId>> + '_ {
492         self.get_crate_data(def.krate).get_struct_field_visibilities(def.index)
493     }
494
495     pub fn ctor_untracked(&self, def: DefId) -> Option<(CtorKind, DefId)> {
496         self.get_crate_data(def.krate).get_ctor(def.index)
497     }
498
499     pub fn visibility_untracked(&self, def: DefId) -> Visibility<DefId> {
500         self.get_crate_data(def.krate).get_visibility(def.index)
501     }
502
503     pub fn module_children_untracked<'a>(
504         &'a self,
505         def_id: DefId,
506         sess: &'a Session,
507     ) -> impl Iterator<Item = ModChild> + 'a {
508         self.get_crate_data(def_id.krate).get_module_children(def_id.index, sess)
509     }
510
511     pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
512         let _prof_timer = sess.prof.generic_activity("metadata_load_macro");
513
514         let data = self.get_crate_data(id.krate);
515         if data.root.is_proc_macro_crate() {
516             return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
517         }
518
519         let span = data.get_span(id.index, sess);
520
521         LoadedMacro::MacroDef(
522             ast::Item {
523                 ident: data.item_ident(id.index, sess),
524                 id: ast::DUMMY_NODE_ID,
525                 span,
526                 attrs: data.get_item_attrs(id.index, sess).collect(),
527                 kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)),
528                 vis: ast::Visibility {
529                     span: span.shrink_to_lo(),
530                     kind: ast::VisibilityKind::Inherited,
531                     tokens: None,
532                 },
533                 tokens: None,
534             },
535             data.root.edition,
536         )
537     }
538
539     pub fn fn_has_self_parameter_untracked(&self, def: DefId, sess: &Session) -> bool {
540         self.get_crate_data(def.krate).get_fn_has_self_parameter(def.index, sess)
541     }
542
543     pub fn crate_source_untracked(&self, cnum: CrateNum) -> Lrc<CrateSource> {
544         self.get_crate_data(cnum).source.clone()
545     }
546
547     pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
548         self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
549     }
550
551     pub fn def_kind(&self, def: DefId) -> DefKind {
552         self.get_crate_data(def.krate).def_kind(def.index)
553     }
554
555     pub fn crates_untracked(&self) -> impl Iterator<Item = CrateNum> + '_ {
556         self.iter_crate_data().map(|(cnum, _)| cnum)
557     }
558
559     pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
560         self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
561     }
562
563     pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
564         self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
565     }
566
567     /// Only public-facing way to traverse all the definitions in a non-local crate.
568     /// Critically useful for this third-party project: <https://github.com/hacspec/hacspec>.
569     /// See <https://github.com/rust-lang/rust/pull/85889> for context.
570     pub fn num_def_ids_untracked(&self, cnum: CrateNum) -> usize {
571         self.get_crate_data(cnum).num_def_ids()
572     }
573
574     pub fn item_attrs_untracked<'a>(
575         &'a self,
576         def_id: DefId,
577         sess: &'a Session,
578     ) -> impl Iterator<Item = ast::Attribute> + 'a {
579         self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess)
580     }
581
582     pub fn get_proc_macro_quoted_span_untracked(
583         &self,
584         cnum: CrateNum,
585         id: usize,
586         sess: &Session,
587     ) -> Span {
588         self.get_crate_data(cnum).get_proc_macro_quoted_span(id, sess)
589     }
590
591     /// Decodes all trait impls in the crate (for rustdoc).
592     pub fn trait_impls_in_crate_untracked(
593         &self,
594         cnum: CrateNum,
595     ) -> impl Iterator<Item = (DefId, DefId, Option<SimplifiedType>)> + '_ {
596         self.get_crate_data(cnum).get_trait_impls()
597     }
598
599     /// Decodes all inherent impls in the crate (for rustdoc).
600     pub fn inherent_impls_in_crate_untracked(
601         &self,
602         cnum: CrateNum,
603     ) -> impl Iterator<Item = (DefId, DefId)> + '_ {
604         self.get_crate_data(cnum).get_inherent_impls()
605     }
606
607     /// Decodes all incoherent inherent impls in the crate (for rustdoc).
608     pub fn incoherent_impls_in_crate_untracked(
609         &self,
610         cnum: CrateNum,
611     ) -> impl Iterator<Item = DefId> + '_ {
612         self.get_crate_data(cnum).get_all_incoherent_impls()
613     }
614
615     pub fn associated_item_def_ids_untracked<'a>(
616         &'a self,
617         def_id: DefId,
618         sess: &'a Session,
619     ) -> impl Iterator<Item = DefId> + 'a {
620         self.get_crate_data(def_id.krate).get_associated_item_def_ids(def_id.index, sess)
621     }
622
623     pub fn may_have_doc_links_untracked(&self, def_id: DefId) -> bool {
624         self.get_crate_data(def_id.krate).get_may_have_doc_links(def_id.index)
625     }
626 }
627
628 impl CrateStore for CStore {
629     fn as_any(&self) -> &dyn Any {
630         self
631     }
632     fn untracked_as_any(&mut self) -> &mut dyn Any {
633         self
634     }
635
636     fn crate_name(&self, cnum: CrateNum) -> Symbol {
637         self.get_crate_data(cnum).root.name
638     }
639
640     fn stable_crate_id(&self, cnum: CrateNum) -> StableCrateId {
641         self.get_crate_data(cnum).root.stable_crate_id
642     }
643
644     fn stable_crate_id_to_crate_num(&self, stable_crate_id: StableCrateId) -> CrateNum {
645         self.stable_crate_ids[&stable_crate_id]
646     }
647
648     /// Returns the `DefKey` for a given `DefId`. This indicates the
649     /// parent `DefId` as well as some idea of what kind of data the
650     /// `DefId` refers to.
651     fn def_key(&self, def: DefId) -> DefKey {
652         self.get_crate_data(def.krate).def_key(def.index)
653     }
654
655     fn def_path(&self, def: DefId) -> DefPath {
656         self.get_crate_data(def.krate).def_path(def.index)
657     }
658
659     fn def_path_hash(&self, def: DefId) -> DefPathHash {
660         self.get_crate_data(def.krate).def_path_hash(def.index)
661     }
662
663     fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId {
664         let def_index = self.get_crate_data(cnum).def_path_hash_to_def_index(hash);
665         DefId { krate: cnum, index: def_index }
666     }
667
668     fn expn_hash_to_expn_id(
669         &self,
670         sess: &Session,
671         cnum: CrateNum,
672         index_guess: u32,
673         hash: ExpnHash,
674     ) -> ExpnId {
675         self.get_crate_data(cnum).expn_hash_to_expn_id(sess, index_guess, hash)
676     }
677
678     fn import_source_files(&self, sess: &Session, cnum: CrateNum) {
679         let cdata = self.get_crate_data(cnum);
680         for file_index in 0..cdata.root.source_map.size() {
681             cdata.imported_source_file(file_index as u32, sess);
682         }
683     }
684 }