Skip to content
Permalink
Browse files

Update get_lib_features, defined_lib_features, get_lang_items, define…

…d_lang_items, missing_lang_items, postorder_cnums and maybe_unused_extern_crates
  • Loading branch information...
Zoxc committed Dec 1, 2018
1 parent 46f2511 commit 3f87975d656aa9847b3fc9e7310e9308cebfdf8d
@@ -91,6 +91,8 @@ macro_rules! arena_types {
rustc::hir::def_id::DefId,
String
>,
[few] get_lib_features: rustc::middle::lib_features::LibFeatures,
[few] defined_lib_features: rustc::middle::lang_items::LanguageItems,
], $tcx);
)
}
@@ -256,8 +256,8 @@ pub fn used_crates(tcx: TyCtxt<'_, '_, '_>, prefer: LinkagePreference)
Some((cnum, path))
})
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
Lrc::make_mut(&mut ordering).reverse();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned();
ordering.reverse();
libs.sort_by_cached_key(|&(a, _)| {
ordering.iter().position(|x| *x == a)
});
@@ -883,7 +883,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
remaining_lib_features.remove(&Symbol::intern("test"));

let check_features =
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {
for &(feature, since) in defined_features {
if let Some(since) = since {
if let Some(span) = remaining_lib_features.get(&feature) {
@@ -908,7 +908,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
if remaining_lib_features.is_empty() {
break;
}
check_features(&mut remaining_lib_features, &tcx.defined_lib_features(cnum));
check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum));
}
}

@@ -787,22 +787,22 @@ rustc_queries! {
query item_children(_: DefId) -> &'tcx [Export<hir::HirId>] {}
query extern_mod_stmt_cnum(_: DefId) -> Option<CrateNum> {}

query get_lib_features(_: CrateNum) -> Lrc<LibFeatures> {
query get_lib_features(_: CrateNum) -> &'tcx LibFeatures {
eval_always
desc { "calculating the lib features map" }
}
query defined_lib_features(_: CrateNum)
-> Lrc<Vec<(Symbol, Option<Symbol>)>> {
-> &'tcx [(Symbol, Option<Symbol>)] {
desc { "calculating the lib features defined in a crate" }
}
query get_lang_items(_: CrateNum) -> Lrc<LanguageItems> {
query get_lang_items(_: CrateNum) -> &'tcx LanguageItems {
eval_always
desc { "calculating the lang items map" }
}
query defined_lang_items(_: CrateNum) -> Lrc<Vec<(DefId, usize)>> {
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
desc { "calculating the lang items defined in a crate" }
}
query missing_lang_items(_: CrateNum) -> Lrc<Vec<LangItem>> {
query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
desc { "calculating the missing lang items in a crate" }
}
query visible_parent_map(_: CrateNum)
@@ -817,7 +817,7 @@ rustc_queries! {
eval_always
desc { "looking at the source for a crate" }
}
query postorder_cnums(_: CrateNum) -> Lrc<Vec<CrateNum>> {
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
eval_always
desc { "generating a postorder list of CrateNums" }
}
@@ -829,7 +829,7 @@ rustc_queries! {
eval_always
}
query maybe_unused_extern_crates(_: CrateNum)
-> Lrc<Vec<(DefId, Span)>> {
-> &'tcx [(DefId, Span)] {
eval_always
desc { "looking up all possibly unused extern crates" }
}
@@ -1376,11 +1376,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.sess.consider_optimizing(&cname, msg)
}

pub fn lib_features(self) -> Lrc<middle::lib_features::LibFeatures> {
pub fn lib_features(self) -> &'gcx middle::lib_features::LibFeatures {
self.get_lib_features(LOCAL_CRATE)
}

pub fn lang_items(self) -> Lrc<middle::lang_items::LanguageItems> {
pub fn lang_items(self) -> &'gcx middle::lang_items::LanguageItems {
self.get_lang_items(LOCAL_CRATE)
}

@@ -3060,19 +3060,19 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
};
providers.get_lib_features = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
Lrc::new(middle::lib_features::collect(tcx))
tcx.arena.alloc(middle::lib_features::collect(tcx))
};
providers.get_lang_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
Lrc::new(middle::lang_items::collect(tcx))
tcx.arena.alloc(middle::lang_items::collect(tcx))
};
providers.upvars = |tcx, id| tcx.gcx.upvars.get(&id).map(|v| &v[..]);
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);
Lrc::new(tcx.maybe_unused_extern_crates.clone())
&tcx.maybe_unused_extern_crates[..]
};
providers.names_imported_by_glob_use = |tcx, id| {
assert_eq!(id.krate, LOCAL_CRATE);
@@ -3103,7 +3103,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
};
providers.postorder_cnums = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(tcx.cstore.postorder_cnums_untracked())
tcx.arena.alloc_slice(&tcx.cstore.postorder_cnums_untracked())
};
providers.output_filenames = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
@@ -229,9 +229,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
tcx.arena.alloc_slice(&result)
}
defined_lib_features => { Lrc::new(cdata.get_lib_features()) }
defined_lang_items => { Lrc::new(cdata.get_lang_items()) }
missing_lang_items => { Lrc::new(cdata.get_missing_lang_items()) }
defined_lib_features => { cdata.get_lib_features(tcx) }
defined_lang_items => { cdata.get_lang_items(tcx) }
missing_lang_items => { cdata.get_missing_lang_items(tcx) }

missing_extern_crate_item => {
let r = match *cdata.extern_crate.borrow() {
@@ -708,26 +708,30 @@ impl<'a, 'tcx> CrateMetadata {
}

/// Iterates over all the stability attributes in the given crate.
pub fn get_lib_features(&self) -> Vec<(ast::Name, Option<ast::Name>)> {
pub fn get_lib_features(
&self,
tcx: TyCtxt<'_, 'tcx, '_>,
) -> &'tcx [(ast::Name, Option<ast::Name>)] {
// FIXME: For a proc macro crate, not sure whether we should return the "host"
// features or an empty Vec. Both don't cause ICEs.
self.root
tcx.arena.alloc_from_iter(self.root
.lib_features
.decode(self)
.collect()
.decode(self))
}

/// Iterates over the language items in the given crate.
pub fn get_lang_items(&self) -> Vec<(DefId, usize)> {
pub fn get_lang_items(
&self,
tcx: TyCtxt<'_, 'tcx, '_>,
) -> &'tcx [(DefId, usize)] {
if self.proc_macros.is_some() {
// Proc macro crates do not export any lang-items to the target.
vec![]
&[]
} else {
self.root
tcx.arena.alloc_from_iter(self.root
.lang_items
.decode(self)
.map(|(def_index, index)| (self.local_def_id(def_index), index))
.collect()
.map(|(def_index, index)| (self.local_def_id(def_index), index)))
}
}

@@ -1102,15 +1106,17 @@ impl<'a, 'tcx> CrateMetadata {
.collect()
}

pub fn get_missing_lang_items(&self) -> Vec<lang_items::LangItem> {
pub fn get_missing_lang_items(
&self,
tcx: TyCtxt<'_, 'tcx, '_>,
) -> &'tcx [lang_items::LangItem] {
if self.proc_macros.is_some() {
// Proc macro crates do not depend on any target weak lang-items.
vec![]
&[]
} else {
self.root
tcx.arena.alloc_from_iter(self.root
.lang_items_missing
.decode(self)
.collect()
.decode(self))
}
}

0 comments on commit 3f87975

Please sign in to comment.
You can’t perform that action at this time.