Iterate to encode def_kind.
This commit is contained in:
parent
c58a6fa422
commit
a185cdbc59
6 changed files with 57 additions and 72 deletions
|
@ -130,7 +130,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||
static_mutability => { cdata.static_mutability(def_id.index) }
|
||||
generator_kind => { cdata.generator_kind(def_id.index) }
|
||||
def_kind => { cdata.def_kind(def_id.index) }
|
||||
opt_def_kind => { Some(cdata.def_kind(def_id.index)) }
|
||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||
def_ident_span => {
|
||||
cdata.try_item_ident(def_id.index, &tcx.sess).ok().map(|ident| ident.span)
|
||||
|
|
|
@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
|||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_data_structures::sync::{join, Lrc};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, DefKind};
|
||||
use rustc_hir::def::{CtorOf, DefKind};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
|
@ -725,6 +725,14 @@ impl EncodeContext<'a, 'tcx> {
|
|||
let hir = tcx.hir();
|
||||
for local_id in hir.iter_local_def_id() {
|
||||
let def_id = local_id.to_def_id();
|
||||
let def_kind = tcx.opt_def_kind(local_id);
|
||||
let def_kind = if let Some(def_kind) = def_kind { def_kind } else { continue };
|
||||
record!(self.tables.def_kind[def_id] <- match def_kind {
|
||||
// Replace Ctor by the enclosing object to avoid leaking details in children crates.
|
||||
DefKind::Ctor(CtorOf::Struct, _) => DefKind::Struct,
|
||||
DefKind::Ctor(CtorOf::Variant, _) => DefKind::Variant,
|
||||
def_kind => def_kind,
|
||||
});
|
||||
record!(self.tables.span[def_id] <- tcx.def_span(def_id));
|
||||
}
|
||||
}
|
||||
|
@ -752,7 +760,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
};
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Variant);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
|
||||
|
@ -792,7 +799,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
};
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Variant);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
self.encode_stability(def_id);
|
||||
|
@ -844,7 +850,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
expansion: tcx.hir().definitions().expansion_that_defined(local_def_id),
|
||||
};
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Mod);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.attributes[def_id] <- attrs);
|
||||
|
@ -875,7 +880,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
let variant_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
|
||||
let variant_data = tcx.hir().expect_variant_data(variant_id);
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Field);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Field);
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
|
||||
|
@ -901,7 +905,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
};
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Struct);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
|
||||
|
@ -976,7 +979,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
);
|
||||
let rendered_const = self.lazy(RenderedConst(rendered));
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocConst);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
|
||||
container,
|
||||
Default::default(),
|
||||
|
@ -997,7 +999,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
} else {
|
||||
bug!()
|
||||
};
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocFn);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
||||
fn_data,
|
||||
container,
|
||||
|
@ -1006,7 +1007,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
}
|
||||
ty::AssocKind::Type => {
|
||||
self.encode_explicit_item_bounds(def_id);
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocTy);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
|
||||
}
|
||||
}
|
||||
|
@ -1084,7 +1084,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
|
||||
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
|
||||
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocConst);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
|
||||
container,
|
||||
qualifs,
|
||||
|
@ -1104,7 +1103,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
} else {
|
||||
bug!()
|
||||
};
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocFn);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
||||
fn_data,
|
||||
container,
|
||||
|
@ -1112,7 +1110,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
})));
|
||||
}
|
||||
ty::AssocKind::Type => {
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocTy);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
|
||||
}
|
||||
}
|
||||
|
@ -1251,19 +1248,12 @@ impl EncodeContext<'a, 'tcx> {
|
|||
|
||||
self.encode_ident_span(def_id, item.ident);
|
||||
|
||||
let (def_kind, entry_kind) = match item.kind {
|
||||
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => {
|
||||
(DefKind::Static, EntryKind::MutStatic)
|
||||
}
|
||||
hir::ItemKind::Static(_, hir::Mutability::Not, _) => {
|
||||
(DefKind::Static, EntryKind::ImmStatic)
|
||||
}
|
||||
let entry_kind = match item.kind {
|
||||
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
|
||||
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
|
||||
hir::ItemKind::Const(_, body_id) => {
|
||||
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
|
||||
(
|
||||
DefKind::Const,
|
||||
EntryKind::Const(qualifs, self.encode_rendered_const_for_body(body_id)),
|
||||
)
|
||||
EntryKind::Const(qualifs, self.encode_rendered_const_for_body(body_id))
|
||||
}
|
||||
hir::ItemKind::Fn(ref sig, .., body) => {
|
||||
let data = FnData {
|
||||
|
@ -1272,21 +1262,19 @@ impl EncodeContext<'a, 'tcx> {
|
|||
param_names: self.encode_fn_param_names_for_body(body),
|
||||
};
|
||||
|
||||
(DefKind::Fn, EntryKind::Fn(self.lazy(data)))
|
||||
EntryKind::Fn(self.lazy(data))
|
||||
}
|
||||
hir::ItemKind::Mod(ref m) => {
|
||||
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
|
||||
}
|
||||
hir::ItemKind::ForeignMod { .. } => (DefKind::ForeignMod, EntryKind::ForeignMod),
|
||||
hir::ItemKind::GlobalAsm(..) => (DefKind::GlobalAsm, EntryKind::GlobalAsm),
|
||||
hir::ItemKind::TyAlias(..) => (DefKind::TyAlias, EntryKind::Type),
|
||||
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod,
|
||||
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
|
||||
hir::ItemKind::TyAlias(..) => EntryKind::Type,
|
||||
hir::ItemKind::OpaqueTy(..) => {
|
||||
self.encode_explicit_item_bounds(def_id);
|
||||
(DefKind::OpaqueTy, EntryKind::OpaqueTy)
|
||||
}
|
||||
hir::ItemKind::Enum(..) => {
|
||||
(DefKind::Enum, EntryKind::Enum(self.tcx.adt_def(def_id).repr))
|
||||
EntryKind::OpaqueTy
|
||||
}
|
||||
hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr),
|
||||
hir::ItemKind::Struct(ref struct_def, _) => {
|
||||
let adt_def = self.tcx.adt_def(def_id);
|
||||
let variant = adt_def.non_enum_variant();
|
||||
|
@ -1298,7 +1286,7 @@ impl EncodeContext<'a, 'tcx> {
|
|||
.ctor_hir_id()
|
||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||
|
||||
let ek = EntryKind::Struct(
|
||||
EntryKind::Struct(
|
||||
self.lazy(VariantData {
|
||||
ctor_kind: variant.ctor_kind,
|
||||
discr: variant.discr,
|
||||
|
@ -1306,14 +1294,13 @@ impl EncodeContext<'a, 'tcx> {
|
|||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
}),
|
||||
adt_def.repr,
|
||||
);
|
||||
(DefKind::Struct, ek)
|
||||
)
|
||||
}
|
||||
hir::ItemKind::Union(..) => {
|
||||
let adt_def = self.tcx.adt_def(def_id);
|
||||
let variant = adt_def.non_enum_variant();
|
||||
|
||||
let ek = EntryKind::Union(
|
||||
EntryKind::Union(
|
||||
self.lazy(VariantData {
|
||||
ctor_kind: variant.ctor_kind,
|
||||
discr: variant.discr,
|
||||
|
@ -1321,8 +1308,7 @@ impl EncodeContext<'a, 'tcx> {
|
|||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
}),
|
||||
adt_def.repr,
|
||||
);
|
||||
(DefKind::Union, ek)
|
||||
)
|
||||
}
|
||||
hir::ItemKind::Impl(hir::Impl { defaultness, .. }) => {
|
||||
let trait_ref = self.tcx.impl_trait_ref(def_id);
|
||||
|
@ -1352,7 +1338,7 @@ impl EncodeContext<'a, 'tcx> {
|
|||
let data =
|
||||
ImplData { polarity, defaultness, parent_impl: parent, coerce_unsized_info };
|
||||
|
||||
(DefKind::Impl, EntryKind::Impl(self.lazy(data)))
|
||||
EntryKind::Impl(self.lazy(data))
|
||||
}
|
||||
hir::ItemKind::Trait(..) => {
|
||||
let trait_def = self.tcx.trait_def(def_id);
|
||||
|
@ -1364,14 +1350,13 @@ impl EncodeContext<'a, 'tcx> {
|
|||
specialization_kind: trait_def.specialization_kind,
|
||||
};
|
||||
|
||||
(DefKind::Trait, EntryKind::Trait(self.lazy(data)))
|
||||
EntryKind::Trait(self.lazy(data))
|
||||
}
|
||||
hir::ItemKind::TraitAlias(..) => (DefKind::TraitAlias, EntryKind::TraitAlias),
|
||||
hir::ItemKind::TraitAlias(..) => EntryKind::TraitAlias,
|
||||
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {
|
||||
bug!("cannot encode info for item {:?}", item)
|
||||
}
|
||||
};
|
||||
record!(self.tables.def_kind[def_id] <- def_kind);
|
||||
record!(self.tables.kind[def_id] <- entry_kind);
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.attributes[def_id] <- item.attrs);
|
||||
|
@ -1491,7 +1476,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
/// Serialize the text of exported macros
|
||||
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
|
||||
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id).to_def_id();
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Macro(MacroKind::Bang));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
record!(self.tables.attributes[def_id] <- macro_def.attrs);
|
||||
|
@ -1500,14 +1484,7 @@ impl EncodeContext<'a, 'tcx> {
|
|||
self.encode_deprecation(def_id);
|
||||
}
|
||||
|
||||
fn encode_info_for_generic_param(
|
||||
&mut self,
|
||||
def_id: DefId,
|
||||
def_kind: DefKind,
|
||||
kind: EntryKind,
|
||||
encode_type: bool,
|
||||
) {
|
||||
record!(self.tables.def_kind[def_id] <- def_kind);
|
||||
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
|
||||
record!(self.tables.kind[def_id] <- kind);
|
||||
if encode_type {
|
||||
self.encode_item_type(def_id);
|
||||
|
@ -1525,12 +1502,10 @@ impl EncodeContext<'a, 'tcx> {
|
|||
match ty.kind() {
|
||||
ty::Generator(..) => {
|
||||
let data = self.tcx.generator_kind(def_id).unwrap();
|
||||
record!(self.tables.def_kind[def_id.to_def_id()] <- DefKind::Generator);
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Generator(data));
|
||||
}
|
||||
|
||||
ty::Closure(..) => {
|
||||
record!(self.tables.def_kind[def_id.to_def_id()] <- DefKind::Closure);
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Closure);
|
||||
}
|
||||
|
||||
|
@ -1559,7 +1534,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
let const_data = self.encode_rendered_const_for_body(body_id);
|
||||
let qualifs = self.tcx.mir_const_qualif(def_id);
|
||||
|
||||
record!(self.tables.def_kind[def_id.to_def_id()] <- DefKind::AnonConst);
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data));
|
||||
self.encode_item_type(def_id.to_def_id());
|
||||
self.encode_generics(def_id.to_def_id());
|
||||
|
@ -1822,19 +1796,15 @@ impl EncodeContext<'a, 'tcx> {
|
|||
},
|
||||
param_names: self.encode_fn_param_names(names),
|
||||
};
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Fn);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignFn(self.lazy(data)));
|
||||
}
|
||||
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => {
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Static);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignMutStatic);
|
||||
}
|
||||
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => {
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::Static);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignImmStatic);
|
||||
}
|
||||
hir::ForeignItemKind::Type => {
|
||||
record!(self.tables.def_kind[def_id] <- DefKind::ForeignTy);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
|
||||
}
|
||||
}
|
||||
|
@ -1912,7 +1882,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
GenericParamKind::Type { ref default, .. } => {
|
||||
self.encode_info_for_generic_param(
|
||||
def_id.to_def_id(),
|
||||
DefKind::TyParam,
|
||||
EntryKind::TypeParam,
|
||||
default.is_some(),
|
||||
);
|
||||
|
@ -1923,7 +1892,6 @@ impl EncodeContext<'a, 'tcx> {
|
|||
GenericParamKind::Const { .. } => {
|
||||
self.encode_info_for_generic_param(
|
||||
def_id.to_def_id(),
|
||||
DefKind::ConstParam,
|
||||
EntryKind::ConstParam,
|
||||
true,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue