From 57681628f9138a76302d0eb41cac69c44b00f75a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Dec 2019 18:52:36 +0100 Subject: [PATCH] Move get_lib_features query in librustc_passes. --- src/librustc/lib.rs | 25 +++++++++++++++- src/librustc/ty/context.rs | 4 --- src/librustc_passes/lib.rs | 2 ++ src/librustc_passes/lib_features.rs | 44 +++++++++++------------------ 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 38dcbc8e3fb..35c20cdbaf5 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -102,7 +102,30 @@ pub mod middle { pub mod exported_symbols; pub mod free_region; pub mod lang_items; - pub mod lib_features; + 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, + pub unstable: FxHashSet, + } + + impl LibFeatures { + pub fn to_vec(&self) -> Vec<(Symbol, Option)> { + 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; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 566c814f947..69e3358d6f6 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2751,10 +2751,6 @@ 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)) diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 1ac03122c4a..da781f2bae5 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -27,6 +27,7 @@ pub mod hir_stats; mod intrinsicck; pub mod layout_test; +mod lib_features; mod liveness; pub mod loops; mod reachable; @@ -35,6 +36,7 @@ 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); diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index b4ddb09861d..0b0183f3cce 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -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, - pub unstable: FxHashSet, -} - -impl LibFeatures { - fn new() -> LibFeatures { - LibFeatures { stable: Default::default(), unstable: Default::default() } - } - - pub fn to_vec(&self) -> Vec<(Symbol, Option)> { - 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, 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)) + }; +}