Skip to content

Commit faee780

Browse files
committed
Iterate on type_of.
1 parent 488c368 commit faee780

File tree

1 file changed

+7
-50
lines changed

1 file changed

+7
-50
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ impl EncodeContext<'a, 'tcx> {
950950
if let DefKind::Trait | DefKind::TraitAlias = def_kind {
951951
record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
952952
}
953+
if let Ok(ty) = self.tcx.try_type_of(def_id) {
954+
record!(self.tables.ty[def_id] <- ty);
955+
}
953956
}
954957
let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE);
955958
for (def_id, implementations) in inherent_impls.inherent_impls.iter() {
@@ -964,11 +967,6 @@ impl EncodeContext<'a, 'tcx> {
964967
}
965968
}
966969

967-
fn encode_item_type(&mut self, def_id: DefId) {
968-
debug!("EncodeContext::encode_item_type({:?})", def_id);
969-
record!(self.tables.ty[def_id] <- self.tcx.type_of(def_id));
970-
}
971-
972970
fn encode_enum_variant_info(&mut self, def: &ty::AdtDef, index: VariantIdx) {
973971
let tcx = self.tcx;
974972
let variant = &def.variants[index];
@@ -988,7 +986,6 @@ impl EncodeContext<'a, 'tcx> {
988986
f.did.index
989987
}));
990988
self.encode_ident_span(def_id, variant.ident);
991-
self.encode_item_type(def_id);
992989
if variant.ctor_kind == CtorKind::Fn {
993990
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
994991
if let Some(ctor_def_id) = variant.ctor_def_id {
@@ -1012,7 +1009,6 @@ impl EncodeContext<'a, 'tcx> {
10121009
};
10131010

10141011
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1015-
self.encode_item_type(def_id);
10161012
if variant.ctor_kind == CtorKind::Fn {
10171013
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
10181014
}
@@ -1073,7 +1069,6 @@ impl EncodeContext<'a, 'tcx> {
10731069

10741070
record!(self.tables.kind[def_id] <- EntryKind::Field);
10751071
self.encode_ident_span(def_id, field.ident);
1076-
self.encode_item_type(def_id);
10771072
}
10781073

10791074
fn encode_struct_ctor(&mut self, adt_def: &ty::AdtDef, def_id: DefId) {
@@ -1089,7 +1084,6 @@ impl EncodeContext<'a, 'tcx> {
10891084
};
10901085

10911086
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
1092-
self.encode_item_type(def_id);
10931087
if variant.ctor_kind == CtorKind::Fn {
10941088
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
10951089
}
@@ -1157,16 +1151,6 @@ impl EncodeContext<'a, 'tcx> {
11571151
}
11581152
}
11591153
self.encode_ident_span(def_id, ast_item.ident);
1160-
match trait_item.kind {
1161-
ty::AssocKind::Const | ty::AssocKind::Fn => {
1162-
self.encode_item_type(def_id);
1163-
}
1164-
ty::AssocKind::Type => {
1165-
if trait_item.defaultness.has_value() {
1166-
self.encode_item_type(def_id);
1167-
}
1168-
}
1169-
}
11701154
if trait_item.kind == ty::AssocKind::Fn {
11711155
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
11721156
}
@@ -1223,7 +1207,6 @@ impl EncodeContext<'a, 'tcx> {
12231207
}
12241208
}
12251209
self.encode_ident_span(def_id, impl_item.ident);
1226-
self.encode_item_type(def_id);
12271210
if impl_item.kind == ty::AssocKind::Fn {
12281211
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
12291212
}
@@ -1471,18 +1454,6 @@ impl EncodeContext<'a, 'tcx> {
14711454
}
14721455
_ => {}
14731456
}
1474-
match item.kind {
1475-
hir::ItemKind::Static(..)
1476-
| hir::ItemKind::Const(..)
1477-
| hir::ItemKind::Fn(..)
1478-
| hir::ItemKind::TyAlias(..)
1479-
| hir::ItemKind::OpaqueTy(..)
1480-
| hir::ItemKind::Enum(..)
1481-
| hir::ItemKind::Struct(..)
1482-
| hir::ItemKind::Union(..)
1483-
| hir::ItemKind::Impl { .. } => self.encode_item_type(def_id),
1484-
_ => {}
1485-
}
14861457
if let hir::ItemKind::Fn(..) = item.kind {
14871458
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
14881459
}
@@ -1500,11 +1471,8 @@ impl EncodeContext<'a, 'tcx> {
15001471
self.encode_ident_span(def_id, macro_def.ident);
15011472
}
15021473

1503-
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
1474+
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind) {
15041475
record!(self.tables.kind[def_id] <- kind);
1505-
if encode_type {
1506-
self.encode_item_type(def_id);
1507-
}
15081476
}
15091477

15101478
fn encode_info_for_closure(&mut self, def_id: LocalDefId) {
@@ -1527,7 +1495,6 @@ impl EncodeContext<'a, 'tcx> {
15271495

15281496
_ => bug!("closure that is neither generator nor closure"),
15291497
}
1530-
self.encode_item_type(def_id.to_def_id());
15311498
if let ty::Closure(def_id, substs) = *ty.kind() {
15321499
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
15331500
}
@@ -1541,7 +1508,6 @@ impl EncodeContext<'a, 'tcx> {
15411508
let qualifs = self.tcx.mir_const_qualif(def_id);
15421509

15431510
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data));
1544-
self.encode_item_type(def_id.to_def_id());
15451511
}
15461512

15471513
fn encode_native_libraries(&mut self) -> Lazy<[NativeLib]> {
@@ -1817,7 +1783,6 @@ impl EncodeContext<'a, 'tcx> {
18171783
}
18181784
}
18191785
self.encode_ident_span(def_id, nitem.ident);
1820-
self.encode_item_type(def_id);
18211786
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
18221787
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
18231788
}
@@ -1875,19 +1840,11 @@ impl EncodeContext<'a, 'tcx> {
18751840
let def_id = self.tcx.hir().local_def_id(param.hir_id);
18761841
match param.kind {
18771842
GenericParamKind::Lifetime { .. } => continue,
1878-
GenericParamKind::Type { default, .. } => {
1879-
self.encode_info_for_generic_param(
1880-
def_id.to_def_id(),
1881-
EntryKind::TypeParam,
1882-
default.is_some(),
1883-
);
1843+
GenericParamKind::Type { .. } => {
1844+
self.encode_info_for_generic_param(def_id.to_def_id(), EntryKind::TypeParam);
18841845
}
18851846
GenericParamKind::Const { .. } => {
1886-
self.encode_info_for_generic_param(
1887-
def_id.to_def_id(),
1888-
EntryKind::ConstParam,
1889-
true,
1890-
);
1847+
self.encode_info_for_generic_param(def_id.to_def_id(), EntryKind::ConstParam);
18911848
// FIXME(const_generics_defaults)
18921849
}
18931850
}

0 commit comments

Comments
 (0)