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) }
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||||
static_mutability => { cdata.static_mutability(def_id.index) }
|
static_mutability => { cdata.static_mutability(def_id.index) }
|
||||||
generator_kind => { cdata.generator_kind(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_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||||
def_ident_span => {
|
def_ident_span => {
|
||||||
cdata.try_item_ident(def_id.index, &tcx.sess).ok().map(|ident| 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::stable_hasher::StableHasher;
|
||||||
use rustc_data_structures::sync::{join, Lrc};
|
use rustc_data_structures::sync::{join, Lrc};
|
||||||
use rustc_hir as hir;
|
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::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::DefPathData;
|
use rustc_hir::definitions::DefPathData;
|
||||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
|
@ -725,6 +725,14 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
for local_id in hir.iter_local_def_id() {
|
for local_id in hir.iter_local_def_id() {
|
||||||
let def_id = local_id.to_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));
|
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(),
|
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.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(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(),
|
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.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
self.encode_stability(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),
|
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.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
|
||||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.attributes[def_id] <- attrs);
|
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_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
|
||||||
let variant_data = tcx.hir().expect_variant_data(variant_id);
|
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.kind[def_id] <- EntryKind::Field);
|
||||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
|
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(),
|
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.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.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(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));
|
let rendered_const = self.lazy(RenderedConst(rendered));
|
||||||
|
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocConst);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
|
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
|
||||||
container,
|
container,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -997,7 +999,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
bug!()
|
bug!()
|
||||||
};
|
};
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocFn);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
||||||
fn_data,
|
fn_data,
|
||||||
container,
|
container,
|
||||||
|
@ -1006,7 +1007,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type => {
|
ty::AssocKind::Type => {
|
||||||
self.encode_explicit_item_bounds(def_id);
|
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));
|
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 {
|
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
|
||||||
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
|
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(
|
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
|
||||||
container,
|
container,
|
||||||
qualifs,
|
qualifs,
|
||||||
|
@ -1104,7 +1103,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
bug!()
|
bug!()
|
||||||
};
|
};
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocFn);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
||||||
fn_data,
|
fn_data,
|
||||||
container,
|
container,
|
||||||
|
@ -1112,7 +1110,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type => {
|
ty::AssocKind::Type => {
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::AssocTy);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
|
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);
|
self.encode_ident_span(def_id, item.ident);
|
||||||
|
|
||||||
let (def_kind, entry_kind) = match item.kind {
|
let entry_kind = match item.kind {
|
||||||
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => {
|
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
|
||||||
(DefKind::Static, EntryKind::MutStatic)
|
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
|
||||||
}
|
|
||||||
hir::ItemKind::Static(_, hir::Mutability::Not, _) => {
|
|
||||||
(DefKind::Static, EntryKind::ImmStatic)
|
|
||||||
}
|
|
||||||
hir::ItemKind::Const(_, body_id) => {
|
hir::ItemKind::Const(_, body_id) => {
|
||||||
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
|
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
|
||||||
(
|
EntryKind::Const(qualifs, self.encode_rendered_const_for_body(body_id))
|
||||||
DefKind::Const,
|
|
||||||
EntryKind::Const(qualifs, self.encode_rendered_const_for_body(body_id)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::Fn(ref sig, .., body) => {
|
hir::ItemKind::Fn(ref sig, .., body) => {
|
||||||
let data = FnData {
|
let data = FnData {
|
||||||
|
@ -1272,21 +1262,19 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
param_names: self.encode_fn_param_names_for_body(body),
|
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) => {
|
hir::ItemKind::Mod(ref m) => {
|
||||||
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
|
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
|
||||||
}
|
}
|
||||||
hir::ItemKind::ForeignMod { .. } => (DefKind::ForeignMod, EntryKind::ForeignMod),
|
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod,
|
||||||
hir::ItemKind::GlobalAsm(..) => (DefKind::GlobalAsm, EntryKind::GlobalAsm),
|
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
|
||||||
hir::ItemKind::TyAlias(..) => (DefKind::TyAlias, EntryKind::Type),
|
hir::ItemKind::TyAlias(..) => EntryKind::Type,
|
||||||
hir::ItemKind::OpaqueTy(..) => {
|
hir::ItemKind::OpaqueTy(..) => {
|
||||||
self.encode_explicit_item_bounds(def_id);
|
self.encode_explicit_item_bounds(def_id);
|
||||||
(DefKind::OpaqueTy, EntryKind::OpaqueTy)
|
EntryKind::OpaqueTy
|
||||||
}
|
|
||||||
hir::ItemKind::Enum(..) => {
|
|
||||||
(DefKind::Enum, EntryKind::Enum(self.tcx.adt_def(def_id).repr))
|
|
||||||
}
|
}
|
||||||
|
hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr),
|
||||||
hir::ItemKind::Struct(ref struct_def, _) => {
|
hir::ItemKind::Struct(ref struct_def, _) => {
|
||||||
let adt_def = self.tcx.adt_def(def_id);
|
let adt_def = self.tcx.adt_def(def_id);
|
||||||
let variant = adt_def.non_enum_variant();
|
let variant = adt_def.non_enum_variant();
|
||||||
|
@ -1298,7 +1286,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
.ctor_hir_id()
|
.ctor_hir_id()
|
||||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
.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 {
|
self.lazy(VariantData {
|
||||||
ctor_kind: variant.ctor_kind,
|
ctor_kind: variant.ctor_kind,
|
||||||
discr: variant.discr,
|
discr: variant.discr,
|
||||||
|
@ -1306,14 +1294,13 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||||
}),
|
}),
|
||||||
adt_def.repr,
|
adt_def.repr,
|
||||||
);
|
)
|
||||||
(DefKind::Struct, ek)
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(..) => {
|
hir::ItemKind::Union(..) => {
|
||||||
let adt_def = self.tcx.adt_def(def_id);
|
let adt_def = self.tcx.adt_def(def_id);
|
||||||
let variant = adt_def.non_enum_variant();
|
let variant = adt_def.non_enum_variant();
|
||||||
|
|
||||||
let ek = EntryKind::Union(
|
EntryKind::Union(
|
||||||
self.lazy(VariantData {
|
self.lazy(VariantData {
|
||||||
ctor_kind: variant.ctor_kind,
|
ctor_kind: variant.ctor_kind,
|
||||||
discr: variant.discr,
|
discr: variant.discr,
|
||||||
|
@ -1321,8 +1308,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||||
}),
|
}),
|
||||||
adt_def.repr,
|
adt_def.repr,
|
||||||
);
|
)
|
||||||
(DefKind::Union, ek)
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(hir::Impl { defaultness, .. }) => {
|
hir::ItemKind::Impl(hir::Impl { defaultness, .. }) => {
|
||||||
let trait_ref = self.tcx.impl_trait_ref(def_id);
|
let trait_ref = self.tcx.impl_trait_ref(def_id);
|
||||||
|
@ -1352,7 +1338,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
let data =
|
let data =
|
||||||
ImplData { polarity, defaultness, parent_impl: parent, coerce_unsized_info };
|
ImplData { polarity, defaultness, parent_impl: parent, coerce_unsized_info };
|
||||||
|
|
||||||
(DefKind::Impl, EntryKind::Impl(self.lazy(data)))
|
EntryKind::Impl(self.lazy(data))
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(..) => {
|
hir::ItemKind::Trait(..) => {
|
||||||
let trait_def = self.tcx.trait_def(def_id);
|
let trait_def = self.tcx.trait_def(def_id);
|
||||||
|
@ -1364,14 +1350,13 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
specialization_kind: trait_def.specialization_kind,
|
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(..) => {
|
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {
|
||||||
bug!("cannot encode info for item {:?}", item)
|
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.kind[def_id] <- entry_kind);
|
||||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.attributes[def_id] <- item.attrs);
|
record!(self.tables.attributes[def_id] <- item.attrs);
|
||||||
|
@ -1491,7 +1476,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
/// Serialize the text of exported macros
|
/// Serialize the text of exported macros
|
||||||
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
|
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();
|
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.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.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||||
record!(self.tables.attributes[def_id] <- macro_def.attrs);
|
record!(self.tables.attributes[def_id] <- macro_def.attrs);
|
||||||
|
@ -1500,14 +1484,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
self.encode_deprecation(def_id);
|
self.encode_deprecation(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_info_for_generic_param(
|
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
|
||||||
&mut self,
|
|
||||||
def_id: DefId,
|
|
||||||
def_kind: DefKind,
|
|
||||||
kind: EntryKind,
|
|
||||||
encode_type: bool,
|
|
||||||
) {
|
|
||||||
record!(self.tables.def_kind[def_id] <- def_kind);
|
|
||||||
record!(self.tables.kind[def_id] <- kind);
|
record!(self.tables.kind[def_id] <- kind);
|
||||||
if encode_type {
|
if encode_type {
|
||||||
self.encode_item_type(def_id);
|
self.encode_item_type(def_id);
|
||||||
|
@ -1525,12 +1502,10 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Generator(..) => {
|
ty::Generator(..) => {
|
||||||
let data = self.tcx.generator_kind(def_id).unwrap();
|
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));
|
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Generator(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Closure(..) => {
|
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);
|
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 const_data = self.encode_rendered_const_for_body(body_id);
|
||||||
let qualifs = self.tcx.mir_const_qualif(def_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));
|
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_item_type(def_id.to_def_id());
|
||||||
self.encode_generics(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),
|
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)));
|
record!(self.tables.kind[def_id] <- EntryKind::ForeignFn(self.lazy(data)));
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => {
|
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => {
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::Static);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignMutStatic);
|
record!(self.tables.kind[def_id] <- EntryKind::ForeignMutStatic);
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => {
|
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => {
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::Static);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignImmStatic);
|
record!(self.tables.kind[def_id] <- EntryKind::ForeignImmStatic);
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Type => {
|
hir::ForeignItemKind::Type => {
|
||||||
record!(self.tables.def_kind[def_id] <- DefKind::ForeignTy);
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
|
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1912,7 +1882,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
GenericParamKind::Type { ref default, .. } => {
|
GenericParamKind::Type { ref default, .. } => {
|
||||||
self.encode_info_for_generic_param(
|
self.encode_info_for_generic_param(
|
||||||
def_id.to_def_id(),
|
def_id.to_def_id(),
|
||||||
DefKind::TyParam,
|
|
||||||
EntryKind::TypeParam,
|
EntryKind::TypeParam,
|
||||||
default.is_some(),
|
default.is_some(),
|
||||||
);
|
);
|
||||||
|
@ -1923,7 +1892,6 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
GenericParamKind::Const { .. } => {
|
GenericParamKind::Const { .. } => {
|
||||||
self.encode_info_for_generic_param(
|
self.encode_info_for_generic_param(
|
||||||
def_id.to_def_id(),
|
def_id.to_def_id(),
|
||||||
DefKind::ConstParam,
|
|
||||||
EntryKind::ConstParam,
|
EntryKind::ConstParam,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use self::collector::NodeCollector;
|
use self::collector::NodeCollector;
|
||||||
|
|
||||||
use crate::hir::{Owner, OwnerNodes};
|
use crate::hir::{Owner, OwnerNodes};
|
||||||
use crate::ty::query::Providers;
|
|
||||||
use crate::ty::TyCtxt;
|
use crate::ty::TyCtxt;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
|
@ -187,14 +186,14 @@ impl<'hir> Map<'hir> {
|
||||||
self.tcx.definitions.iter_local_def_id()
|
self.tcx.definitions.iter_local_def_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_kind(&self, local_def_id: LocalDefId) -> DefKind {
|
pub fn opt_def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> {
|
||||||
// FIXME(eddyb) support `find` on the crate root.
|
// FIXME(eddyb) support `find` on the crate root.
|
||||||
if local_def_id.to_def_id().index == CRATE_DEF_INDEX {
|
if local_def_id.to_def_id().index == CRATE_DEF_INDEX {
|
||||||
return DefKind::Mod;
|
return Some(DefKind::Mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir_id = self.local_def_id_to_hir_id(local_def_id);
|
let hir_id = self.local_def_id_to_hir_id(local_def_id);
|
||||||
match self.get(hir_id) {
|
let def_kind = match self.find(hir_id)? {
|
||||||
Node::Item(item) => match item.kind {
|
Node::Item(item) => match item.kind {
|
||||||
ItemKind::Static(..) => DefKind::Static,
|
ItemKind::Static(..) => DefKind::Static,
|
||||||
ItemKind::Const(..) => DefKind::Const,
|
ItemKind::Const(..) => DefKind::Const,
|
||||||
|
@ -265,8 +264,14 @@ impl<'hir> Map<'hir> {
|
||||||
| Node::Lifetime(_)
|
| Node::Lifetime(_)
|
||||||
| Node::Visibility(_)
|
| Node::Visibility(_)
|
||||||
| Node::Block(_)
|
| Node::Block(_)
|
||||||
| Node::Crate(_) => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)),
|
| Node::Crate(_) => return None,
|
||||||
|
};
|
||||||
|
Some(def_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn def_kind(&self, local_def_id: LocalDefId) -> DefKind {
|
||||||
|
self.opt_def_kind(local_def_id)
|
||||||
|
.unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", local_def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
|
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
|
||||||
|
@ -1110,7 +1115,3 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
|
||||||
None => format!("unknown node{}", id_str),
|
None => format!("unknown node{}", id_str),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
|
||||||
providers.def_kind = |tcx, def_id| tcx.hir().def_kind(def_id.expect_local());
|
|
||||||
}
|
|
||||||
|
|
|
@ -94,5 +94,5 @@ pub fn provide(providers: &mut Providers) {
|
||||||
span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", id);
|
span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
map::provide(providers);
|
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
|
||||||
}
|
}
|
||||||
|
|
|
@ -878,7 +878,7 @@ rustc_queries! {
|
||||||
cache_on_disk_if { true }
|
cache_on_disk_if { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
query def_kind(def_id: DefId) -> DefKind {
|
query opt_def_kind(def_id: DefId) -> Option<DefKind> {
|
||||||
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
|
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,3 +130,19 @@ mod sealed {
|
||||||
}
|
}
|
||||||
|
|
||||||
use sealed::IntoQueryParam;
|
use sealed::IntoQueryParam;
|
||||||
|
|
||||||
|
impl TyCtxt<'tcx> {
|
||||||
|
pub fn def_kind(self, def_id: impl IntoQueryParam<DefId>) -> DefKind {
|
||||||
|
let def_id = def_id.into_query_param();
|
||||||
|
self.opt_def_kind(def_id)
|
||||||
|
.unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TyCtxtAt<'tcx> {
|
||||||
|
pub fn def_kind(self, def_id: impl IntoQueryParam<DefId>) -> DefKind {
|
||||||
|
let def_id = def_id.into_query_param();
|
||||||
|
self.opt_def_kind(def_id)
|
||||||
|
.unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue