Skip to content

Commit 6aecc91

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 b5660a8 commit 6aecc91

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
lines changed

src/librustc/arena.rs

+2
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

+2-2
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

+2-2
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

+7-7
Original file line numberDiff line numberDiff line change
@@ -789,22 +789,22 @@ rustc_queries! {
789789
query item_children(_: DefId) -> &'tcx [Export<hir::HirId>] {}
790790
query extern_mod_stmt_cnum(_: DefId) -> Option<CrateNum> {}
791791

792-
query get_lib_features(_: CrateNum) -> Lrc<LibFeatures> {
792+
query get_lib_features(_: CrateNum) -> &'tcx LibFeatures {
793793
eval_always
794794
desc { "calculating the lib features map" }
795795
}
796796
query defined_lib_features(_: CrateNum)
797-
-> Lrc<Vec<(Symbol, Option<Symbol>)>> {
797+
-> &'tcx [(Symbol, Option<Symbol>)] {
798798
desc { "calculating the lib features defined in a crate" }
799799
}
800-
query get_lang_items(_: CrateNum) -> Lrc<LanguageItems> {
800+
query get_lang_items(_: CrateNum) -> &'tcx LanguageItems {
801801
eval_always
802802
desc { "calculating the lang items map" }
803803
}
804-
query defined_lang_items(_: CrateNum) -> Lrc<Vec<(DefId, usize)>> {
804+
query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
805805
desc { "calculating the lang items defined in a crate" }
806806
}
807-
query missing_lang_items(_: CrateNum) -> Lrc<Vec<LangItem>> {
807+
query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
808808
desc { "calculating the missing lang items in a crate" }
809809
}
810810
query visible_parent_map(_: CrateNum)
@@ -819,7 +819,7 @@ rustc_queries! {
819819
eval_always
820820
desc { "looking at the source for a crate" }
821821
}
822-
query postorder_cnums(_: CrateNum) -> Lrc<Vec<CrateNum>> {
822+
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
823823
eval_always
824824
desc { "generating a postorder list of CrateNums" }
825825
}
@@ -831,7 +831,7 @@ rustc_queries! {
831831
eval_always
832832
}
833833
query maybe_unused_extern_crates(_: CrateNum)
834-
-> Lrc<Vec<(DefId, Span)>> {
834+
-> &'tcx [(DefId, Span)] {
835835
eval_always
836836
desc { "looking up all possibly unused extern crates" }
837837
}

src/librustc/ty/context.rs

+6-6
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

+3-3
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

+20-14
Original file line numberDiff line numberDiff line change
@@ -707,26 +707,30 @@ impl<'a, 'tcx> CrateMetadata {
707707
}
708708

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

719721
/// Iterates over the language items in the given crate.
720-
pub fn get_lang_items(&self) -> Vec<(DefId, usize)> {
722+
pub fn get_lang_items(
723+
&self,
724+
tcx: TyCtxt<'_, 'tcx, '_>,
725+
) -> &'tcx [(DefId, usize)] {
721726
if self.proc_macros.is_some() {
722727
// Proc macro crates do not export any lang-items to the target.
723-
vec![]
728+
&[]
724729
} else {
725-
self.root
730+
tcx.arena.alloc_from_iter(self.root
726731
.lang_items
727732
.decode(self)
728-
.map(|(def_index, index)| (self.local_def_id(def_index), index))
729-
.collect()
733+
.map(|(def_index, index)| (self.local_def_id(def_index), index)))
730734
}
731735
}
732736

@@ -1101,15 +1105,17 @@ impl<'a, 'tcx> CrateMetadata {
11011105
.collect()
11021106
}
11031107

1104-
pub fn get_missing_lang_items(&self) -> Vec<lang_items::LangItem> {
1108+
pub fn get_missing_lang_items(
1109+
&self,
1110+
tcx: TyCtxt<'_, 'tcx, '_>,
1111+
) -> &'tcx [lang_items::LangItem] {
11051112
if self.proc_macros.is_some() {
11061113
// Proc macro crates do not depend on any target weak lang-items.
1107-
vec![]
1114+
&[]
11081115
} else {
1109-
self.root
1116+
tcx.arena.alloc_from_iter(self.root
11101117
.lang_items_missing
1111-
.decode(self)
1112-
.collect()
1118+
.decode(self))
11131119
}
11141120
}
11151121

0 commit comments

Comments
 (0)