Use () for entry_fn.
This commit is contained in:
parent
601453a2ac
commit
829a9d33a9
@ -15,7 +15,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
unwind_context: &mut UnwindContext,
|
||||
is_jit: bool,
|
||||
) {
|
||||
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
|
||||
let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
|
||||
Some((def_id, entry_ty)) => (
|
||||
def_id,
|
||||
match entry_ty {
|
||||
|
@ -23,7 +23,7 @@
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::layout::HasTyCtxt;
|
||||
@ -343,7 +343,7 @@ fn dbg_scope_fn(
|
||||
if self.sess().opts.optimize != config::OptLevel::No {
|
||||
spflags |= DISPFlags::SPFlagOptimized;
|
||||
}
|
||||
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
|
||||
if let Some((id, _)) = self.tcx.entry_fn(()) {
|
||||
if id == def_id {
|
||||
spflags |= DISPFlags::SPFlagMainSubprogram;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ fn exported_symbols_provider_local(
|
||||
.map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level))
|
||||
.collect();
|
||||
|
||||
if tcx.entry_fn(LOCAL_CRATE).is_some() {
|
||||
if tcx.entry_fn(()).is_some() {
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
|
||||
|
||||
symbols.push((exported_symbol, SymbolExportLevel::C));
|
||||
|
@ -347,7 +347,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
cx: &'a Bx::CodegenCx,
|
||||
) -> Option<Bx::Function> {
|
||||
let main_def_id = cx.tcx().entry_fn(LOCAL_CRATE).map(|(def_id, _)| def_id)?;
|
||||
let (main_def_id, entry_type) = cx.tcx().entry_fn(())?;
|
||||
let main_is_local = main_def_id.is_local();
|
||||
let instance = Instance::mono(cx.tcx(), main_def_id);
|
||||
|
||||
@ -364,10 +364,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
|
||||
let main_llfn = cx.get_fn_addr(instance);
|
||||
|
||||
return cx.tcx().entry_fn(LOCAL_CRATE).map(|(_, et)| {
|
||||
let use_start_lang_item = EntryFnType::Start != et;
|
||||
create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item)
|
||||
});
|
||||
let use_start_lang_item = EntryFnType::Start != entry_type;
|
||||
let entry_fn = create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item);
|
||||
return Some(entry_fn);
|
||||
|
||||
fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
cx: &'a Bx::CodegenCx,
|
||||
|
@ -820,8 +820,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||
sess.time("misc_checking_1", || {
|
||||
parallel!(
|
||||
{
|
||||
entry_point = sess
|
||||
.time("looking_for_entry_point", || rustc_passes::entry::find_entry_point(tcx));
|
||||
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
|
||||
|
||||
sess.time("looking_for_plugin_registrar", || {
|
||||
plugin::build::find_plugin_registrar(tcx)
|
||||
|
@ -302,7 +302,7 @@ pub fn ongoing_codegen(&'tcx self) -> Result<&Query<Box<dyn Any>>> {
|
||||
/// to write UI tests that actually test that compilation succeeds without reporting
|
||||
/// an error.
|
||||
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
|
||||
let def_id = match tcx.entry_fn(LOCAL_CRATE) {
|
||||
let def_id = match tcx.entry_fn(()) {
|
||||
Some((def_id, _)) => def_id,
|
||||
_ => return,
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
|
||||
|
||||
match *self {
|
||||
MonoItem::Fn(ref instance) => {
|
||||
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
|
||||
let entry_def_id = tcx.entry_fn(()).map(|(id, _)| id);
|
||||
// If this function isn't inlined or otherwise has an extern
|
||||
// indicator, then we'll be creating a globally shared version.
|
||||
if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
|
||||
|
@ -1201,7 +1201,7 @@
|
||||
|
||||
/// 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(_: ()) -> Option<(DefId, EntryFnType)> {
|
||||
desc { "looking up the entry function of a crate" }
|
||||
}
|
||||
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
|
||||
|
@ -322,7 +322,7 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
|
||||
let mut roots = Vec::new();
|
||||
|
||||
{
|
||||
let entry_fn = tcx.entry_fn(LOCAL_CRATE);
|
||||
let entry_fn = tcx.entry_fn(());
|
||||
|
||||
debug!("collect_roots: entry_fn = {:?}", entry_fn);
|
||||
|
||||
|
@ -472,7 +472,7 @@ fn create_and_seed_worklist<'tcx>(
|
||||
)
|
||||
.chain(
|
||||
// Seed entry point
|
||||
tcx.entry_fn(LOCAL_CRATE).and_then(|(def_id, _)| {
|
||||
tcx.entry_fn(()).and_then(|(def_id, _)| {
|
||||
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
|
||||
}),
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
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::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem, CRATE_HIR_ID};
|
||||
use rustc_middle::hir::map::Map;
|
||||
@ -48,9 +48,7 @@ fn visit_foreign_item(&mut self, _: &'tcx ForeignItem<'tcx>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
|
||||
let any_exe = tcx.sess.crate_types().iter().any(|ty| *ty == CrateType::Executable);
|
||||
if !any_exe {
|
||||
// No need to find a main function.
|
||||
@ -227,10 +225,6 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||
err.emit();
|
||||
}
|
||||
|
||||
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> {
|
||||
tcx.entry_fn(LOCAL_CRATE)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { entry_fn, ..*providers };
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
||||
}
|
||||
|
||||
fn check_for_entry_fn(tcx: TyCtxt<'_>) {
|
||||
match tcx.entry_fn(LOCAL_CRATE) {
|
||||
match tcx.entry_fn(()) {
|
||||
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
|
||||
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
|
||||
_ => {}
|
||||
|
@ -60,7 +60,7 @@
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::LangItem::{ResultErr, ResultOk};
|
||||
use rustc_hir::{
|
||||
@ -677,7 +677,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
|
||||
/// Returns `true` if the provided `def_id` is an entrypoint to a program.
|
||||
pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
|
||||
cx.tcx
|
||||
.entry_fn(LOCAL_CRATE)
|
||||
.entry_fn(())
|
||||
.map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user