Move get_lib_features query in librustc_passes.
This commit is contained in:
parent
ec3a9f64f1
commit
57681628f9
@ -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<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;
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user