Skip to content

Commit 88e322c

Browse files
authored
Rollup merge of rust-lang#67698 - cjgillot:passes-first, r=Zoxc
Move reachable_set and diagnostic_items to librustc_passes. Split out of rust-lang#67688 r? @Zoxc
2 parents 3928ace + f5c63e7 commit 88e322c

File tree

11 files changed

+97
-95
lines changed

11 files changed

+97
-95
lines changed

src/librustc/lib.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,7 @@ pub mod hir;
9595
pub mod ich;
9696
pub mod infer;
9797
pub mod lint;
98-
99-
pub mod middle {
100-
pub mod cstore;
101-
pub mod dependency_format;
102-
pub mod diagnostic_items;
103-
pub mod exported_symbols;
104-
pub mod free_region;
105-
pub mod lang_items;
106-
pub mod lib_features;
107-
pub mod privacy;
108-
pub mod reachable;
109-
pub mod recursion_limit;
110-
pub mod region;
111-
pub mod resolve_lifetime;
112-
pub mod stability;
113-
pub mod weak_lang_items;
114-
}
115-
98+
pub mod middle;
11699
pub mod mir;
117100
pub use rustc_session as session;
118101
pub mod traits;

src/librustc/middle/mod.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pub mod cstore;
2+
pub mod dependency_format;
3+
pub mod exported_symbols;
4+
pub mod free_region;
5+
pub mod lang_items;
6+
pub mod lib_features {
7+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use syntax::symbol::Symbol;
9+
10+
#[derive(HashStable)]
11+
pub struct LibFeatures {
12+
// A map from feature to stabilisation version.
13+
pub stable: FxHashMap<Symbol, Symbol>,
14+
pub unstable: FxHashSet<Symbol>,
15+
}
16+
17+
impl LibFeatures {
18+
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
19+
let mut all_features: Vec<_> = self
20+
.stable
21+
.iter()
22+
.map(|(f, s)| (*f, Some(*s)))
23+
.chain(self.unstable.iter().map(|f| (*f, None)))
24+
.collect();
25+
all_features.sort_unstable_by_key(|f| f.0.as_str());
26+
all_features
27+
}
28+
}
29+
}
30+
pub mod privacy;
31+
pub mod recursion_limit;
32+
pub mod region;
33+
pub mod resolve_lifetime;
34+
pub mod stability;
35+
pub mod weak_lang_items;

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ rustc_queries! {
510510
}
511511

