Skip to content

Commit 23148b1

Browse files
committed
Auto merge of rust-lang#119409 - Kobzol:rustc-codegen-ssa-query-instability, r=Nilstrieb
rustc_codegen_ssa: Enforce `rustc::potential_query_instability` lint Part of rust-lang#84447.
2 parents c6c4abf + 4612edc commit 23148b1

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,12 @@ impl CguReuseTracker {
267267

268268
fn check_expected_reuse(&self, sess: &Session) {
269269
if let Some(ref data) = self.data {
270-
for (cgu_name, &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind)) in
271-
&data.expected_reuse
272-
{
270+
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
271+
keys.sort_unstable();
272+
for cgu_name in keys {
273+
let &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) =
274+
data.expected_reuse.get(cgu_name).unwrap();
275+
273276
if let Some(&actual_reuse) = data.actual_reuse.get(cgu_name) {
274277
let (error, at_least) = match comparison_kind {
275278
ComparisonKind::Exact => (expected_reuse != actual_reuse, false),

compiler/rustc_codegen_ssa/src/back/link.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ fn link_staticlib<'a>(
554554
archive_builder_builder
555555
.extract_bundled_libs(path, tempdir.as_ref(), &relevant_libs)
556556
.unwrap_or_else(|e| sess.dcx().emit_fatal(e));
557+
558+
// We sort the libraries below
559+
#[allow(rustc::potential_query_instability)]
560+
let mut relevant_libs: Vec<Symbol> = relevant_libs.into_iter().collect();
561+
relevant_libs.sort_unstable();
557562
for filename in relevant_libs {
558563
let joined = tempdir.as_ref().join(filename.as_str());
559564
let path = joined.as_path();
@@ -2201,14 +2206,19 @@ fn linker_with_args<'a>(
22012206
.iter()
22022207
.find(|(ty, _)| *ty == crate_type)
22032208
.expect("failed to find crate type in dependency format list");
2204-
let native_libraries_from_nonstatics = codegen_results
2209+
2210+
// We sort the libraries below
2211+
#[allow(rustc::potential_query_instability)]
2212+
let mut native_libraries_from_nonstatics = codegen_results
22052213
.crate_info
22062214
.native_libraries
22072215
.iter()
22082216
.filter_map(|(cnum, libraries)| {
22092217
(dependency_linkage[cnum.as_usize() - 1] != Linkage::Static).then_some(libraries)
22102218
})
2211-
.flatten();
2219+
.flatten()
2220+
.collect::<Vec<_>>();
2221+
native_libraries_from_nonstatics.sort_unstable_by(|a, b| a.name.as_str().cmp(b.name.as_str()));
22122222
for (raw_dylib_name, raw_dylib_imports) in
22132223
collate_raw_dylibs(sess, native_libraries_from_nonstatics)?
22142224
{

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ fn exported_symbols_provider_local(
319319

320320
let (_, cgus) = tcx.collect_and_partition_mono_items(());
321321

322+
// The symbols created in this loop are sorted below it
323+
#[allow(rustc::potential_query_instability)]
322324
for (mono_item, data) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
323325
if data.linkage != Linkage::External {
324326
// We can only re-use things with external linkage, otherwise

compiler/rustc_codegen_ssa/src/base.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -912,17 +912,22 @@ impl CrateInfo {
912912
})
913913
.collect();
914914
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };
915+
916+
// This loop only adds new items to values of the hash map, so the order in which we
917+
// iterate over the values is not important.
918+
#[allow(rustc::potential_query_instability)]
915919
info.linked_symbols
916920
.iter_mut()
917921
.filter(|(crate_type, _)| {
918922
!matches!(crate_type, CrateType::Rlib | CrateType::Staticlib)
919923
})
920924
.for_each(|(_, linked_symbols)| {
921-
linked_symbols.extend(
922-
missing_weak_lang_items
923-
.iter()
924-
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
925-
);
925+
let mut symbols = missing_weak_lang_items
926+
.iter()
927+
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text))
928+
.collect::<Vec<_>>();
929+
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
930+
linked_symbols.extend(symbols);
926931
if tcx.allocator_kind(()).is_some() {
927932
// At least one crate needs a global allocator. This crate may be placed
928933
// after the crate that defines it in the linker order, in which case some

compiler/rustc_codegen_ssa/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![feature(strict_provenance)]
1212
#![feature(try_blocks)]
1313
#![recursion_limit = "256"]
14-
#![allow(rustc::potential_query_instability)]
1514

1615
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
1716
//! The backend-agnostic functions of this crate use functions defined in various traits that

0 commit comments

Comments
 (0)