Move weak_lang_items checking to librustc_passes.
This commit is contained in:
parent
98b46f7796
commit
b6f875d678
4 changed files with 40 additions and 33 deletions
32
src/librustc/middle/weak_lang_items.rs
Normal file
32
src/librustc/middle/weak_lang_items.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
//! Validity checking for weak lang items
|
||||
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_lang_items::{lang_items, LangItem};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
|
||||
pub use rustc_lang_items::weak_lang_items::link_name;
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
|
||||
self.lang_items().is_weak_lang_item(item_def_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the specified `lang_item` doesn't actually need to be
|
||||
/// present for this compilation.
|
||||
///
|
||||
/// Not all lang items are always required for each compilation, particularly in
|
||||
/// the case of panic=abort. In these situations some lang items are injected by
|
||||
/// crates and don't actually need to be defined in libstd.
|
||||
pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool {
|
||||
// If we're not compiling with unwinding, we won't actually need these
|
||||
// symbols. Other panic runtimes ensure that the relevant symbols are
|
||||
// available to link things together, but they're never exercised.
|
||||
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
|
||||
return lang_item == lang_items::EhPersonalityLangItem
|
||||
|| lang_item == lang_items::EhUnwindResumeLangItem;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
|
@ -7,8 +7,9 @@
|
|||
//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.
|
||||
//! * Functions called by the compiler itself.
|
||||
|
||||
use crate::weak_lang_items;
|
||||
|
||||
use rustc::middle::cstore::ExternCrate;
|
||||
use rustc::middle::weak_lang_items;
|
||||
use rustc::ty::TyCtxt;
|
||||
|
||||
use rustc_errors::struct_span_err;
|
||||
|
|
|
@ -32,6 +32,7 @@ mod reachable;
|
|||
mod region;
|
||||
pub mod stability;
|
||||
mod upvars;
|
||||
mod weak_lang_items;
|
||||
|
||||
pub fn provide(providers: &mut Providers<'_>) {
|
||||
check_attr::provide(providers);
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
//! Validity checking for weak lang items
|
||||
|
||||
use crate::middle::lang_items;
|
||||
use crate::session::config;
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::middle::weak_lang_items::whitelisted;
|
||||
use rustc::session::config;
|
||||
|
||||
use crate::hir::map::Map;
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc::hir::map::Map;
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_lang_items::weak_lang_items::WEAK_ITEMS_REFS;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
|
||||
pub use rustc_lang_items::weak_lang_items::link_name;
|
||||
|
||||
struct Context<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
@ -42,24 +39,6 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
|
|||
verify(tcx, items);
|
||||
}
|
||||
|
||||
/// Returns `true` if the specified `lang_item` doesn't actually need to be
|
||||
/// present for this compilation.
|
||||
///
|
||||
/// Not all lang items are always required for each compilation, particularly in
|
||||
/// the case of panic=abort. In these situations some lang items are injected by
|
||||
/// crates and don't actually need to be defined in libstd.
|
||||
pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: lang_items::LangItem) -> bool {
|
||||
// If we're not compiling with unwinding, we won't actually need these
|
||||
// symbols. Other panic runtimes ensure that the relevant symbols are
|
||||
// available to link things together, but they're never exercised.
|
||||
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
|
||||
return lang_item == lang_items::EhPersonalityLangItem
|
||||
|| lang_item == lang_items::EhUnwindResumeLangItem;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
|
||||
// We only need to check for the presence of weak lang items if we're
|
||||
// emitting something that's not an rlib.
|
||||
|
@ -122,9 +101,3 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
|||
intravisit::walk_foreign_item(self, i)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
|
||||
self.lang_items().is_weak_lang_item(item_def_id)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue