Rollup merge of #67698 - cjgillot:passes-first, r=Zoxc

Move reachable_set and diagnostic_items to librustc_passes.

Split out of #67688

r? @Zoxc
This commit is contained in:
Yuki Okushi
2019-12-30 14:07:55 +09:00
committed by GitHub
11 changed files with 97 additions and 95 deletions
+1 -18
View File
@@ -95,24 +95,7 @@
pub mod ich;
pub mod infer;
pub mod lint;
pub mod middle {
pub mod cstore;
pub mod dependency_format;
pub mod diagnostic_items;
pub mod exported_symbols;
pub mod free_region;
pub mod lang_items;
pub mod lib_features;
pub mod privacy;
pub mod reachable;
pub mod recursion_limit;
pub mod region;
pub mod resolve_lifetime;
pub mod stability;
pub mod weak_lang_items;
}
pub mod middle;
pub mod mir;
pub use rustc_session as session;
pub mod traits;
+35
View File
@@ -0,0 +1,35 @@
pub mod cstore;
pub mod dependency_format;
pub mod exported_symbols;
pub mod free_region;
pub mod lang_items;
pub mod lib_features {
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::symbol::Symbol;
#[derive(HashStable)]
pub struct LibFeatures {
// A map from feature to stabilisation version.
pub stable: FxHashMap<Symbol, Symbol>,
pub unstable: FxHashSet<Symbol>,
}
impl LibFeatures {
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
let mut all_features: Vec<_> = self
.stable
.iter()
.map(|(f, s)| (*f, Some(*s)))
.chain(self.unstable.iter().map(|f| (*f, None)))
.collect();
all_features.sort_unstable_by_key(|f| f.0.as_str());
all_features
}
}
}
pub mod privacy;
pub mod recursion_limit;
pub mod region;
pub mod resolve_lifetime;
pub mod stability;
pub mod weak_lang_items;
+1 -1
View File
@@ -510,7 +510,7 @@
}
Other {
query reachable_set(_: CrateNum) -> ReachableSet {
query reachable_set(_: CrateNum) -> Lrc<HirIdSet> {
desc { "reachability" }
}
-12
View File
@@ -2751,22 +2751,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(id, LOCAL_CRATE);
tcx.crate_name
};
providers.get_lib_features = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.arena.alloc(middle::lib_features::collect(tcx))
};
providers.get_lang_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.arena.alloc(middle::lang_items::collect(tcx))
};
providers.diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
middle::diagnostic_items::collect(tcx)
};
providers.all_diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
middle::diagnostic_items::collect_all(tcx)
};
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
+1 -2
View File
@@ -10,7 +10,6 @@
use crate::middle::lang_items::{LangItem, LanguageItems};
use crate::middle::lib_features::LibFeatures;
use crate::middle::privacy::AccessLevels;
use crate::middle::reachable::ReachableSet;
use crate::middle::region;
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
use crate::middle::stability::{self, DeprecationEntry};
@@ -37,7 +36,7 @@
use crate::ty::util::NeedsDrop;
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
use crate::util::common::ErrorReported;
use crate::util::nodemap::{DefIdMap, DefIdSet};
use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdSet};
use rustc_data_structures::profiling::ProfileCategory::*;
use rustc_data_structures::fingerprint::Fingerprint;
@@ -65,7 +65,6 @@ fn reachable_non_generics_provider(
let mut reachable_non_generics: DefIdMap<_> = tcx
.reachable_set(LOCAL_CRATE)
.0
.iter()
.filter_map(|&hir_id| {
// We want to ignore some FFI functions that are not exposed from
@@ -313,7 +312,7 @@ fn upstream_monomorphizations_for_provider(
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
!tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id)
!tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
} else {
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
}
+1 -3
View File
@@ -10,7 +10,7 @@
use rustc::hir::lowering::lower_crate;
use rustc::lint;
use rustc::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn};
use rustc::middle::{self, reachable, resolve_lifetime, stability};
use rustc::middle::{self, resolve_lifetime, stability};
use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType};
use rustc::session::config::{PpMode, PpSourceMode};
use rustc::session::search_paths::PathKind;
@@ -678,14 +678,12 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
plugin::build::provide(providers);
hir::provide(providers);
mir::provide(providers);
reachable::provide(providers);
resolve_lifetime::provide(providers);
rustc_privacy::provide(providers);
typeck::provide(providers);
ty::provide(providers);
traits::provide(providers);
stability::provide(providers);
reachable::provide(providers);
rustc_passes::provide(providers);
rustc_traits::provide(providers);
middle::region::provide(providers);
@@ -9,12 +9,13 @@
//!
//! * Compiler internal types like `Ty` and `TyCtxt`
use crate::hir::def_id::{DefId, LOCAL_CRATE};
use crate::ty::TyCtxt;
use crate::util::nodemap::FxHashMap;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc::util::nodemap::FxHashMap;
use crate::hir;
use crate::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use syntax::ast;
use syntax::symbol::{sym, Symbol};
@@ -93,7 +94,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
}
/// Traverse and collect the diagnostic items in the current
pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
// Initialize the collector.
let mut collector = DiagnosticItemCollector::new(tcx);
@@ -104,7 +105,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
}
/// Traverse and collect all the diagnostic items in all crates.
pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
// Initialize the collector.
let mut collector = FxHashMap::default();
@@ -117,3 +118,14 @@ pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
tcx.arena.alloc(collector)
}
pub fn provide(providers: &mut Providers<'_>) {
providers.diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
collect(tcx)
};
providers.all_diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
collect_all(tcx)
};
}
+6
View File
@@ -22,17 +22,23 @@
pub mod ast_validation;
mod check_const;
pub mod dead;
mod diagnostic_items;
pub mod entry;
pub mod hir_stats;
mod intrinsicck;
pub mod layout_test;
mod lib_features;
mod liveness;
pub mod loops;
mod reachable;
pub fn provide(providers: &mut Providers<'_>) {
check_const::provide(providers);
diagnostic_items::provide(providers);
entry::provide(providers);
lib_features::provide(providers);
loops::provide(providers);
liveness::provide(providers);
intrinsicck::provide(providers);
reachable::provide(providers);
}
@@ -4,38 +4,19 @@
// and `#[unstable (..)]`), but are not declared in one single location
// (unlike lang features), which means we need to collect them instead.
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
use crate::ty::TyCtxt;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_macros::HashStable;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::middle::lib_features::LibFeatures;
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
use syntax::symbol::Symbol;
use syntax_pos::{sym, Span};
use rustc_error_codes::*;
#[derive(HashStable)]
pub struct LibFeatures {
// A map from feature to stabilisation version.
pub stable: FxHashMap<Symbol, Symbol>,
pub unstable: FxHashSet<Symbol>,
}
impl LibFeatures {
fn new() -> LibFeatures {
LibFeatures { stable: Default::default(), unstable: Default::default() }
}
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
let mut all_features: Vec<_> = self
.stable
.iter()
.map(|(f, s)| (*f, Some(*s)))
.chain(self.unstable.iter().map(|f| (*f, None)))
.collect();
all_features.sort_unstable_by_key(|f| f.0.as_str());
all_features
}
fn new_lib_features() -> LibFeatures {
LibFeatures { stable: Default::default(), unstable: Default::default() }
}
pub struct LibFeatureCollector<'tcx> {
@@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
impl LibFeatureCollector<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> {
LibFeatureCollector { tcx, lib_features: LibFeatures::new() }
LibFeatureCollector { tcx, lib_features: new_lib_features() }
}
fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
@@ -142,7 +123,7 @@ fn visit_attribute(&mut self, attr: &'tcx Attribute) {
}
}
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
let mut collector = LibFeatureCollector::new(tcx);
let krate = tcx.hir().krate();
for attr in krate.non_exported_macro_attrs {
@@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
intravisit::walk_crate(&mut collector, krate);
collector.lib_features
}
pub fn provide(providers: &mut Providers<'_>) {
providers.get_lib_features = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.arena.alloc(collect(tcx))
};
}
@@ -5,23 +5,22 @@
// makes all other generics or inline functions that it references
// reachable as well.
use crate::hir::def::{DefKind, Res};
use crate::hir::def_id::{CrateNum, DefId};
use crate::hir::Node;
use crate::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
use crate::middle::privacy;
use crate::session::config;
use crate::ty::query::Providers;
use crate::ty::{self, TyCtxt};
use crate::util::nodemap::{FxHashSet, HirIdSet};
use rustc::hir::def::{DefKind, Res};
use rustc::hir::def_id::{CrateNum, DefId};
use rustc::hir::Node;
use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc::middle::privacy;
use rustc::session::config;
use rustc::ty::query::Providers;
use rustc::ty::{self, TyCtxt};
use rustc::util::nodemap::{FxHashSet, HirIdSet};
use rustc_data_structures::sync::Lrc;
use crate::hir;
use crate::hir::def_id::LOCAL_CRATE;
use crate::hir::intravisit;
use crate::hir::intravisit::{NestedVisitorMap, Visitor};
use crate::hir::itemlikevisit::ItemLikeVisitor;
use rustc_macros::HashStable;
use rustc::hir;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::hir::intravisit;
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc_target::spec::abi::Abi;
// Returns true if the given item must be inlined because it may be
@@ -378,12 +377,7 @@ fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
}
}
// We introduce a new-type here, so we can have a specialized HashStable
// implementation for it.
#[derive(Clone, HashStable)]
pub struct ReachableSet(pub Lrc<HirIdSet>);
fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet {
fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Lrc<HirIdSet> {
debug_assert!(crate_num == LOCAL_CRATE);
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
@@ -429,7 +423,7 @@ fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet {
debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols);
// Return the set of reachable symbols.
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
Lrc::new(reachable_context.reachable_symbols)
}
pub fn provide(providers: &mut Providers<'_>) {