Skip to content

Commit 3022afe

Browse files
committed
Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillot
Get rid of native_library projection queries They don't seem particularly useful as I don't expect native libraries to change frequently. Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2 parents eecde58 + ccc5461 commit 3022afe

File tree

7 files changed

+18
-25
lines changed

7 files changed

+18
-25
lines changed

compiler/rustc_codegen_llvm/src/callee.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
179179
// MinGW: For backward compatibility we rely on the linker to decide whether it
180180
// should use dllimport for functions.
181181
if cx.use_dll_storage_attrs
182-
&& tcx.is_dllimport_foreign_item(instance_def_id)
182+
&& let Some(library) = tcx.native_library(instance_def_id)
183+
&& library.kind.is_dllimport()
183184
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
184185
{
185186
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);

compiler/rustc_codegen_llvm/src/consts.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ impl<'ll> CodegenCx<'ll, '_> {
332332
}
333333
}
334334

335-
if self.use_dll_storage_attrs && self.tcx.is_dllimport_foreign_item(def_id) {
335+
if self.use_dll_storage_attrs
336+
&& let Some(library) = self.tcx.native_library(def_id)
337+
&& library.kind.is_dllimport()
338+
{
336339
// For foreign (native) libs we know the exact storage type to use.
337340
unsafe {
338341
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
7676
// let it through if it's included statically.
7777
match tcx.hir().get_by_def_id(def_id) {
7878
Node::ForeignItem(..) => {
79-
tcx.is_statically_included_foreign_item(def_id).then_some(def_id)
79+
tcx.native_library(def_id).map_or(false, |library| library.kind.is_statically_included()).then_some(def_id)
8080
}
8181

8282
// Only consider nodes that actually have exported symbols.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::ty::fast_reject::SimplifiedType;
1515
use rustc_middle::ty::query::{ExternProviders, Providers};
1616
use rustc_middle::ty::{self, TyCtxt, Visibility};
1717
use rustc_session::cstore::{CrateSource, CrateStore};
18-
use rustc_session::utils::NativeLibKind;
1918
use rustc_session::{Session, StableCrateId};
2019
use rustc_span::hygiene::{ExpnHash, ExpnId};
2120
use rustc_span::source_map::{Span, Spanned};
@@ -340,20 +339,10 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
340339
// resolve! Does this work? Unsure! That's what the issue is about
341340
*providers = Providers {
342341
allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
343-
is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
344-
Some(
345-
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified,
346-
) => true,
347-
_ => false,
348-
},
349-
is_statically_included_foreign_item: |tcx, id| {
350-
matches!(tcx.native_library_kind(id), Some(NativeLibKind::Static { .. }))
351-
},
352342
is_private_dep: |_tcx, cnum| {
353343
assert_eq!(cnum, LOCAL_CRATE);
354344
false
355345
},
356-
native_library_kind: |tcx, id| tcx.native_library(id).map(|l| l.kind),
357346
native_library: |tcx, id| {
358347
tcx.native_libraries(id.krate)
359348
.iter()

compiler/rustc_middle/src/query/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1587,16 +1587,6 @@ rustc_queries! {
15871587
separate_provide_extern
15881588
}
15891589

1590-
query is_dllimport_foreign_item(def_id: DefId) -> bool {
1591-
desc { |tcx| "checking if `{}` is a a dylib", tcx.def_path_str(def_id) }
1592-
}
1593-
query is_statically_included_foreign_item(def_id: DefId) -> bool {
1594-
desc { |tcx| "checking if `{}` is a staticlib", tcx.def_path_str(def_id) }
1595-
}
1596-
query native_library_kind(def_id: DefId)
1597-
-> Option<NativeLibKind> {
1598-
desc { |tcx| "getting the native library kind of `{}`", tcx.def_path_str(def_id) }
1599-
}
16001590
query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
16011591
desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
16021592
}

compiler/rustc_middle/src/ty/query.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolMangli
5252
use rustc_session::cstore::{CrateDepKind, CrateSource};
5353
use rustc_session::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLib};
5454
use rustc_session::lint::LintExpectationId;
55-
use rustc_session::utils::NativeLibKind;
5655
use rustc_session::Limits;
5756
use rustc_span::symbol::Symbol;
5857
use rustc_span::{Span, DUMMY_SP};

compiler/rustc_session/src/utils.rs

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ impl NativeLibKind {
5353
NativeLibKind::RawDylib | NativeLibKind::Unspecified | NativeLibKind::LinkArg => false,
5454
}
5555
}
56+
57+
pub fn is_statically_included(&self) -> bool {
58+
matches!(self, NativeLibKind::Static { .. })
59+
}
60+
61+
pub fn is_dllimport(&self) -> bool {
62+
matches!(
63+
self,
64+
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
65+
)
66+
}
5667
}
5768

5869
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]

0 commit comments

Comments
 (0)