summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_query_system
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_query_system
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_query_system')
-rw-r--r--compiler/rustc_query_system/src/dep_graph/dep_node.rs13
-rw-r--r--compiler/rustc_query_system/src/dep_graph/graph.rs11
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs31
-rw-r--r--compiler/rustc_query_system/src/values.rs7
4 files changed, 39 insertions, 23 deletions
diff --git a/compiler/rustc_query_system/src/dep_graph/dep_node.rs b/compiler/rustc_query_system/src/dep_graph/dep_node.rs
index 9e1ca6ab5..39a4cb1b1 100644
--- a/compiler/rustc_query_system/src/dep_graph/dep_node.rs
+++ b/compiler/rustc_query_system/src/dep_graph/dep_node.rs
@@ -46,7 +46,7 @@ use super::{DepContext, DepKind, FingerprintStyle};
use crate::ich::StableHashingContext;
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_hir::definitions::DefPathHash;
use std::fmt;
use std::hash::Hash;
@@ -247,3 +247,14 @@ impl<HCX> HashStable<HCX> for WorkProductId {
self.hash.hash_stable(hcx, hasher)
}
}
+impl<HCX> ToStableHashKey<HCX> for WorkProductId {
+ type KeyType = Fingerprint;
+ #[inline]
+ fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
+ self.hash
+ }
+}
+unsafe impl StableOrd for WorkProductId {
+ // Fingerprint can use unstable (just a tuple of `u64`s), so WorkProductId can as well
+ const CAN_USE_UNSTABLE_SORT: bool = true;
+}
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs
index c0d7386dd..c9e80a6d9 100644
--- a/compiler/rustc_query_system/src/dep_graph/graph.rs
+++ b/compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -1,11 +1,12 @@
use parking_lot::Mutex;
use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef};
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
+use rustc_data_structures::unord::UnordMap;
use rustc_index::IndexVec;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use smallvec::{smallvec, SmallVec};
@@ -93,7 +94,7 @@ pub struct DepGraphData<K: DepKind> {
/// things available to us. If we find that they are not dirty, we
/// load the path to the file storing those work-products here into
/// this map. We can later look for and extract that data.
- previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
+ previous_work_products: FxIndexMap<WorkProductId, WorkProduct>,
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
@@ -116,7 +117,7 @@ impl<K: DepKind> DepGraph<K> {
pub fn new(
profiler: &SelfProfilerRef,
prev_graph: SerializedDepGraph<K>,
- prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
+ prev_work_products: FxIndexMap<WorkProductId, WorkProduct>,
encoder: FileEncoder,
record_graph: bool,
record_stats: bool,
@@ -688,7 +689,7 @@ impl<K: DepKind> DepGraph<K> {
/// Access the map of work-products created during the cached run. Only
/// used during saving of the dep-graph.
- pub fn previous_work_products(&self) -> &FxHashMap<WorkProductId, WorkProduct> {
+ pub fn previous_work_products(&self) -> &FxIndexMap<WorkProductId, WorkProduct> {
&self.data.as_ref().unwrap().previous_work_products
}
@@ -1048,7 +1049,7 @@ pub struct WorkProduct {
///
/// By convention, file extensions are currently used as identifiers, i.e. the key "o" maps to
/// the object file's path, and "dwo" to the dwarf object file's path.
- pub saved_files: FxHashMap<String, String>,
+ pub saved_files: UnordMap<String, String>,
}
// Index type for `DepNodeData`'s edges.
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index 730e4c8d3..4adb4eb74 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -69,6 +69,8 @@ where
make_query: fn(Qcx, K) -> QueryStackFrame<D>,
jobs: &mut QueryMap<D>,
) -> Option<()> {
+ let mut active = Vec::new();
+
#[cfg(parallel_compiler)]
{
// We use try_lock_shards here since we are called from the
@@ -77,8 +79,7 @@ where
for shard in shards.iter() {
for (k, v) in shard.iter() {
if let QueryResult::Started(ref job) = *v {
- let query = make_query(qcx, *k);
- jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
+ active.push((*k, job.clone()));
}
}
}
@@ -91,12 +92,18 @@ where
// really hurt much.)
for (k, v) in self.active.try_lock()?.iter() {
if let QueryResult::Started(ref job) = *v {
- let query = make_query(qcx, *k);
- jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
+ active.push((*k, job.clone()));
}
}
}
+ // Call `make_query` while we're not holding a `self.active` lock as `make_query` may call
+ // queries leading to a deadlock.
+ for (key, job) in active {
+ let query = make_query(qcx, key);
+ jobs.insert(job.id, QueryJobInfo { query, job });
+ }
+
Some(())
}
}
@@ -119,18 +126,13 @@ where
#[cold]
#[inline(never)]
-fn mk_cycle<Q, Qcx>(
- query: Q,
- qcx: Qcx,
- cycle_error: CycleError<Qcx::DepKind>,
- handler: HandleCycleError,
-) -> Q::Value
+fn mk_cycle<Q, Qcx>(query: Q, qcx: Qcx, cycle_error: CycleError<Qcx::DepKind>) -> Q::Value
where
Q: QueryConfig<Qcx>,
Qcx: QueryContext,
{
let error = report_cycle(qcx.dep_context().sess(), &cycle_error);
- handle_cycle_error(query, qcx, &cycle_error, error, handler)
+ handle_cycle_error(query, qcx, &cycle_error, error)
}
fn handle_cycle_error<Q, Qcx>(
@@ -138,14 +140,13 @@ fn handle_cycle_error<Q, Qcx>(
qcx: Qcx,
cycle_error: &CycleError<Qcx::DepKind>,
mut error: DiagnosticBuilder<'_, ErrorGuaranteed>,
- handler: HandleCycleError,
) -> Q::Value
where
Q: QueryConfig<Qcx>,
Qcx: QueryContext,
{
use HandleCycleError::*;
- match handler {
+ match query.handle_cycle_error() {
Error => {
error.emit();
query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
@@ -270,7 +271,7 @@ where
&qcx.current_query_job(),
span,
);
- (mk_cycle(query, qcx, error, query.handle_cycle_error()), None)
+ (mk_cycle(query, qcx, error), None)
}
#[inline(always)]
@@ -307,7 +308,7 @@ where
(v, Some(index))
}
- Err(cycle) => (mk_cycle(query, qcx, cycle, query.handle_cycle_error()), None),
+ Err(cycle) => (mk_cycle(query, qcx, cycle), None),
}
}
diff --git a/compiler/rustc_query_system/src/values.rs b/compiler/rustc_query_system/src/values.rs
index b6e2cfa3d..ce551078c 100644
--- a/compiler/rustc_query_system/src/values.rs
+++ b/compiler/rustc_query_system/src/values.rs
@@ -6,10 +6,13 @@ pub trait Value<Tcx: DepContext, D: DepKind>: Sized {
}
impl<Tcx: DepContext, T, D: DepKind> Value<Tcx, D> for T {
- default fn from_cycle_error(tcx: Tcx, _: &[QueryInfo<D>]) -> T {
+ default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo<D>]) -> T {
tcx.sess().abort_if_errors();
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
// non-trivial to define it earlier.
- panic!("Value::from_cycle_error called without errors");
+ panic!(
+ "<{} as Value>::from_cycle_error called without errors: {cycle:#?}",
+ std::any::type_name::<T>()
+ );
}
}