Skip to content

Commit

Permalink
Rollup merge of rust-lang#67698 - cjgillot:passes-first, r=Zoxc
Browse files Browse the repository at this point in the history
Move reachable_set and diagnostic_items to librustc_passes.

Split out of rust-lang#67688

r? @Zoxc
  • Loading branch information
JohnTitor authored Dec 30, 2019
2 parents 3928ace + f5c63e7 commit 88e322c
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 95 deletions.
19 changes: 1 addition & 18 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,7 @@ pub mod hir;
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;
Expand Down
35 changes: 35 additions & 0 deletions src/librustc/middle/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ rustc_queries! {
}

Other {
query reachable_set(_: CrateNum) -> ReachableSet {
query reachable_set(_: CrateNum) -> Lrc<HirIdSet> {
desc { "reachability" }
}

Expand Down
12 changes: 0 additions & 12 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
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};
Expand All @@ -37,7 +36,7 @@ use crate::ty::subst::SubstsRef;
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;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand All @@ -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 changes: 6 additions & 0 deletions src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ use rustc::ty::query::Providers;
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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)> {
Expand Down Expand Up @@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
}
}

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 {
Expand All @@ -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))
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -378,12 +377,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
}
}

// 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);
Expand Down Expand Up @@ -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<'_>) {
Expand Down

0 comments on commit 88e322c

Please sign in to comment.