Encode def_ident_span using the query.

This commit is contained in:
Camille GILLOT 2022-04-03 15:10:26 +02:00
parent df59705301
commit 871993f7a1
2 changed files with 5 additions and 23 deletions

View file

@ -774,17 +774,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
let name = self.opt_item_name(item_index)?;
let span = match self.root.tables.def_ident_span.get(self, item_index) {
Some(lazy_span) => lazy_span.decode((self, sess)),
None => {
// FIXME: this weird case of a name with no span is specific to `extern crate`
// items, which are supposed to be treated like `use` items and only be encoded
// to metadata as `Export`s, return `None` because that's what all the callers
// expect in this case.
assert_eq!(self.def_kind(item_index), DefKind::ExternCrate);
return None;
}
};
let span = self.root.tables.def_ident_span.get(self, item_index)?.decode((self, sess));
Some(Ident::new(name, span))
}

View file

@ -31,7 +31,7 @@ use rustc_serialize::{opaque, Encodable, Encoder};
use rustc_session::config::CrateType;
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
use rustc_span::hygiene::{ExpnIndex, HygieneEncodeContext, MacroKind};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{
self, DebuggerVisualizerFile, ExternalSource, FileName, SourceFile, Span, SyntaxContext,
};
@ -1011,6 +1011,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.def_span[def_id] <- tcx.def_span(def_id));
self.encode_attrs(local_id);
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expn_that_defined(def_id));
if let Some(ident_span) = tcx.def_ident_span(def_id) {
record!(self.tables.def_ident_span[def_id] <- ident_span);
}
if def_kind.has_codegen_attrs() {
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
}
@ -1075,7 +1078,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
assert!(f.did.is_local());
f.did.index
}));
self.encode_ident_span(def_id, variant.ident(tcx));
self.encode_item_type(def_id);
if variant.ctor_kind == CtorKind::Fn {
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
@ -1167,7 +1169,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_field({:?})", def_id);
record!(self.tables.kind[def_id] <- EntryKind::Field);
self.encode_ident_span(def_id, field.ident(self.tcx));
self.encode_item_type(def_id);
}
@ -1246,7 +1247,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
}
}
self.encode_ident_span(def_id, ast_item.ident);
match trait_item.kind {
ty::AssocKind::Const | ty::AssocKind::Fn => {
self.encode_item_type(def_id);
@ -1310,7 +1310,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
}
}
self.encode_ident_span(def_id, impl_item.ident(self.tcx));
self.encode_item_type(def_id);
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
self.tables.trait_item_def_id.set(def_id.index, trait_item_def_id.into());
@ -1412,8 +1411,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
self.encode_ident_span(def_id, item.ident);
let entry_kind = match item.kind {
hir::ItemKind::Static(..) => EntryKind::Static,
hir::ItemKind::Const(_, body_id) => {
@ -1959,7 +1956,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
}
}
self.encode_ident_span(def_id, nitem.ident);
self.encode_item_type(def_id);
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@ -2041,10 +2037,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}
fn encode_ident_span(&mut self, def_id: DefId, ident: Ident) {
record!(self.tables.def_ident_span[def_id] <- ident.span);
}
/// In some cases, along with the item itself, we also
/// encode some sub-items. Usually we want some info from the item
/// so it's easier to do that here then to wait until we would encounter