512512
Other {
513-
query reachable_set(_: CrateNum) -> ReachableSet {
513+
query reachable_set(_: CrateNum) -> Lrc<HirIdSet> {
514514
desc { "reachability" }
515515
}
516516

src/librustc/ty/context.rs

-12
Original file line numberDiff line numberDiff line change
@@ -2751,22 +2751,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
27512751
assert_eq!(id, LOCAL_CRATE);
27522752
tcx.crate_name
27532753
};
2754-
providers.get_lib_features = |tcx, id| {
2755-
assert_eq!(id, LOCAL_CRATE);
2756-
tcx.arena.alloc(middle::lib_features::collect(tcx))
2757-
};
27582754
providers.get_lang_items = |tcx, id| {
27592755
assert_eq!(id, LOCAL_CRATE);
27602756
tcx.arena.alloc(middle::lang_items::collect(tcx))
27612757
};
2762-
providers.diagnostic_items = |tcx, id| {
2763-
assert_eq!(id, LOCAL_CRATE);
2764-
middle::diagnostic_items::collect(tcx)
2765-
};
2766-
providers.all_diagnostic_items = |tcx, id| {
2767-
assert_eq!(id, LOCAL_CRATE);
2768-
middle::diagnostic_items::collect_all(tcx)
2769-
};
27702758
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
27712759
providers.maybe_unused_extern_crates = |tcx, cnum| {
27722760
assert_eq!(cnum, LOCAL_CRATE);

src/librustc/ty/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
1010
use crate::middle::lang_items::{LangItem, LanguageItems};
1111
use crate::middle::lib_features::LibFeatures;
1212
use crate::middle::privacy::AccessLevels;
13-
use crate::middle::reachable::ReachableSet;
1413
use crate::middle::region;
1514
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
1615
use crate::middle::stability::{self, DeprecationEntry};
@@ -37,7 +36,7 @@ use crate::ty::subst::SubstsRef;
3736
use crate::ty::util::NeedsDrop;
3837
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
3938
use crate::util::common::ErrorReported;
40-
use crate::util::nodemap::{DefIdMap, DefIdSet};
39+
use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdSet};
4140
use rustc_data_structures::profiling::ProfileCategory::*;
4241

4342
use rustc_data_structures::fingerprint::Fingerprint;

src/librustc_codegen_ssa/back/symbol_export.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ fn reachable_non_generics_provider(
6565

6666
let mut reachable_non_generics: DefIdMap<_> = tcx
6767
.reachable_set(LOCAL_CRATE)
68-
.0
6968
.iter()
7069
.filter_map(|&hir_id| {
7170
// We want to ignore some FFI functions that are not exposed from
@@ -313,7 +312,7 @@ fn upstream_monomorphizations_for_provider(
313312

314313
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
315314
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
316-
!tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id)
315+
!tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
317316
} else {
318317
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
319318
}

src/librustc_interface/passes.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
1010
use rustc::hir::lowering::lower_crate;
1111
use rustc::lint;
1212
use rustc::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn};
13-
use rustc::middle::{self, reachable, resolve_lifetime, stability};
13+
use rustc::middle::{self, resolve_lifetime, stability};
1414
use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType};
1515
use rustc::session::config::{PpMode, PpSourceMode};
1616
use rustc::session::search_paths::PathKind;
@@ -678,14 +678,12 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
678678
plugin::build::provide(providers);
679679
hir::provide(providers);
680680
mir::provide(providers);
681-
reachable::provide(providers);
682681
resolve_lifetime::provide(providers);
683682
rustc_privacy::provide(providers);
684683
typeck::provide(providers);
685684
ty::provide(providers);
686685
traits::provide(providers);
687686
stability::provide(providers);
688-
reachable::provide(providers);
689687
rustc_passes::provide(providers);
690688
rustc_traits::provide(providers);
691689
middle::region::provide(providers);

src/librustc/middle/diagnostic_items.rs renamed to src/librustc_passes/diagnostic_items.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
//!
1010
//! * Compiler internal types like `Ty` and `TyCtxt`
1111
12-
use crate::hir::def_id::{DefId, LOCAL_CRATE};
13-
use crate::ty::TyCtxt;
14-
use crate::util::nodemap::FxHashMap;
12+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
13+
use rustc::ty::query::Providers;
14+
use rustc::ty::TyCtxt;
15+
use rustc::util::nodemap::FxHashMap;
1516

16-
use crate::hir;
17-
use crate::hir::itemlikevisit::ItemLikeVisitor;
17+
use rustc::hir;
18+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1819
use syntax::ast;
1920
use syntax::symbol::{sym, Symbol};
2021

@@ -93,7 +94,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
9394
}
9495

9596
/// Traverse and collect the diagnostic items in the current
96-
pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
97+
fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
9798
// Initialize the collector.
9899
let mut collector = DiagnosticItemCollector::new(tcx);
99100

@@ -104,7 +105,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
104105
}
105106

106107
/// Traverse and collect all the diagnostic items in all crates.
107-
pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
108+
fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
108109
// Initialize the collector.
109110
let mut collector = FxHashMap::default();
110111

@@ -117,3 +118,14 @@ pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
117118

118119
tcx.arena.alloc(collector)
119120
}
121+
122+
pub fn provide(providers: &mut Providers<'_>) {
123+
providers.diagnostic_items = |tcx, id| {
124+
assert_eq!(id, LOCAL_CRATE);
125+
collect(tcx)
126+
};
127+
providers.all_diagnostic_items = |tcx, id| {
128+
assert_eq!(id, LOCAL_CRATE);
129+
collect_all(tcx)
130+
};
131+
}

src/librustc_passes/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@ use rustc::ty::query::Providers;
2222
pub mod ast_validation;
2323
mod check_const;
2424
pub mod dead;
25+
mod diagnostic_items;
2526
pub mod entry;
2627
pub mod hir_stats;
2728
mod intrinsicck;
2829
pub mod layout_test;
30+
mod lib_features;
2931
mod liveness;
3032
pub mod loops;
33+
mod reachable;
3134

3235
pub fn provide(providers: &mut Providers<'_>) {
3336
check_const::provide(providers);
37+
diagnostic_items::provide(providers);
3438
entry::provide(providers);
39+
lib_features::provide(providers);
3540
loops::provide(providers);
3641
liveness::provide(providers);
3742
intrinsicck::provide(providers);
43+
reachable::provide(providers);
3844
}

src/librustc/middle/lib_features.rs renamed to src/librustc_passes/lib_features.rs

+16-28
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,19 @@
44
// and `#[unstable (..)]`), but are not declared in one single location
55
// (unlike lang features), which means we need to collect them instead.
66

