Skip to content

Commit 3f87975

Browse files
committed
Update get_lib_features, defined_lib_features, get_lang_items, defined_lang_items, missing_lang_items, postorder_cnums and maybe_unused_extern_crates
1 parent 46f2511 commit 3f87975

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
lines changed

src/librustc/arena.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ macro_rules! arena_types {
9191
rustc::hir::def_id::DefId,
9292
String
9393
>,
94+
[few] get_lib_features: rustc::middle::lib_features::LibFeatures,
95+
[few] defined_lib_features: rustc::middle::lang_items::LanguageItems,
9496
], $tcx);
9597
)
9698
}

src/librustc/middle/cstore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ pub fn used_crates(tcx: TyCtxt<'_, '_, '_>, prefer: LinkagePreference)
256256
Some((cnum, path))
257257
})
258258
.collect::<Vec<_>>();
259-
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
260-
Lrc::make_mut(&mut ordering).reverse();
259+
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned();
260+
ordering.reverse();
261261
libs.sort_by_cached_key(|&(a, _)| {
262262
ordering.iter().position(|x| *x == a)
263263
});

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
883883
remaining_lib_features.remove(&Symbol::intern("test"));
884884

885885
let check_features =
886-
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {
886+
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {
887887
for &(feature, since) in defined_features {
888888
if let Some(since) = since {
889889
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>) {
908908
if remaining_lib_features.is_empty() {
909909
break;
910910
}
911-
check_features(&mut remaining_lib_features, &tcx.defined_lib_features(cnum));
911+
check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum));
912912
}
913913
}
914914

src/librustc/query/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,22 +787,22 @@ rustc_queries! {
787787
query item_children(_: DefId) -> &'tcx [Export<hir::HirId>] {}
788788
query extern_mod_stmt_cnum(_: DefId) -> Option<CrateNum> {}
789789

790-
query get_lib_features(_: CrateNum) -> Lrc<LibFeatures> {
790+
query get_lib_features(_: CrateNum) -> &'tcx LibFeatures {
791791
eval_always
792792
desc { "calculating the lib features map" }
793793
}
794794
query defined_lib_features(_: CrateNum)
795-
-> Lrc<Vec<(Symbol, Option<Symbol>)>> {
795+
-> &'tcx [(Symbol, Option<Symbol>)] {
796796
desc { "calculating the lib features defined in a crate" }
797797
}
798-
query get_lang_items(_: CrateNum) -> Lrc<LanguageItems> {
798+
query get_lang_items(_: CrateNum) -> &'tcx LanguageItems {
799799
eval_always
800800
desc { "calculating the lang items map" }
801801
}
802-
query defined_lang_items(_: CrateNum) -> Lrc<Vec<(DefId, usize)>> {
802+
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
803803
desc { "calculating the lang items defined in a crate" }
804804
}
805-
query missing_lang_items(_: CrateNum) -> Lrc<Vec<LangItem>> {
805+
query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
806806
desc { "calculating the missing lang items in a crate" }
807807
}
808808
query visible_parent_map(_: CrateNum)
@@ -817,7 +817,7 @@ rustc_queries! {
817817
eval_always
818818
desc { "looking at the source for a crate" }
819819
}
820-
query postorder_cnums(_: CrateNum) -> Lrc<Vec<CrateNum>> {
820+
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
821821
eval_always
822822
desc { "generating a postorder list of CrateNums" }
823823
}
@@ -829,7 +829,7 @@ rustc_queries! {
829829
eval_always
830830
}
831831
query maybe_unused_extern_crates(_: CrateNum)
832-
-> Lrc<Vec<(DefId, Span)>> {
832+
-> &'tcx [(DefId, Span)] {
833833
eval_always
834834
desc { "looking up all possibly unused extern crates" }
835835
}

src/librustc/ty/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13761376
self.sess.consider_optimizing(&cname, msg)
13771377
}
13781378

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

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

