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

Commit 293e885

Browse files
committed
Iterate DefId to encode attributes.
1 parent f1bf6d0 commit 293e885

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
22
use crate::rmeta::*;
33

4-
use rustc_ast as ast;
54
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder};
65
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
76
use rustc_data_structures::stable_hasher::StableHasher;
@@ -437,7 +436,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
437436

438437
fn encode_info_for_items(&mut self) {
439438
let krate = self.tcx.hir().krate();
440-
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.item.module, &krate.item.attrs);
439+
self.encode_info_for_mod(hir::CRATE_HIR_ID, &krate.item.module);
441440

442441
// Proc-macro crates only export proc-macro items, which are looked
443442
// up using `proc_macro_data`
@@ -769,6 +768,7 @@ impl EncodeContext<'a, 'tcx> {
769768
def_kind => def_kind,
770769
});
771770
record!(self.tables.span[def_id] <- tcx.def_span(def_id));
771+
record!(self.tables.attributes[def_id] <- tcx.get_attrs(def_id));
772772
if should_encode_visibility(def_kind) {
773773
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
774774
}
@@ -799,7 +799,6 @@ impl EncodeContext<'a, 'tcx> {
799799
};
800800

801801
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
802-
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
803802
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
804803
record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
805804
assert!(f.did.is_local());
@@ -854,7 +853,7 @@ impl EncodeContext<'a, 'tcx> {
854853
self.encode_mir_for_ctfe(def_id.expect_local());
855854
}
856855

857-
fn encode_info_for_mod(&mut self, id: hir::HirId, md: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
856+
fn encode_info_for_mod(&mut self, id: hir::HirId, md: &hir::Mod<'_>) {
858857
let tcx = self.tcx;
859858
let local_def_id = tcx.hir().local_def_id(id);
860859
let def_id = local_def_id.to_def_id();
@@ -887,7 +886,6 @@ impl EncodeContext<'a, 'tcx> {
887886
};
888887

889888
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
890-
record!(self.tables.attributes[def_id] <- attrs);
891889
if self.is_proc_macro {
892890
record!(self.tables.children[def_id] <- &[]);
893891
} else {
@@ -905,18 +903,13 @@ impl EncodeContext<'a, 'tcx> {
905903
variant_index: VariantIdx,
906904
field_index: usize,
907905
) {
908-
let tcx = self.tcx;
909906
let variant = &adt_def.variants[variant_index];
910907
let field = &variant.fields[field_index];
911908

912909
let def_id = field.did;
913910
debug!("EncodeContext::encode_field({:?})", def_id);
914911

915-
let variant_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
916-
let variant_data = tcx.hir().expect_variant_data(variant_id);
917-
918912
record!(self.tables.kind[def_id] <- EntryKind::Field);
919-
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
920913
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
921914
self.encode_ident_span(def_id, field.ident);
922915
self.encode_stability(def_id);
@@ -1043,7 +1036,6 @@ impl EncodeContext<'a, 'tcx> {
10431036
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
10441037
}
10451038
}
1046-
record!(self.tables.attributes[def_id] <- ast_item.attrs);
10471039
self.encode_ident_span(def_id, ast_item.ident);
10481040
self.encode_stability(def_id);
10491041
self.encode_const_stability(def_id);
@@ -1145,7 +1137,6 @@ impl EncodeContext<'a, 'tcx> {
11451137
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
11461138
}
11471139
}
1148-
record!(self.tables.attributes[def_id] <- ast_item.attrs);
11491140
self.encode_ident_span(def_id, impl_item.ident);
11501141
self.encode_stability(def_id);
11511142
self.encode_const_stability(def_id);
@@ -1296,7 +1287,7 @@ impl EncodeContext<'a, 'tcx> {
12961287
EntryKind::Fn(self.lazy(data))
12971288
}
12981289
hir::ItemKind::Mod(ref m) => {
1299-
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
1290+
return self.encode_info_for_mod(item.hir_id, m);
13001291
}
13011292
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod,
13021293
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
@@ -1389,7 +1380,6 @@ impl EncodeContext<'a, 'tcx> {
13891380
}
13901381
};
13911382
record!(self.tables.kind[def_id] <- entry_kind);
1392-
record!(self.tables.attributes[def_id] <- item.attrs);
13931383
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
13941384
// FIXME(eddyb) there should be a nicer way to do this.
13951385
match item.kind {
@@ -1507,7 +1497,6 @@ impl EncodeContext<'a, 'tcx> {
15071497
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
15081498
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id).to_def_id();
15091499
record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
1510-
record!(self.tables.attributes[def_id] <- macro_def.attrs);
15111500
self.encode_ident_span(def_id, macro_def.ident);
15121501
self.encode_stability(def_id);
15131502
self.encode_deprecation(def_id);
@@ -1540,7 +1529,6 @@ impl EncodeContext<'a, 'tcx> {
15401529

15411530
_ => bug!("closure that is neither generator nor closure"),
15421531
}
1543-
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
15441532
self.encode_item_type(def_id.to_def_id());
15451533
if let ty::Closure(def_id, substs) = *ty.kind() {
15461534
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
@@ -1837,7 +1825,6 @@ impl EncodeContext<'a, 'tcx> {
18371825
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
18381826
}
18391827
}
1840-
record!(self.tables.attributes[def_id] <- nitem.attrs);
18411828
self.encode_ident_span(def_id, nitem.ident);
18421829
self.encode_stability(def_id);
18431830
self.encode_const_stability(def_id);

0 commit comments

Comments
 (0)