Return a FxHashSet<LocalDefId>
from mir_keys
query
This commit is contained in:
parent
82cc530431
commit
82823c0229
@ -5,12 +5,11 @@ use log::{debug, trace};
|
||||
use rustc_ast::ast::{self, Ident};
|
||||
use rustc_ast::attr;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_data_structures::sync::{join, Lrc};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::CtorKind;
|
||||
use rustc_hir::def_id::DefIdSet;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathTable;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
@ -644,8 +643,8 @@ impl EncodeContext<'tcx> {
|
||||
self.encode_generics(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
|
||||
fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) {
|
||||
@ -683,8 +682,8 @@ impl EncodeContext<'tcx> {
|
||||
self.encode_generics(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
|
||||
fn encode_info_for_mod(
|
||||
@ -786,8 +785,8 @@ impl EncodeContext<'tcx> {
|
||||
self.encode_generics(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
|
||||
fn encode_generics(&mut self, def_id: DefId) {
|
||||
@ -896,8 +895,8 @@ impl EncodeContext<'tcx> {
|
||||
self.encode_inferred_outlives(def_id);
|
||||
|
||||
// This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
|
||||
fn metadata_output_only(&self) -> bool {
|
||||
@ -985,8 +984,8 @@ impl EncodeContext<'tcx> {
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => false,
|
||||
};
|
||||
if mir {
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1004,17 +1003,17 @@ impl EncodeContext<'tcx> {
|
||||
self.lazy(param_names.iter().map(|ident| ident.name))
|
||||
}
|
||||
|
||||
fn encode_optimized_mir(&mut self, def_id: DefId) {
|
||||
fn encode_optimized_mir(&mut self, def_id: LocalDefId) {
|
||||
debug!("EntryBuilder::encode_mir({:?})", def_id);
|
||||
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
|
||||
record!(self.tables.mir[def_id] <- self.tcx.optimized_mir(def_id));
|
||||
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_promoted_mir(&mut self, def_id: DefId) {
|
||||
fn encode_promoted_mir(&mut self, def_id: LocalDefId) {
|
||||
debug!("EncodeContext::encode_promoted_mir({:?})", def_id);
|
||||
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
|
||||
record!(self.tables.promoted_mir[def_id] <- self.tcx.promoted_mir(def_id));
|
||||
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1282,8 +1281,8 @@ impl EncodeContext<'tcx> {
|
||||
_ => false,
|
||||
};
|
||||
if mir {
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
self.encode_promoted_mir(def_id.expect_local());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1316,8 +1315,7 @@ impl EncodeContext<'tcx> {
|
||||
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
|
||||
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
|
||||
|
||||
let def_id = def_id.to_def_id();
|
||||
record!(self.tables.kind[def_id] <- match ty.kind {
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
|
||||
ty::Generator(..) => {
|
||||
let data = self.tcx.generator_kind(def_id).unwrap();
|
||||
EntryKind::Generator(data)
|
||||
@ -1327,14 +1325,14 @@ impl EncodeContext<'tcx> {
|
||||
|
||||
_ => bug!("closure that is neither generator nor closure"),
|
||||
});
|
||||
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
|
||||
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
|
||||
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
|
||||
self.encode_item_type(def_id);
|
||||
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
|
||||
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
|
||||
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
|
||||
self.encode_item_type(def_id.to_def_id());
|
||||
if let ty::Closure(def_id, substs) = ty.kind {
|
||||
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_generics(def_id.to_def_id());
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
@ -1344,16 +1342,15 @@ impl EncodeContext<'tcx> {
|
||||
let id = self.tcx.hir().as_local_hir_id(def_id);
|
||||
let body_id = self.tcx.hir().body_owned_by(id);
|
||||
let const_data = self.encode_rendered_const_for_body(body_id);
|
||||
let def_id = def_id.to_def_id();
|
||||
let qualifs = self.tcx.mir_const_qualif(def_id);
|
||||
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Const(qualifs, const_data));
|
||||
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
|
||||
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
|
||||
self.encode_item_type(def_id);
|
||||
self.encode_generics(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Const(qualifs, const_data));
|
||||
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
|
||||
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
|
||||
self.encode_item_type(def_id.to_def_id());
|
||||
self.encode_generics(def_id.to_def_id());
|
||||
self.encode_explicit_predicates(def_id.to_def_id());
|
||||
self.encode_inferred_outlives(def_id.to_def_id());
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
@ -1726,12 +1723,11 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
|
||||
/// Only a subset of the queries are actually prefetched to keep this code smaller.
|
||||
struct PrefetchVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
mir_keys: &'tcx DefIdSet,
|
||||
mir_keys: &'tcx FxHashSet<LocalDefId>,
|
||||
}
|
||||
|
||||
impl<'tcx> PrefetchVisitor<'tcx> {
|
||||
fn prefetch_mir(&self, def_id: LocalDefId) {
|
||||
let def_id = def_id.to_def_id();
|
||||
if self.mir_keys.contains(&def_id) {
|
||||
self.tcx.optimized_mir(def_id);
|
||||
self.tcx.promoted_mir(def_id);
|
||||
|
@ -34,7 +34,8 @@ macro_rules! arena_types {
|
||||
rustc_hir::def_id::DefId,
|
||||
rustc_middle::ty::subst::SubstsRef<$tcx>
|
||||
)>,
|
||||
[few, decode] mir_keys: rustc_hir::def_id::DefIdSet,
|
||||
[few, decode] collect_and_partition_mono_items: rustc_hir::def_id::DefIdSet,
|
||||
[few, decode] mir_keys: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
|
||||
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
|
||||
[] region_scope_tree: rustc_middle::middle::region::ScopeTree,
|
||||
[] item_local_set: rustc_hir::ItemLocalSet,
|
||||
|
@ -156,7 +156,7 @@ rustc_queries! {
|
||||
/// Set of all the `DefId`s in this crate that have MIR associated with
|
||||
/// them. This includes all the body owners, but also things like struct
|
||||
/// constructors.
|
||||
query mir_keys(_: CrateNum) -> &'tcx DefIdSet {
|
||||
query mir_keys(_: CrateNum) -> &'tcx FxHashSet<LocalDefId> {
|
||||
desc { "getting a list of all mir_keys" }
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
use crate::{shim, util};
|
||||
use required_consts::RequiredConstsVisitor;
|
||||
use rustc_ast::ast;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::visit::Visitor as _;
|
||||
@ -54,24 +55,24 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
|
||||
}
|
||||
|
||||
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
tcx.mir_keys(def_id.krate).contains(&def_id)
|
||||
tcx.mir_keys(def_id.krate).contains(&def_id.expect_local())
|
||||
}
|
||||
|
||||
/// Finds the full set of `DefId`s within the current crate that have
|
||||
/// MIR associated with them.
|
||||
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
|
||||
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &FxHashSet<LocalDefId> {
|
||||
assert_eq!(krate, LOCAL_CRATE);
|
||||
|
||||
let mut set = DefIdSet::default();
|
||||
let mut set = FxHashSet::default();
|
||||
|
||||
// All body-owners have MIR associated with them.
|
||||
set.extend(tcx.body_owners().map(LocalDefId::to_def_id));
|
||||
set.extend(tcx.body_owners());
|
||||
|
||||
// Additionally, tuple struct/variant constructors have MIR, but
|
||||
// they don't have a BodyId, so we need to build them separately.
|
||||
struct GatherCtors<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
set: &'a mut DefIdSet,
|
||||
set: &'a mut FxHashSet<LocalDefId>,
|
||||
}
|
||||
impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> {
|
||||
fn visit_variant_data(
|
||||
@ -83,7 +84,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
|
||||
_: Span,
|
||||
) {
|
||||
if let hir::VariantData::Tuple(_, hir_id) = *v {
|
||||
self.set.insert(self.tcx.hir().local_def_id(hir_id).to_def_id());
|
||||
self.set.insert(self.tcx.hir().local_def_id(hir_id));
|
||||
}
|
||||
intravisit::walk_struct_def(self, v)
|
||||
}
|
||||
|
@ -868,5 +868,9 @@ fn write_user_type_annotations(body: &Body<'_>, w: &mut dyn Write) -> io::Result
|
||||
}
|
||||
|
||||
pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
|
||||
if let Some(i) = single { vec![i] } else { tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect() }
|
||||
if let Some(i) = single {
|
||||
vec![i]
|
||||
} else {
|
||||
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user