@@ -3060,19 +3060,19 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30603060
};
30613061
providers.get_lib_features = |tcx, id| {
30623062
assert_eq!(id, LOCAL_CRATE);
3063-
Lrc::new(middle::lib_features::collect(tcx))
3063+
tcx.arena.alloc(middle::lib_features::collect(tcx))
30643064
};
30653065
providers.get_lang_items = |tcx, id| {
30663066
assert_eq!(id, LOCAL_CRATE);
3067-
Lrc::new(middle::lang_items::collect(tcx))
3067+
tcx.arena.alloc(middle::lang_items::collect(tcx))
30683068
};
30693069
providers.upvars = |tcx, id| tcx.gcx.upvars.get(&id).map(|v| &v[..]);
30703070
providers.maybe_unused_trait_import = |tcx, id| {
30713071
tcx.maybe_unused_trait_imports.contains(&id)
30723072
};
30733073
providers.maybe_unused_extern_crates = |tcx, cnum| {
30743074
assert_eq!(cnum, LOCAL_CRATE);
3075-
Lrc::new(tcx.maybe_unused_extern_crates.clone())
3075+
&tcx.maybe_unused_extern_crates[..]
30763076
};
30773077
providers.names_imported_by_glob_use = |tcx, id| {
30783078
assert_eq!(id.krate, LOCAL_CRATE);
@@ -3103,7 +3103,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
31033103
};
31043104
providers.postorder_cnums = |tcx, cnum| {
31053105
assert_eq!(cnum, LOCAL_CRATE);
3106-
Lrc::new(tcx.cstore.postorder_cnums_untracked())
3106+
tcx.arena.alloc_slice(&tcx.cstore.postorder_cnums_untracked())
31073107
};
31083108
providers.output_filenames = |tcx, cnum| {
31093109
assert_eq!(cnum, LOCAL_CRATE);

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
229229
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
230230
tcx.arena.alloc_slice(&result)
231231
}
232-
defined_lib_features => { Lrc::new(cdata.get_lib_features()) }
233-
defined_lang_items => { Lrc::new(cdata.get_lang_items()) }
234-
missing_lang_items => { Lrc::new(cdata.get_missing_lang_items()) }
232+
defined_lib_features => { cdata.get_lib_features(tcx) }
233+
defined_lang_items => { cdata.get_lang_items(tcx) }
234+
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
235235

236236
missing_extern_crate_item => {
237237
let r = match *cdata.extern_crate.borrow() {

src/librustc_metadata/decoder.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -708,26 +708,30 @@ impl<'a, 'tcx> CrateMetadata {
708708
}
709709

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

720722
/// Iterates over the language items in the given crate.
721-
pub fn get_lang_items(&self) -> Vec<(DefId, usize)> {
723+
pub fn get_lang_items(
724+
&self,
725+
tcx: TyCtxt<'_, 'tcx, '_>,
726+
) -> &'tcx [(DefId, usize)] {
722727
if self.proc_macros.is_some() {
723728
// Proc macro crates do not export any lang-items to the target.
724-
vec![]
729+
&[]
725730
} else {
726-
self.root
731+
tcx.arena.alloc_from_iter(self.root
727732
.lang_items
728733
.decode(self)
729-
.map(|(def_index, index)| (self.local_def_id(def_index), index))
730-
.collect()
734+
.map(|(def_index, index)| (self.local_def_id(def_index), index)))
731735
}
732736
}
733737

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

1105-
pub fn get_missing_lang_items(&self) -> Vec<lang_items::LangItem> {
1109+
pub fn get_missing_lang_items(
1110+
&self,
1111+
tcx: TyCtxt<'_, 'tcx, '_>,
1112+
) -> &'tcx [lang_items::LangItem] {
11061113
if self.proc_macros.is_some() {
11071114
// Proc macro crates do not depend on any target weak lang-items.
1108-
vec![]
1115+
&[]
11091116
} else {
1110-
self.root
1117+
tcx.arena.alloc_from_iter(self.root
11111118
.lang_items_missing
1112-
.decode(self)
1113-
.collect()
1119+
.decode(self))
11141120
}
11151121
}
11161122

0 commit comments

Comments
 (0)