Use () in dependency_formats.

This commit is contained in:
Camille GILLOT 2021-05-11 11:26:52 +02:00
parent ac923d94f8
commit 85a14d70bb
8 changed files with 18 additions and 13 deletions

View File

@ -13,7 +13,7 @@ pub(crate) fn codegen(
module: &mut impl Module, module: &mut impl Module,
unwind_context: &mut UnwindContext, unwind_context: &mut UnwindContext,
) -> bool { ) -> bool {
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic) list.iter().any(|&linkage| linkage == Linkage::Dynamic)
}); });

View File

@ -179,7 +179,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
let mut dylib_paths = Vec::new(); let mut dylib_paths = Vec::new();
let crate_info = CrateInfo::new(tcx); let crate_info = CrateInfo::new(tcx);
let formats = tcx.dependency_formats(LOCAL_CRATE); let formats = tcx.dependency_formats(());
let data = &formats let data = &formats
.iter() .iter()
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)

View File

@ -1303,7 +1303,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
} }
} }
let formats = tcx.dependency_formats(LOCAL_CRATE); let formats = tcx.dependency_formats(());
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap(); let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
for (index, dep_format) in deps.iter().enumerate() { for (index, dep_format) in deps.iter().enumerate() {

View File

@ -511,7 +511,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// linkage, then it's already got an allocator shim and we'll be using that // linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the // one instead. If nothing exists then it's our job to generate the
// allocator! // allocator!
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic) list.iter().any(|&linkage| linkage == Linkage::Dynamic)
}); });
@ -768,7 +768,7 @@ impl CrateInfo {
used_crate_source: Default::default(), used_crate_source: Default::default(),
lang_item_to_crate: Default::default(), lang_item_to_crate: Default::default(),
missing_lang_items: Default::default(), missing_lang_items: Default::default(),
dependency_formats: tcx.dependency_formats(LOCAL_CRATE), dependency_formats: tcx.dependency_formats(()),
}; };
let lang_items = tcx.lang_items(); let lang_items = tcx.lang_items();

View File

@ -370,10 +370,7 @@ pub fn provide(providers: &mut Providers) {
visible_parent_map visible_parent_map
}, },
dependency_formats: |tcx, cnum| { dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(crate::dependency_format::calculate(tcx))
},
has_global_allocator: |tcx, cnum| { has_global_allocator: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
CStore::from_tcx(tcx).has_global_allocator() CStore::from_tcx(tcx).has_global_allocator()

View File

@ -1773,7 +1773,7 @@ impl EncodeContext<'a, 'tcx> {
fn encode_dylib_dependency_formats(&mut self) -> Lazy<[Option<LinkagePreference>]> { fn encode_dylib_dependency_formats(&mut self) -> Lazy<[Option<LinkagePreference>]> {
empty_proc_macro!(self); empty_proc_macro!(self);
let formats = self.tcx.dependency_formats(LOCAL_CRATE); let formats = self.tcx.dependency_formats(());
for (ty, arr) in formats.iter() { for (ty, arr) in formats.iter() {
if *ty != CrateType::Dylib { if *ty != CrateType::Dylib {
continue; continue;

View File

@ -1053,9 +1053,7 @@ rustc_queries! {
desc { "dylib dependency formats of crate" } desc { "dylib dependency formats of crate" }
} }
query dependency_formats(_: CrateNum) query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
-> Lrc<crate::middle::dependency_format::Dependencies>
{
desc { "get the linkage format of all dependencies" } desc { "get the linkage format of all dependencies" }
} }

View File

@ -21,6 +21,16 @@ pub trait Key {
fn default_span(&self, tcx: TyCtxt<'_>) -> Span; fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
} }
impl Key for () {
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for ty::InstanceDef<'tcx> { impl<'tcx> Key for ty::InstanceDef<'tcx> {
fn query_crate(&self) -> CrateNum { fn query_crate(&self) -> CrateNum {
LOCAL_CRATE LOCAL_CRATE