Skip to content

Commit

Permalink
Rollup merge of rust-lang#71292 - marmeladema:queries-local-def-id, r…
Browse files Browse the repository at this point in the history
…=eddyb

Convert more queries to use `LocalDefId`

This PR is based on commits in rust-lang#71215 and should partially solve rust-lang#70853
  • Loading branch information
Dylan-DPC committed Apr 27, 2020
2 parents d81f559 + 90639e2 commit b893ad0
Show file tree
Hide file tree
Showing 44 changed files with 292 additions and 240 deletions.
7 changes: 5 additions & 2 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ impl<'a, 'b> Context<'a, 'b> {
.iter()
.filter(|fmt| fmt.precision_span.is_some())
.count();
e.span_label(span, &format!(
e.span_label(
span,
&format!(
"this precision flag adds an extra required argument at position {}, \
which is why there {} expected",
pos,
Expand All @@ -419,7 +421,8 @@ impl<'a, 'b> Context<'a, 'b> {
} else {
format!("are {} arguments", count)
},
));
),
);
if let Some(arg) = self.args.get(pos) {
e.span_label(
arg.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
spflags |= DISPFlags::SPFlagOptimized;
}
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
if id == def_id {
if id.to_def_id() == def_id {
spflags |= DISPFlags::SPFlagMainSubprogram;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::profiling::print_time_passes_entry;
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_hir::lang_items::StartFnLangItem;
use rustc_index::vec::Idx;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
Expand Down Expand Up @@ -397,7 +397,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
None => return None,
};

let instance = Instance::mono(cx.tcx(), main_def_id);
let instance = Instance::mono(cx.tcx(), main_def_id.to_def_id());

if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
// We want to create the wrapper in the same codegen unit as Rust's main
Expand All @@ -416,7 +416,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx,
sp: Span,
rust_main: Bx::Value,
rust_main_def_id: DefId,
rust_main_def_id: LocalDefId,
use_start_lang_item: bool,
) -> Bx::Function {
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
});

sess.time("MIR_borrow_checking", || {
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id()));
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
});

sess.time("dumping_chalk_like_clauses", || {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'tcx> Queries<'tcx> {
_ => return,
};

let attrs = &*tcx.get_attrs(def_id);
let attrs = &*tcx.get_attrs(def_id.to_def_id());
let attrs = attrs.iter().filter(|attr| attr.check_name(sym::rustc_error));
for attr in attrs {
match attr.meta_item_list() {
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod unused;

use rustc_ast::ast;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::builtin::{
Expand Down Expand Up @@ -90,12 +90,8 @@ pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers { lint_mod, ..*providers };
}

fn lint_mod(tcx: TyCtxt<'_>, module_def_id: DefId) {
late::late_lint_mod(
tcx,
module_def_id.expect_local(),
BuiltinCombinedModuleLateLintPass::new(),
);
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
late::late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
}

macro_rules! pre_expansion_lint_passes {
Expand Down
66 changes: 31 additions & 35 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_middle/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::base_n;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::HirId;
use rustc_session::config::OptLevel;
use rustc_span::source_map::Span;
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'tcx> MonoItem<'tcx> {
// linkage, then we'll be creating a globally shared version.
if self.explicit_linkage(tcx).is_some()
|| !instance.def.generates_cgu_internal_copy(tcx)
|| Some(instance.def_id()) == entry_def_id
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
{
return InstantiationMode::GloballyShared { may_conflict: false };
}
Expand Down
Loading

0 comments on commit b893ad0

Please sign in to comment.