Skip to content

Commit 062a42c

Browse files
committed
Handle rustc_query_system cases of rustc::potential_query_instability lint
1 parent f7c8928 commit 062a42c

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

Cargo.lock

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
3-
version = 3
3+
version = 4
44

55
[[package]]
66
name = "addr2line"
@@ -1520,6 +1520,12 @@ dependencies = [
15201520
"serde",
15211521
]
15221522

1523+
[[package]]
1524+
name = "hashbrown"
1525+
version = "0.15.0"
1526+
source = "registry+https://github.com/rust-lang/crates.io-index"
1527+
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
1528+
15231529
[[package]]
15241530
name = "heck"
15251531
version = "0.4.1"
@@ -1768,12 +1774,12 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
17681774

17691775
[[package]]
17701776
name = "indexmap"
1771-
version = "2.5.0"
1777+
version = "2.6.0"
17721778
source = "registry+https://github.com/rust-lang/crates.io-index"
1773-
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
1779+
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
17741780
dependencies = [
17751781
"equivalent",
1776-
"hashbrown",
1782+
"hashbrown 0.15.0",
17771783
"rustc-rayon",
17781784
"serde",
17791785
]
@@ -2467,7 +2473,7 @@ checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a"
24672473
dependencies = [
24682474
"crc32fast",
24692475
"flate2",
2470-
"hashbrown",
2476+
"hashbrown 0.14.5",
24712477
"indexmap",
24722478
"memchr",
24732479
"ruzstd",
@@ -2496,7 +2502,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
24962502
checksum = "30c7f82d6d446dd295845094f3a76bcdc5e6183b66667334e169f019cd05e5a0"
24972503
dependencies = [
24982504
"ahash",
2499-
"hashbrown",
2505+
"hashbrown 0.14.5",
25002506
"parking_lot",
25012507
"stable_deref_trait",
25022508
]
@@ -4283,6 +4289,7 @@ dependencies = [
42834289
name = "rustc_query_system"
42844290
version = "0.0.0"
42854291
dependencies = [
4292+
"indexmap",
42864293
"parking_lot",
42874294
"rustc-rayon-core",
42884295
"rustc_ast",
@@ -5213,7 +5220,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
52135220
checksum = "813ba76597db32dc4f6992fd8bf8f394715b88d352fd97401da67dab6283b4c6"
52145221
dependencies = [
52155222
"gimli 0.30.0",
5216-
"hashbrown",
5223+
"hashbrown 0.14.5",
52175224
"object 0.36.4",
52185225
"tracing",
52195226
]
@@ -5873,7 +5880,7 @@ checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc"
58735880
dependencies = [
58745881
"ahash",
58755882
"bitflags 2.6.0",
5876-
"hashbrown",
5883+
"hashbrown 0.14.5",
58775884
"indexmap",
58785885
"semver",
58795886
"serde",

compiler/rustc_query_system/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
indexmap = "2.6.0"
89
parking_lot = "0.12"
910
rustc-rayon-core = { version = "0.5.0", optional = true }
1011
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_query_system/src/dep_graph/graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::assert_matches::assert_matches;
2-
use std::collections::hash_map::Entry;
32
use std::fmt::Debug;
43
use std::hash::Hash;
54
use std::marker::PhantomData;
65
use std::sync::Arc;
76
use std::sync::atomic::Ordering;
87

8+
use indexmap::map::Entry;
99
use rustc_data_structures::fingerprint::Fingerprint;
10-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
1111
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
1212
use rustc_data_structures::sharded::{self, Sharded};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1054,7 +1054,7 @@ rustc_index::newtype_index! {
10541054
/// first, and `data` second.
10551055
pub(super) struct CurrentDepGraph<D: Deps> {
10561056
encoder: GraphEncoder<D>,
1057-
new_node_to_index: Sharded<FxHashMap<DepNode, DepNodeIndex>>,
1057+
new_node_to_index: Sharded<FxIndexMap<DepNode, DepNodeIndex>>,
10581058
prev_index_to_index: Lock<IndexVec<SerializedDepNodeIndex, Option<DepNodeIndex>>>,
10591059

10601060
/// This is used to verify that fingerprints do not change between the creation of a node
@@ -1124,7 +1124,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11241124
previous,
11251125
),
11261126
new_node_to_index: Sharded::new(|| {
1127-
FxHashMap::with_capacity_and_hasher(
1127+
FxIndexMap::with_capacity_and_hasher(
11281128
new_node_count_estimate / sharded::shards(),
11291129
Default::default(),
11301130
)

compiler/rustc_query_system/src/dep_graph/serialized.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use std::marker::PhantomData;
4040
use std::sync::Arc;
4141

4242
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
43-
use rustc_data_structures::fx::FxHashMap;
43+
use rustc_data_structures::fx::FxIndexMap;
4444
use rustc_data_structures::outline;
4545
use rustc_data_structures::profiling::SelfProfilerRef;
4646
use rustc_data_structures::sync::Lock;
@@ -472,7 +472,7 @@ struct EncoderState<D: Deps> {
472472
encoder: FileEncoder,
473473
total_node_count: usize,
474474
total_edge_count: usize,
475-
stats: Option<FxHashMap<DepKind, Stat>>,
475+
stats: Option<FxIndexMap<DepKind, Stat>>,
476476

477477
/// Stores the number of times we've encoded each dep kind.
478478
kind_stats: Vec<u32>,
@@ -486,7 +486,7 @@ impl<D: Deps> EncoderState<D> {
486486
encoder,
487487
total_edge_count: 0,
488488
total_node_count: 0,
489-
stats: record_stats.then(FxHashMap::default),
489+
stats: record_stats.then(FxIndexMap::default),
490490
kind_stats: iter::repeat(0).take(D::DEP_KIND_MAX as usize + 1).collect(),
491491
marker: PhantomData,
492492
}

compiler/rustc_query_system/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tidy-alphabetical-start
2-
#![allow(rustc::potential_query_instability, internal_features)]
2+
#![allow(internal_features)]
33
#![feature(assert_matches)]
44
#![feature(core_intrinsics)]
55
#![feature(hash_raw_entry)]

compiler/rustc_query_system/src/query/caches.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::fmt::Debug;
22
use std::hash::Hash;
33

4-
use rustc_data_structures::fx::FxHashMap;
4+
use indexmap::map::RawEntryApiV1;
5+
use rustc_data_structures::fx::FxIndexMap;
56
use rustc_data_structures::sharded::{self, Sharded};
67
use rustc_data_structures::sync::{Lock, OnceLock};
78
use rustc_hir::def_id::LOCAL_CRATE;
@@ -23,7 +24,7 @@ pub trait QueryCache: Sized {
2324
}
2425

2526
pub struct DefaultCache<K, V> {
26-
cache: Sharded<FxHashMap<K, (V, DepNodeIndex)>>,
27+
cache: Sharded<FxIndexMap<K, (V, DepNodeIndex)>>,
2728
}
2829

2930
impl<K, V> Default for DefaultCache<K, V> {
@@ -44,7 +45,7 @@ where
4445
fn lookup(&self, key: &K) -> Option<(V, DepNodeIndex)> {
4546
let key_hash = sharded::make_hash(key);
4647
let lock = self.cache.lock_shard_by_hash(key_hash);
47-
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
48+
let result = lock.raw_entry_v1().from_key_hashed_nocheck(key_hash, key);
4849

4950
if let Some((_, value)) = result { Some(*value) } else { None }
5051
}

compiler/rustc_query_system/src/query/job.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::hash::Hash;
22
use std::io::Write;
33
use std::num::NonZero;
44

5-
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_errors::{Diag, DiagCtxtHandle};
77
use rustc_hir::def::DefKind;
88
use rustc_session::Session;
@@ -30,7 +30,7 @@ pub struct QueryInfo {
3030
pub query: QueryStackFrame,
3131
}
3232

33-
pub type QueryMap = FxHashMap<QueryJobId, QueryJobInfo>;
33+
pub type QueryMap = FxIndexMap<QueryJobId, QueryJobInfo>;
3434

3535
/// A value uniquely identifying an active query job.
3636
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]

compiler/rustc_query_system/src/query/plumbing.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
//! manage the caches, and so forth.
44
55
use std::cell::Cell;
6-
use std::collections::hash_map::Entry;
76
use std::fmt::Debug;
87
use std::hash::Hash;
98
use std::mem;
109

10+
use indexmap::map::Entry;
1111
use rustc_data_structures::fingerprint::Fingerprint;
12-
use rustc_data_structures::fx::FxHashMap;
12+
use rustc_data_structures::fx::FxIndexMap;
1313
use rustc_data_structures::sharded::Sharded;
1414
use rustc_data_structures::stack::ensure_sufficient_stack;
1515
use rustc_data_structures::sync::Lock;
@@ -33,7 +33,7 @@ use crate::query::{
3333
};
3434

3535
pub struct QueryState<K> {
36-
active: Sharded<FxHashMap<K, QueryResult>>,
36+
active: Sharded<FxIndexMap<K, QueryResult>>,
3737
}
3838

3939
/// Indicates the state of a query for a given key in a query map.
@@ -187,7 +187,7 @@ where
187187
// since unwinding also wants to look at this map, this can also prevent a double
188188
// panic.
189189
let mut lock = state.active.lock_shard_by_value(&key);
190-
lock.remove(&key)
190+
lock.shift_remove(&key)
191191
};
192192
val.unwrap().expect_job()
193193
};
@@ -207,7 +207,7 @@ where
207207
let state = self.state;
208208
let job = {
209209
let mut shard = state.active.lock_shard_by_value(&self.key);
210-
let job = shard.remove(&self.key).unwrap().expect_job();
210+
let job = shard.shift_remove(&self.key).unwrap().expect_job();
211211

212212
shard.insert(self.key, QueryResult::Poisoned);
213213
job

0 commit comments

Comments
 (0)