8000 Split lang_items to crates `rustc_hir` and `rustc_passes`. by cjgillot · Pull Request #68554 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Split lang_items to crates rustc_hir and rustc_passes. #68554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 12, 2020
Prev Previous commit
Next Next commit
Merge rustc::middle::*lang_items.
  • Loading branch information
cjgillot committed Feb 11, 2020
commit 513eb744c0c2ead6b10a3a3e5f0267e4136a9b4f
24 changes: 24 additions & 0 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::ty::{self, TyCtxt};

use rustc_hir::def_id::DefId;
use rustc_span::Span;
use rustc_target::spec::PanicStrategy;

pub use rustc_hir::weak_lang_items::link_name;
pub use rustc_hir::{LangItem, LanguageItems};

impl<'tcx> TyCtxt<'tcx> {
Expand All @@ -38,4 +40,26 @@ impl<'tcx> TyCtxt<'tcx> {
_ => None,
}
}

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 == LangItem::EhPersonalityLangItem
|| lang_item == LangItem::EhUnwindResumeLangItem;
}

false
}
1 change: 0 additions & 1 deletion src/librustc/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ pub mod recursion_limit;
pub mod region;
pub mod resolve_lifetime;
pub mod stability;
pub mod weak_lang_items;
32 changes: 0 additions & 32 deletions src/librustc/middle/weak_lang_items.rs

This file was deleted.

9 changes: 3 additions & 6 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}
use rustc::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc::middle::cstore::EncodedMetadata;
use rustc::middle::cstore::{self, LinkagePreference};
use rustc::middle::lang_items;
use rustc::middle::lang_items::StartFnLangItem;
use rustc::middle::weak_lang_items;
use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
use rustc::session::config::{self, EntryFnType, Lto};
use rustc::session::Session;
Expand Down Expand Up @@ -847,11 +847,8 @@ impl CrateInfo {

// No need to look for lang items that are whitelisted and don't
// actually need to exist.
let missing = missing
.iter()
.cloned()
.filter(|&l| !weak_lang_items::whitelisted(tcx, l))
.collect();
let missing =
missing.iter().cloned().filter(|&l| !lang_items::whitelisted(tcx, l)).collect();
info.missing_lang_items.insert(cnum, missing);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/weak_lang_items.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Validity checking for weak lang items

use rustc::middle::lang_items;
use rustc::middle::weak_lang_items::whitelisted;
use rustc::middle::lang_items::whitelisted;
use rustc::session::config;

use rustc::hir::map::Map;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::astconv::{AstConv, Bounds, SizedByDefault};
use crate::check::intrinsic::intrinsic_operation_unsafety;
use crate::constrained_generic_params as cgp;
use crate::lint;
use crate::middle::lang_items;
use crate::middle::resolve_lifetime as rl;
use crate::middle::weak_lang_items;
use rustc::hir::map::blocks::FnLikeNode;
use rustc::hir::map::Map;
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
Expand Down Expand Up @@ -2977,7 +2977,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if tcx.is_weak_lang_item(id) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
}
if let Some(name) = weak_lang_items::link_name(&attrs) {
if let Some(name) = lang_items::link_name(&attrs) {
codegen_fn_attrs.export_name = Some(name);
codegen_fn_attrs.link_name = Some(name);
}
Expand Down
0