7-
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
8-
use crate::ty::TyCtxt;
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10-
use rustc_macros::HashStable;
7+
use rustc::hir::def_id::LOCAL_CRATE;
8+
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
9+
use rustc::middle::lib_features::LibFeatures;
10+
use rustc::ty::query::Providers;
11+
use rustc::ty::TyCtxt;
1112
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
1213
use syntax::symbol::Symbol;
1314
use syntax_pos::{sym, Span};
1415

1516
use rustc_error_codes::*;
1617

17-
#[derive(HashStable)]
18-
pub struct LibFeatures {
19-
// A map from feature to stabilisation version.
20-
pub stable: FxHashMap<Symbol, Symbol>,
21-
pub unstable: FxHashSet<Symbol>,
22-
}
23-
24-
impl LibFeatures {
25-
fn new() -> LibFeatures {
26-
LibFeatures { stable: Default::default(), unstable: Default::default() }
27-
}
28-
29-
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
30-
let mut all_features: Vec<_> = self
31-
.stable
32-
.iter()
33-
.map(|(f, s)| (*f, Some(*s)))
34-
.chain(self.unstable.iter().map(|f| (*f, None)))
35-
.collect();
36-
all_features.sort_unstable_by_key(|f| f.0.as_str());
37-
all_features
38-
}
18+
fn new_lib_features() -> LibFeatures {
19+
LibFeatures { stable: Default::default(), unstable: Default::default() }
3920
}
4021

4122
pub struct LibFeatureCollector<'tcx> {
@@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
4526

4627
impl LibFeatureCollector<'tcx> {
4728
fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> {
48-
LibFeatureCollector { tcx, lib_features: LibFeatures::new() }
29+
LibFeatureCollector { tcx, lib_features: new_lib_features() }
4930
}
5031

5132
fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
@@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
142123
}
143124
}
144125

145-
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
126+
fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
146127
let mut collector = LibFeatureCollector::new(tcx);
147128
let krate = tcx.hir().krate();
148129
for attr in krate.non_exported_macro_attrs {
@@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
151132
intravisit::walk_crate(&mut collector, krate);
152133
collector.lib_features
153134
}
135+
136+
pub fn provide(providers: &mut Providers<'_>) {
137+
providers.get_lib_features = |tcx, id| {
138+
assert_eq!(id, LOCAL_CRATE);
139+
tcx.arena.alloc(collect(tcx))
140+
};
141+
}

src/librustc/middle/reachable.rs renamed to src/librustc_passes/reachable.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
// makes all other generics or inline functions that it references
66
// reachable as well.
77

8-
use crate::hir::def::{DefKind, Res};
9-
use crate::hir::def_id::{CrateNum, DefId};
10-
use crate::hir::Node;
11-
use crate::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
12-
use crate::middle::privacy;
13-
use crate::session::config;
14-
use crate::ty::query::Providers;
15-
use crate::ty::{self, TyCtxt};
16-
use crate::util::nodemap::{FxHashSet, HirIdSet};
8+
use rustc::hir::def::{DefKind, Res};
9+
use rustc::hir::def_id::{CrateNum, DefId};
10+
use rustc::hir::Node;
11+
use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
12+
use rustc::middle::privacy;
13+
use rustc::session::config;
14+
use rustc::ty::query::Providers;
15+
use rustc::ty::{self, TyCtxt};
16+
use rustc::util::nodemap::{FxHashSet, HirIdSet};
1717
use rustc_data_structures::sync::Lrc;
1818

19-
use crate::hir;
20-
use crate::hir::def_id::LOCAL_CRATE;
21-
use crate::hir::intravisit;
22-
use crate::hir::intravisit::{NestedVisitorMap, Visitor};
23-
use crate::hir::itemlikevisit::ItemLikeVisitor;
24-
use rustc_macros::HashStable;
19+
use rustc::hir;
20+
use rustc::hir::def_id::LOCAL_CRATE;
21+
use rustc::hir::intravisit;
22+
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
23+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2524
use rustc_target::spec::abi::Abi;
2625

2726
// Returns true if the given item must be inlined because it may be
@@ -378,12 +377,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
378377
}
379378
}
380379

381-
// We introduce a new-type here, so we can have a specialized HashStable
382-
// implementation for it.
383-
#[derive(Clone, HashStable)]
384-
pub struct ReachableSet(pub Lrc<HirIdSet>);
385-
386-
fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet {
380+
fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Lrc<HirIdSet> {
387381
debug_assert!(crate_num == LOCAL_CRATE);
388382

389383
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
@@ -429,7 +423,7 @@ fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet {
429423
debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols);
430424

431425
// Return the set of reachable symbols.
432-
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
426+
Lrc::new(reachable_context.reachable_symbols)
433427
}
434428

435429
pub fn provide(providers: &mut Providers<'_>) {

0 commit comments

Comments
 (0)