Change return type of entry_fn
query to return a LocalDefId
This commit is contained in:
parent
3877f54000
commit
c9f6ffc3b0
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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
|
||||
@ -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)`,
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
@ -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 };
|
||||
}
|
||||
|
@ -880,7 +880,7 @@ rustc_queries! {
|
||||
|
||||
/// Identifies the entry-point (e.g., the `main` function) for a given
|
||||
/// crate, returning `None` if there is no entry point (such as for library crates).
|
||||
query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> {
|
||||
query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
|
||||
desc { "looking up the entry function of a crate" }
|
||||
}
|
||||
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
|
||||
|
@ -919,7 +919,7 @@ struct RootCollector<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
mode: MonoItemCollectionMode,
|
||||
output: &'a mut Vec<MonoItem<'tcx>>,
|
||||
entry_fn: Option<(DefId, EntryFnType)>,
|
||||
entry_fn: Option<(LocalDefId, EntryFnType)>,
|
||||
}
|
||||
|
||||
impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
|
||||
@ -1008,7 +1008,7 @@ impl RootCollector<'_, 'v> {
|
||||
&& match self.mode {
|
||||
MonoItemCollectionMode::Eager => true,
|
||||
MonoItemCollectionMode::Lazy => {
|
||||
self.entry_fn.map(|(id, _)| id) == Some(def_id.to_def_id())
|
||||
self.entry_fn.map(|(id, _)| id) == Some(def_id)
|
||||
|| self.tcx.is_reachable_non_generic(def_id)
|
||||
|| self
|
||||
.tcx
|
||||
|
@ -452,8 +452,7 @@ fn create_and_seed_worklist<'tcx>(
|
||||
)
|
||||
.chain(
|
||||
// Seed entry point
|
||||
tcx.entry_fn(LOCAL_CRATE)
|
||||
.map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id.expect_local())),
|
||||
tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id)),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::entry::EntryPointType;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem};
|
||||
use rustc_middle::hir::map::Map;
|
||||
@ -48,7 +48,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> {
|
||||
fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
let any_exe =
|
||||
@ -143,13 +143,16 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(DefId, EntryFnType)> {
|
||||
fn configure_main(
|
||||
tcx: TyCtxt<'_>,
|
||||
visitor: &EntryContext<'_, '_>,
|
||||
) -> Option<(LocalDefId, EntryFnType)> {
|
||||
if let Some((hir_id, _)) = visitor.start_fn {
|
||||
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Start))
|
||||
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Start))
|
||||
} else if let Some((hir_id, _)) = visitor.attr_main_fn {
|
||||
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main))
|
||||
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
|
||||
} else if let Some((hir_id, _)) = visitor.main_fn {
|
||||
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main))
|
||||
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
|
||||
} else {
|
||||
no_main_err(tcx, visitor);
|
||||
None
|
||||
@ -211,7 +214,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||
err.emit();
|
||||
}
|
||||
|
||||
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> {
|
||||
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(LocalDefId, EntryFnType)> {
|
||||
tcx.entry_fn(LOCAL_CRATE)
|
||||
}
|
||||
|
||||
|
@ -1451,7 +1451,7 @@ fn check_fn<'a, 'tcx>(
|
||||
// Check that the main return type implements the termination trait.
|
||||
if let Some(term_id) = tcx.lang_items().termination() {
|
||||
if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) {
|
||||
let main_id = hir.as_local_hir_id(def_id.expect_local());
|
||||
let main_id = hir.as_local_hir_id(def_id);
|
||||
if main_id == fn_id {
|
||||
let substs = tcx.mk_substs_trait(declared_ret_ty, &[]);
|
||||
let trait_ref = ty::TraitRef::new(term_id, substs);
|
||||
|
@ -303,8 +303,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
|
||||
|
||||
fn check_for_entry_fn(tcx: TyCtxt<'_>) {
|
||||
match tcx.entry_fn(LOCAL_CRATE) {
|
||||
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id.expect_local()),
|
||||
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id.expect_local()),
|
||||
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
|
||||
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user