Skip to content

Commit 4612edc

Browse files
committed
rustc_codegen_ssa: Enforce rustc::potential_query_instability lint
1 parent 95613d1 commit 4612edc

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
@@ -559,6 +559,11 @@ fn link_staticlib<'a>(
559559
archive_builder_builder
560560
.extract_bundled_libs(path, tempdir.as_ref(), &relevant_libs)
561561
.unwrap_or_else(|e| sess.dcx().emit_fatal(e));
562+
563+
// We sort the libraries below
564+
#[allow(rustc::potential_query_instability)]
565+
let mut relevant_libs: Vec<Symbol> = relevant_libs.into_iter().collect();
566+
relevant_libs.sort_unstable();
562567
for filename in relevant_libs {
563568
let joined = tempdir.as_ref().join(filename.as_str());
564569
let path = joined.as_path();
@@ -2172,14 +2177,19 @@ fn linker_with_args<'a>(
21722177
.iter()
21732178
.find(|(ty, _)| *ty == crate_type)
21742179
.expect("failed to find crate type in dependency format list");
2175-
let native_libraries_from_nonstatics = codegen_results
2180+
2181+
// We sort the libraries below
2182+
#[allow(rustc::potential_query_instability)]
2183+
let mut native_libraries_from_nonstatics = codegen_results
21762184
.crate_info
21772185
.native_libraries
21782186
.iter()
21792187
.filter_map(|(cnum, libraries)| {
21802188
(dependency_linkage[cnum.as_usize() - 1] != Linkage::Static).then_some(libraries)
21812189
})
2182-
.flatten();
2190+
.flatten()
2191+
.collect::<Vec<_>>();
2192+
native_libraries_from_nonstatics.sort_unstable_by(|a, b| a.name.as_str().cmp(b.name.as_str()));
21832193
for (raw_dylib_name, raw_dylib_imports) in
21842194
collate_raw_dylibs(sess, native_libraries_from_nonstatics)?
21852195
{

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ fn exported_symbols_provider_local(
333333

334334
let (_, cgus) = tcx.collect_and_partition_mono_items(());
335335

336+
// The symbols created in this loop are sorted below it
337+
#[allow(rustc::potential_query_instability)]
336338
for (mono_item, data) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
337339
if data.linkage != Linkage::External {
338340
// 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
@@ -906,17 +906,22 @@ impl CrateInfo {
906906
})
907907
.collect();
908908
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };
909+
910+
// This loop only adds new items to values of the hash map, so the order in which we
911+
// iterate over the values is not important.
912+
#[allow(rustc::potential_query_instability)]
909913
info.linked_symbols
910914
.iter_mut()
911915
.filter(|(crate_type, _)| {
912916
!matches!(crate_type, CrateType::Rlib | CrateType::Staticlib)
913917
})
914918
.for_each(|(_, linked_symbols)| {
915-
linked_symbols.extend(
916-
missing_weak_lang_items
917-
.iter()
918-
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
919-
);
919+
let mut symbols = missing_weak_lang_items
920+
.iter()
921+
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text))
922+
.collect::<Vec<_>>();
923+
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
924+
linked_symbols.extend(symbols);
920925
if tcx.allocator_kind(()).is_some() {
921926
// At least one crate needs a global allocator. This crate may be placed
922927
// 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)