Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fd81e96

Browse files
committed
Retire encode_info_for_items.
1 parent 22df322 commit fd81e96

File tree

1 file changed

+33
-83
lines changed

1 file changed

+33
-83
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use rustc_hir::def_id::{
1717
CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE,
1818
};
1919
use rustc_hir::definitions::DefPathData;
20-
use rustc_hir::intravisit::{self, Visitor};
20+
use rustc_hir::intravisit;
2121
use rustc_hir::lang_items::LangItem;
22-
use rustc_middle::hir::nested_filter;
2322
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
2423
use rustc_middle::middle::dependency_format::Linkage;
2524
use rustc_middle::middle::exported_symbols::{
@@ -450,18 +449,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
450449
LazyArray::from_position_and_num_elems(pos, len)
451450
}
452451

453-
fn encode_info_for_items(&mut self) {
454-
self.encode_info_for_mod(CRATE_DEF_ID);
455-
456-
// Proc-macro crates only export proc-macro items, which are looked
457-
// up using `proc_macro_data`
458-
if self.is_proc_macro {
459-
return;
460-
}
461-
462-
self.tcx.hir().visit_all_item_likes_in_crate(self);
463-
}
464-
465452
fn encode_def_path_table(&mut self) {
466453
let table = self.tcx.def_path_table();
467454
if self.is_proc_macro {
@@ -607,8 +594,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
607594

608595
_ = stat!("def-ids", || self.encode_def_ids());
609596

610-
_ = stat!("items", || self.encode_info_for_items());
611-
612597
let interpret_alloc_index = stat!("interpret-alloc-index", || {
613598
let mut interpret_alloc_index = Vec::new();
614599
let mut n = 0;
@@ -1341,10 +1326,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13411326
}
13421327

13431328
fn encode_def_ids(&mut self) {
1329+
self.encode_info_for_mod(CRATE_DEF_ID);
1330+
1331+
// Proc-macro crates only export proc-macro items, which are looked
1332+
// up using `proc_macro_data`
13441333
if self.is_proc_macro {
13451334
return;
13461335
}
1336+
13471337
let tcx = self.tcx;
1338+
13481339
for local_id in tcx.iter_local_def_id() {
13491340
let def_id = local_id.to_def_id();
13501341
let def_kind = tcx.opt_def_kind(local_id);
@@ -1390,6 +1381,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13901381
record!(self.tables.explicit_predicates_of[def_id] <- self.tcx.explicit_predicates_of(def_id));
13911382
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
13921383
record_defaulted_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives);
1384+
1385+
for param in &g.params {
1386+
if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
1387+
let default = self.tcx.const_param_default(param.def_id);
1388+
record!(self.tables.const_param_default[param.def_id] <- default);
1389+
}
1390+
}
13931391
}
13941392
if should_encode_type(tcx, local_id, def_kind) {
13951393
record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
@@ -1440,6 +1438,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14401438
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
14411439
self.encode_info_for_adt(local_id);
14421440
}
1441+
if let DefKind::Mod = def_kind {
1442+
self.encode_info_for_mod(local_id);
1443+
}
1444+
if let DefKind::Macro(_) = def_kind {
1445+
self.encode_info_for_macro(local_id);
1446+
}
1447+
if let DefKind::OpaqueTy = def_kind {
1448+
self.encode_explicit_item_bounds(def_id);
1449+
self.tables
1450+
.is_type_alias_impl_trait
1451+
.set(def_id.index, self.tcx.is_type_alias_impl_trait(def_id));
1452+
}
14431453
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
14441454
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
14451455
{
@@ -1513,10 +1523,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15131523
}
15141524
}
15151525

1526+
#[tracing::instrument(level = "debug", skip(self))]
15161527
fn encode_info_for_mod(&mut self, local_def_id: LocalDefId) {
15171528
let tcx = self.tcx;
15181529
let def_id = local_def_id.to_def_id();
1519-
debug!("EncodeContext::encode_info_for_mod({:?})", def_id);
15201530

15211531
// If we are encoding a proc-macro crates, `encode_info_for_mod` will
15221532
// only ever get called for the crate root. We still want to encode
@@ -1689,40 +1699,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16891699
})
16901700
}
16911701

1692-
fn encode_info_for_item(&mut self, item: &'tcx hir::Item<'tcx>) {
1693-
let def_id = item.owner_id.to_def_id();
1694-
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
1702+
#[tracing::instrument(level = "debug", skip(self))]
1703+
fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
1704+
let tcx = self.tcx;
16951705

1696-
match item.kind {
1697-
hir::ItemKind::Macro(ref macro_def, _) => {
1698-
self.tables.is_macro_rules.set(def_id.index, macro_def.macro_rules);
1699-
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
1700-
}
1701-
hir::ItemKind::Mod(..) => {
1702-
self.encode_info_for_mod(item.owner_id.def_id);
1703-
}
1704-
hir::ItemKind::OpaqueTy(ref opaque) => {
1705-
self.encode_explicit_item_bounds(def_id);
1706-
self.tables.is_type_alias_impl_trait.set(
1707-
def_id.index,
1708-
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias { .. }),
1709-
);
1710-
}
1711-
hir::ItemKind::ExternCrate(_)
1712-
| hir::ItemKind::Use(..)
1713-
| hir::ItemKind::Impl(..)
1714-
| hir::ItemKind::Trait(..)
1715-
| hir::ItemKind::TraitAlias(..)
1716-
| hir::ItemKind::Static(..)
1717-
| hir::ItemKind::Const(..)
1718-
| hir::ItemKind::Enum(..)
1719-
| hir::ItemKind::Struct(..)
1720-
| hir::ItemKind::Union(..)
1721-
| hir::ItemKind::ForeignMod { .. }
1722-
| hir::ItemKind::GlobalAsm(..)
1723-
| hir::ItemKind::Fn(..)
1724-
| hir::ItemKind::TyAlias(..) => {}
1725-
}
1706+
let hir::ItemKind::Macro(ref macro_def, _) = tcx.hir().expect_item(def_id).kind else { bug!() };
1707+
self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
1708+
record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
17261709
}
17271710

17281711
#[tracing::instrument(level = "debug", skip(self))]
@@ -2100,39 +2083,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
21002083
}
21012084
}
21022085

2103-
// FIXME(eddyb) make metadata encoding walk over all definitions, instead of HIR.
2104-
impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
2105-
type NestedFilter = nested_filter::OnlyBodies;
2106-
2107-
fn nested_visit_map(&mut self) -> Self::Map {
2108-
self.tcx.hir()
2109-
}
2110-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
2111-
intravisit::walk_item(self, item);
2112-
self.encode_info_for_item(item);
2113-
}
2114-
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
2115-
intravisit::walk_generics(self, generics);
2116-
self.encode_info_for_generics(generics);
2117-
}
2118-
}
2119-
2120-
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
2121-
fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
2122-
for param in generics.params {
2123-
match param.kind {
2124-
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => {}
2125-
hir::GenericParamKind::Const { ref default, .. } => {
2126-
let def_id = param.def_id.to_def_id();
2127-
if default.is_some() {
2128-
record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id))
2129-
}
2130-
}
2131-
}
2132-
}
2133-
}
2134-
}
2135-
21362086
/// Used to prefetch queries which will be needed later by metadata encoding.
21372087
/// Only a subset of the queries are actually prefetched to keep this code smaller.
21382088
fn prefetch_mir(tcx: TyCtxt<'_>) {

0 commit comments

Comments
 (0)