Cache foreign_modules query
This commit is contained in:
parent
9f6c670c4b
commit
69dc98161a
7 changed files with 20 additions and 16 deletions
|
@ -378,8 +378,8 @@ pub fn provide_both(providers: &mut Providers) {
|
||||||
.collect::<FxHashMap<_, _>>();
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
let mut ret = FxHashMap::default();
|
let mut ret = FxHashMap::default();
|
||||||
for lib in tcx.foreign_modules(cnum).iter() {
|
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
|
||||||
let module = def_id_to_native_lib.get(&lib.def_id).and_then(|s| s.wasm_import_module);
|
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module);
|
||||||
let module = match module {
|
let module = match module {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => continue,
|
None => continue,
|
||||||
|
|
|
@ -861,7 +861,7 @@ pub fn provide_both(providers: &mut Providers) {
|
||||||
providers.dllimport_foreign_items = |tcx, krate| {
|
providers.dllimport_foreign_items = |tcx, krate| {
|
||||||
let module_map = tcx.foreign_modules(krate);
|
let module_map = tcx.foreign_modules(krate);
|
||||||
let module_map =
|
let module_map =
|
||||||
module_map.iter().map(|lib| (lib.def_id, lib)).collect::<FxHashMap<_, _>>();
|
module_map.iter().map(|(def_id, lib)| (def_id, lib)).collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
let dllimports = tcx
|
let dllimports = tcx
|
||||||
.native_libraries(krate)
|
.native_libraries(krate)
|
||||||
|
|
|
@ -1414,12 +1414,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_foreign_modules(&self, tcx: TyCtxt<'tcx>) -> &'tcx [ForeignModule] {
|
fn get_foreign_modules(&self, tcx: TyCtxt<'tcx>) -> Lrc<FxHashMap<DefId, ForeignModule>> {
|
||||||
if self.root.is_proc_macro_crate() {
|
if self.root.is_proc_macro_crate() {
|
||||||
// Proc macro crates do not have any *target* foreign modules.
|
// Proc macro crates do not have any *target* foreign modules.
|
||||||
&[]
|
Lrc::new(FxHashMap::default())
|
||||||
} else {
|
} else {
|
||||||
tcx.arena.alloc_from_iter(self.root.foreign_modules.decode((self, tcx.sess)))
|
let modules: FxHashMap<DefId, ForeignModule> =
|
||||||
|
self.root.foreign_modules.decode((self, tcx.sess)).map(|m| (m.def_id, m)).collect();
|
||||||
|
Lrc::new(modules)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,14 @@ use crate::rmeta::{self, encoder};
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::expand::allocator::AllocatorKind;
|
use rustc_ast::expand::allocator::AllocatorKind;
|
||||||
|
use rustc_data_structures::stable_map::FxHashMap;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
||||||
use rustc_middle::hir::exports::Export;
|
use rustc_middle::hir::exports::Export;
|
||||||
|
use rustc_middle::middle::cstore::ForeignModule;
|
||||||
use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
|
use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
|
||||||
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
||||||
use rustc_middle::middle::stability::DeprecationEntry;
|
use rustc_middle::middle::stability::DeprecationEntry;
|
||||||
|
@ -267,12 +269,10 @@ pub fn provide(providers: &mut Providers) {
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
tcx.foreign_modules(id.krate)
|
let map = tcx.foreign_modules(id.krate);
|
||||||
.iter()
|
let module =
|
||||||
.find(|m| m.def_id == fm_id)
|
tcx.prof.generic_activity("finding_foreign_module").run(|| map.get(&fm_id));
|
||||||
.expect("failed to find foreign module")
|
module.expect("failed to find foreign module").foreign_items.contains(&id)
|
||||||
.foreign_items
|
|
||||||
.contains(&id)
|
|
||||||
})
|
})
|
||||||
.map(|l| l.kind)
|
.map(|l| l.kind)
|
||||||
},
|
},
|
||||||
|
@ -282,7 +282,9 @@ pub fn provide(providers: &mut Providers) {
|
||||||
},
|
},
|
||||||
foreign_modules: |tcx, cnum| {
|
foreign_modules: |tcx, cnum| {
|
||||||
assert_eq!(cnum, LOCAL_CRATE);
|
assert_eq!(cnum, LOCAL_CRATE);
|
||||||
&tcx.arena.alloc(foreign_modules::collect(tcx))[..]
|
let modules: FxHashMap<DefId, ForeignModule> =
|
||||||
|
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect();
|
||||||
|
Lrc::new(modules)
|
||||||
},
|
},
|
||||||
link_args: |tcx, cnum| {
|
link_args: |tcx, cnum| {
|
||||||
assert_eq!(cnum, LOCAL_CRATE);
|
assert_eq!(cnum, LOCAL_CRATE);
|
||||||
|
|
|
@ -1502,7 +1502,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
fn encode_foreign_modules(&mut self) -> Lazy<[ForeignModule]> {
|
fn encode_foreign_modules(&mut self) -> Lazy<[ForeignModule]> {
|
||||||
empty_proc_macro!(self);
|
empty_proc_macro!(self);
|
||||||
let foreign_modules = self.tcx.foreign_modules(LOCAL_CRATE);
|
let foreign_modules = self.tcx.foreign_modules(LOCAL_CRATE);
|
||||||
self.lazy(foreign_modules.iter().cloned())
|
self.lazy(foreign_modules.iter().map(|(_, m)| m).cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable) {
|
fn encode_hygiene(&mut self) -> (SyntaxContextTable, ExpnDataTable) {
|
||||||
|
|
|
@ -1168,7 +1168,7 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
Other {
|
Other {
|
||||||
query foreign_modules(_: CrateNum) -> &'tcx [ForeignModule] {
|
query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
|
||||||
desc { "looking up the foreign modules of a linked crate" }
|
desc { "looking up the foreign modules of a linked crate" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
|
||||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||||
// FIXME(visit_all_item_likes): Foreign items are not visited
|
// FIXME(visit_all_item_likes): Foreign items are not visited
|
||||||
// here, so we have to manually look at them for now.
|
// here, so we have to manually look at them for now.
|
||||||
for foreign_module in tcx.foreign_modules(LOCAL_CRATE) {
|
for (_, foreign_module) in tcx.foreign_modules(LOCAL_CRATE).iter() {
|
||||||
for &foreign_item in foreign_module.foreign_items.iter() {
|
for &foreign_item in foreign_module.foreign_items.iter() {
|
||||||
match tcx.hir().get(tcx.hir().local_def_id_to_hir_id(foreign_item.expect_local())) {
|
match tcx.hir().get(tcx.hir().local_def_id_to_hir_id(foreign_item.expect_local())) {
|
||||||
hir::Node::ForeignItem(item) => {
|
hir::Node::ForeignItem(item) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue