Move get_lib_features query in librustc_passes.
This commit is contained in:
parent
ec3a9f64f1
commit
57681628f9
4 changed files with 42 additions and 33 deletions
|
@ -102,7 +102,30 @@ pub mod middle {
|
||||||
pub mod exported_symbols;
|
pub mod exported_symbols;
|
||||||
pub mod free_region;
|
pub mod free_region;
|
||||||
pub mod lang_items;
|
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 privacy;
|
||||||
pub mod recursion_limit;
|
pub mod recursion_limit;
|
||||||
pub mod region;
|
pub mod region;
|
||||||
|
|
|
@ -2751,10 +2751,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
||||||
assert_eq!(id, LOCAL_CRATE);
|
assert_eq!(id, LOCAL_CRATE);
|
||||||
tcx.crate_name
|
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| {
|
providers.get_lang_items = |tcx, id| {
|
||||||
assert_eq!(id, LOCAL_CRATE);
|
assert_eq!(id, LOCAL_CRATE);
|
||||||
tcx.arena.alloc(middle::lang_items::collect(tcx))
|
tcx.arena.alloc(middle::lang_items::collect(tcx))
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub mod entry;
|
||||||
pub mod hir_stats;
|
pub mod hir_stats;
|
||||||
mod intrinsicck;
|
mod intrinsicck;
|
||||||
pub mod layout_test;
|
pub mod layout_test;
|
||||||
|
mod lib_features;
|
||||||
mod liveness;
|
mod liveness;
|
||||||
pub mod loops;
|
pub mod loops;
|
||||||
mod reachable;
|
mod reachable;
|
||||||
|
@ -35,6 +36,7 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||||
check_const::provide(providers);
|
check_const::provide(providers);
|
||||||
diagnostic_items::provide(providers);
|
diagnostic_items::provide(providers);
|
||||||
entry::provide(providers);
|
entry::provide(providers);
|
||||||
|
lib_features::provide(providers);
|
||||||
loops::provide(providers);
|
loops::provide(providers);
|
||||||
liveness::provide(providers);
|
liveness::provide(providers);
|
||||||
intrinsicck::provide(providers);
|
intrinsicck::provide(providers);
|
||||||
|
|
|
@ -4,38 +4,19 @@
|
||||||
// and `#[unstable (..)]`), but are not declared in one single location
|
// and `#[unstable (..)]`), but are not declared in one single location
|
||||||
// (unlike lang features), which means we need to collect them instead.
|
// (unlike lang features), which means we need to collect them instead.
|
||||||
|
|
||||||
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
use rustc::hir::def_id::LOCAL_CRATE;
|
||||||
use crate::ty::TyCtxt;
|
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc::middle::lib_features::LibFeatures;
|
||||||
use rustc_macros::HashStable;
|
use rustc::ty::query::Providers;
|
||||||
|
use rustc::ty::TyCtxt;
|
||||||
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
|
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax_pos::{sym, Span};
|
use syntax_pos::{sym, Span};
|
||||||
|
|
||||||
use rustc_error_codes::*;
|
use rustc_error_codes::*;
|
||||||
|
|
||||||
#[derive(HashStable)]
|
fn new_lib_features() -> LibFeatures {
|
||||||
pub struct LibFeatures {
|
LibFeatures { stable: Default::default(), unstable: Default::default() }
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LibFeatureCollector<'tcx> {
|
pub struct LibFeatureCollector<'tcx> {
|
||||||
|
@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
|
||||||
|
|
||||||
impl LibFeatureCollector<'tcx> {
|
impl LibFeatureCollector<'tcx> {
|
||||||
fn new(tcx: TyCtxt<'tcx>) -> 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)> {
|
fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
|
||||||
|
@ -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 mut collector = LibFeatureCollector::new(tcx);
|
||||||
let krate = tcx.hir().krate();
|
let krate = tcx.hir().krate();
|
||||||
for attr in krate.non_exported_macro_attrs {
|
for attr in krate.non_exported_macro_attrs {
|
||||||
|
@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
|
||||||
intravisit::walk_crate(&mut collector, krate);
|
intravisit::walk_crate(&mut collector, krate);
|
||||||
collector.lib_features
|
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…
Add table
Add a link
Reference in a new issue