Encode LangItem directly
This commit is contained in:
parent
99de57ae13
commit
ebfa1f0185
@ -42,7 +42,7 @@ macro_rules! expand_group {
|
||||
pub struct LanguageItems {
|
||||
/// Mappings from lang items to their possibly found [`DefId`]s.
|
||||
/// The index corresponds to the order in [`LangItem`].
|
||||
pub items: Vec<Option<DefId>>,
|
||||
items: Vec<Option<DefId>>,
|
||||
/// Lang items that were not found during collection.
|
||||
pub missing: Vec<LangItem>,
|
||||
/// Mapping from [`LangItemGroup`] discriminants to all
|
||||
@ -133,11 +133,6 @@ fn init_none(_: LangItem) -> Option<DefId> { None }
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the mappings to the possibly found `DefId`s for each lang item.
|
||||
pub fn items(&self) -> &[Option<DefId>] {
|
||||
&*self.items
|
||||
}
|
||||
|
||||
/// Returns the [`DefId`]s of all lang items in a group.
|
||||
pub fn group(&self, group: LangItemGroup) -> &[DefId] {
|
||||
self.groups[group as usize].as_ref()
|
||||
|
@ -15,7 +15,6 @@
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
|
||||
use rustc_hir::diagnostic_items::DiagnosticItems;
|
||||
use rustc_hir::lang_items;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
@ -967,7 +966,7 @@ fn get_stability_implications(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Symbol
|
||||
}
|
||||
|
||||
/// Iterates over the language items in the given crate.
|
||||
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
|
||||
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, LangItem)] {
|
||||
tcx.arena.alloc_from_iter(
|
||||
self.root
|
||||
.lang_items
|
||||
@ -1319,7 +1318,7 @@ fn get_dylib_dependency_formats(
|
||||
)
|
||||
}
|
||||
|
||||
fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangItem] {
|
||||
fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [LangItem] {
|
||||
tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self))
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
};
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::lang_items;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::{
|
||||
@ -1905,22 +1905,15 @@ fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
|
||||
self.lazy_array(diagnostic_items.iter().map(|(&name, def_id)| (name, def_id.index)))
|
||||
}
|
||||
|
||||
fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, usize)> {
|
||||
fn encode_lang_items(&mut self) -> LazyArray<(DefIndex, LangItem)> {
|
||||
empty_proc_macro!(self);
|
||||
let tcx = self.tcx;
|
||||
let lang_items = tcx.lang_items();
|
||||
let lang_items = lang_items.items().iter();
|
||||
self.lazy_array(lang_items.enumerate().filter_map(|(i, &opt_def_id)| {
|
||||
if let Some(def_id) = opt_def_id {
|
||||
if def_id.is_local() {
|
||||
return Some((def_id.index, i));
|
||||
}
|
||||
}
|
||||
None
|
||||
let lang_items = self.tcx.lang_items().iter();
|
||||
self.lazy_array(lang_items.filter_map(|(lang_item, def_id)| {
|
||||
def_id.as_local().map(|id| (id.local_def_index, lang_item))
|
||||
}))
|
||||
}
|
||||
|
||||
fn encode_lang_items_missing(&mut self) -> LazyArray<lang_items::LangItem> {
|
||||
fn encode_lang_items_missing(&mut self) -> LazyArray<LangItem> {
|
||||
empty_proc_macro!(self);
|
||||
let tcx = self.tcx;
|
||||
self.lazy_array(&tcx.lang_items().missing)
|
||||
|
@ -12,7 +12,7 @@
|
||||
use rustc_hir::def::{CtorKind, DefKind};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, DefPathHash, StableCrateId};
|
||||
use rustc_hir::definitions::DefKey;
|
||||
use rustc_hir::lang_items;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_index::bit_set::{BitSet, FiniteBitSet};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::metadata::ModChild;
|
||||
@ -230,8 +230,8 @@ pub(crate) struct CrateRoot {
|
||||
dylib_dependency_formats: LazyArray<Option<LinkagePreference>>,
|
||||
lib_features: LazyArray<(Symbol, Option<Symbol>)>,
|
||||
stability_implications: LazyArray<(Symbol, Symbol)>,
|
||||
lang_items: LazyArray<(DefIndex, usize)>,
|
||||
lang_items_missing: LazyArray<lang_items::LangItem>,
|
||||
lang_items: LazyArray<(DefIndex, LangItem)>,
|
||||
lang_items_missing: LazyArray<LangItem>,
|
||||
diagnostic_items: LazyArray<(Symbol, DefIndex)>,
|
||||
native_libraries: LazyArray<NativeLib>,
|
||||
foreign_modules: LazyArray<ForeignModule>,
|
||||
|
@ -1705,7 +1705,7 @@
|
||||
}
|
||||
|
||||
/// Returns the lang items defined in another crate by loading it from metadata.
|
||||
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
|
||||
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
|
||||
desc { "calculating the lang items defined in a crate" }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
|
||||
fn collect_item(&mut self, lang_item: LangItem, item_def_id: DefId) {
|
||||
// Check for duplicates.
|
||||
if let Some(original_def_id) = self.items.items[item_index] {
|
||||
if let Some(original_def_id) = self.items.get(lang_item) {
|
||||
if original_def_id != item_def_id {
|
||||
let local_span = self.tcx.hir().span_if_local(item_def_id);
|
||||
let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name();
|
||||
let lang_item_name = lang_item.name();
|
||||
let crate_name = self.tcx.crate_name(item_def_id.krate);
|
||||
let mut dependency_of = Empty;
|
||||
let is_local = item_def_id.is_local();
|
||||
@ -139,8 +139,8 @@ fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
|
||||
}
|
||||
|
||||
// Matched.
|
||||
self.items.items[item_index] = Some(item_def_id);
|
||||
if let Some(group) = LangItem::from_u32(item_index as u32).unwrap().group() {
|
||||
self.items.set(lang_item, item_def_id);
|
||||
if let Some(group) = lang_item.group() {
|
||||
self.items.groups[group as usize].push(item_def_id);
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,7 @@ fn collect_item_extended(&mut self, item_index: usize, hir_id: HirId, span: Span
|
||||
}
|
||||
}
|
||||
|
||||
self.collect_item(item_index, item_def_id);
|
||||
self.collect_item(lang_item, item_def_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,8 +208,8 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||
|
||||
// Collect lang items in other crates.
|
||||
for &cnum in tcx.crates(()).iter() {
|
||||
for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() {
|
||||
collector.collect_item(item_index, def_id);
|
||||
for &(def_id, lang_item) in tcx.defined_lang_items(cnum).iter() {
|
||||
collector.collect_item(lang_item, def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user