Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle rustc_query_system cases of rustc::potential_query_instability lint #131200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/fx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::hash::BuildHasherDefault;

pub use indexmap::map::RawEntryApiV1 as IndexRawEntryApiV1;
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};

pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::assert_matches::assert_matches;
use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
use std::sync::Arc;
use std::sync::atomic::Ordering;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, IndexEntry};
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -1054,7 +1053,7 @@ rustc_index::newtype_index! {
/// first, and `data` second.
pub(super) struct CurrentDepGraph<D: Deps> {
encoder: GraphEncoder<D>,
new_node_to_index: Sharded<FxHashMap<DepNode, DepNodeIndex>>,
new_node_to_index: Sharded<FxIndexMap<DepNode, DepNodeIndex>>,
prev_index_to_index: Lock<IndexVec<SerializedDepNodeIndex, Option<DepNodeIndex>>>,

/// This is used to verify that fingerprints do not change between the creation of a node
Expand Down Expand Up @@ -1124,7 +1123,7 @@ impl<D: Deps> CurrentDepGraph<D> {
previous,
),
new_node_to_index: Sharded::new(|| {
FxHashMap::with_capacity_and_hasher(
FxIndexMap::with_capacity_and_hasher(
new_node_count_estimate / sharded::shards(),
Default::default(),
)
Expand Down Expand Up @@ -1159,8 +1158,8 @@ impl<D: Deps> CurrentDepGraph<D> {
current_fingerprint: Fingerprint,
) -> DepNodeIndex {
let dep_node_index = match self.new_node_to_index.lock_shard_by_value(&key).entry(key) {
Entry::Occupied(entry) => *entry.get(),
Entry::Vacant(entry) => {
IndexEntry::Occupied(entry) => *entry.get(),
IndexEntry::Vacant(entry) => {
let dep_node_index = self.encoder.send(key, current_fingerprint, edges);
entry.insert(dep_node_index);
dep_node_index
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::marker::PhantomData;
use std::sync::Arc;

use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::outline;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock;
Expand Down Expand Up @@ -472,7 +472,7 @@ struct EncoderState<D: Deps> {
encoder: FileEncoder,
total_node_count: usize,
total_edge_count: usize,
stats: Option<FxHashMap<DepKind, Stat>>,
stats: Option<FxIndexMap<DepKind, Stat>>,

/// Stores the number of times we've encoded each dep kind.
kind_stats: Vec<u32>,
Expand All @@ -486,7 +486,7 @@ impl<D: Deps> EncoderState<D> {
encoder,
total_edge_count: 0,
total_node_count: 0,
stats: record_stats.then(FxHashMap::default),
stats: record_stats.then(FxIndexMap::default),
kind_stats: iter::repeat(0).take(D::DEP_KIND_MAX as usize + 1).collect(),
marker: PhantomData,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tidy-alphabetical-start
#![allow(rustc::potential_query_instability, internal_features)]
#![allow(internal_features)]
#![feature(assert_matches)]
#![feature(core_intrinsics)]
#![feature(hash_raw_entry)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_query_system/src/query/caches.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;
use std::hash::Hash;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxIndexMap, IndexRawEntryApiV1};
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::sync::{Lock, OnceLock};
use rustc_hir::def_id::LOCAL_CRATE;
Expand All @@ -23,7 +23,7 @@ pub trait QueryCache: Sized {
}

pub struct DefaultCache<K, V> {
cache: Sharded<FxHashMap<K, (V, DepNodeIndex)>>,
cache: Sharded<FxIndexMap<K, (V, DepNodeIndex)>>,
}

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

if let Some((_, value)) = result { Some(*value) } else { None }
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::hash::Hash;
use std::io::Write;
use std::num::NonZero;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::{Diag, DiagCtxtHandle};
use rustc_hir::def::DefKind;
use rustc_session::Session;
Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct QueryInfo {
pub query: QueryStackFrame,
}

pub type QueryMap = FxHashMap<QueryJobId, QueryJobInfo>;
pub type QueryMap = FxIndexMap<QueryJobId, QueryJobInfo>;

/// A value uniquely identifying an active query job.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//! manage the caches, and so forth.

use std::cell::Cell;
use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
use rustc_data_structures::sharded::Sharded;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::Lock;
Expand All @@ -33,7 +32,7 @@ use crate::query::{
};

pub struct QueryState<K> {
active: Sharded<FxHashMap<K, QueryResult>>,
active: Sharded<FxIndexMap<K, QueryResult>>,
}

/// Indicates the state of a query for a given key in a query map.
Expand Down Expand Up @@ -187,7 +186,7 @@ where
// since unwinding also wants to look at this map, this can also prevent a double
// panic.
let mut lock = state.active.lock_shard_by_value(&key);
lock.remove(&key)
lock.shift_remove(&key)
};
val.unwrap().expect_job()
};
Expand All @@ -207,7 +206,7 @@ where
let state = self.state;
let job = {
let mut shard = state.active.lock_shard_by_value(&self.key);
let job = shard.remove(&self.key).unwrap().expect_job();
let job = shard.shift_remove(&self.key).unwrap().expect_job();

shard.insert(self.key, QueryResult::Poisoned);
job
Expand Down Expand Up @@ -344,7 +343,7 @@ where
let current_job_id = qcx.current_query_job();

match state_lock.entry(key) {
Entry::Vacant(entry) => {
IndexEntry::Vacant(entry) => {
// Nothing has computed or is computing the query, so we start a new job and insert it in the
// state map.
let id = qcx.next_job_id();
Expand All @@ -356,7 +355,7 @@ where

execute_job::<_, _, INCR>(query, qcx, state, key, id, dep_node)
}
Entry::Occupied(mut entry) => {
IndexEntry::Occupied(mut entry) => {
match entry.get_mut() {
QueryResult::Started(job) => {
#[cfg(parallel_compiler)]
Expand Down
Loading