Skip to content

Commit 878374e

Browse files
committed
Auto merge of rust-lang#151937 - Zalathar:rollup-WdVeaxy, r=Zalathar
Rollup of 3 pull requests Successful merges: - rust-lang#151927 (typeck_root_def_id: improve doc comment) - rust-lang#151907 (Rename `QueryResult` to `ActiveKeyStatus`) - rust-lang#151928 (ty::context: clean some code a little)
2 parents a1db344 + 191c915 commit 878374e

3 files changed

Lines changed: 29 additions & 22 deletions

File tree

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,10 +3470,9 @@ impl<'tcx> TyCtxt<'tcx> {
34703470

34713471
pub fn intrinsic(self, def_id: impl IntoQueryParam<DefId> + Copy) -> Option<ty::IntrinsicDef> {
34723472
match self.def_kind(def_id) {
3473-
DefKind::Fn | DefKind::AssocFn => {}
3474-
_ => return None,
3473+
DefKind::Fn | DefKind::AssocFn => self.intrinsic_raw(def_id),
3474+
_ => None,
34753475
}
3476-
self.intrinsic_raw(def_id)
34773476
}
34783477

34793478
pub fn next_trait_solver_globally(self) -> bool {

compiler/rustc_middle/src/ty/util.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,8 @@ impl<'tcx> TyCtxt<'tcx> {
642642
/// has its own type-checking context or "inference environment".
643643
///
644644
/// For example, a closure has its own `DefId`, but it is type-checked
645-
/// with the containing item. Similarly, an inline const block has its
646-
/// own `DefId` but it is type-checked together with the containing item.
647-
///
648-
/// Therefore, when we fetch the
649-
/// `typeck` the closure, for example, we really wind up
650-
/// fetching the `typeck` the enclosing fn item.
645+
/// with the containing item. Therefore, when we fetch the `typeck` of the closure,
646+
/// for example, we really wind up fetching the `typeck` of the enclosing fn item.
651647
pub fn typeck_root_def_id(self, def_id: DefId) -> DefId {
652648
let mut def_id = def_id;
653649
while self.is_typeck_child(def_id) {

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,34 @@ fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
3333
move |x| x.0 == *k
3434
}
3535

36+
/// For a particular query, keeps track of "active" keys, i.e. keys whose
37+
/// evaluation has started but has not yet finished successfully.
38+
///
39+
/// (Successful query evaluation for a key is represented by an entry in the
40+
/// query's in-memory cache.)
3641
pub struct QueryState<'tcx, K> {
37-
active: Sharded<hash_table::HashTable<(K, QueryResult<'tcx>)>>,
42+
active: Sharded<hash_table::HashTable<(K, ActiveKeyStatus<'tcx>)>>,
3843
}
3944

40-
/// Indicates the state of a query for a given key in a query map.
41-
enum QueryResult<'tcx> {
42-
/// An already executing query. The query job can be used to await for its completion.
45+
/// For a particular query and key, tracks the status of a query evaluation
46+
/// that has started, but has not yet finished successfully.
47+
///
48+
/// (Successful query evaluation for a key is represented by an entry in the
49+
/// query's in-memory cache.)
50+
enum ActiveKeyStatus<'tcx> {
51+
/// Some thread is already evaluating the query for this key.
52+
///
53+
/// The enclosed [`QueryJob`] can be used to wait for it to finish.
4354
Started(QueryJob<'tcx>),
4455

4556
/// The query panicked. Queries trying to wait on this will raise a fatal error which will
4657
/// silently panic.
4758
Poisoned,
4859
}
4960

50-
impl<'tcx> QueryResult<'tcx> {
51-
/// Unwraps the query job expecting that it has started.
61+
impl<'tcx> ActiveKeyStatus<'tcx> {
62+
/// Obtains the enclosed [`QueryJob`], or panics if this query evaluation
63+
/// was poisoned by a panic.
5264
fn expect_job(self) -> QueryJob<'tcx> {
5365
match self {
5466
Self::Started(job) => job,
@@ -76,9 +88,9 @@ where
7688
) -> Option<()> {
7789
let mut active = Vec::new();
7890

79-
let mut collect = |iter: LockGuard<'_, HashTable<(K, QueryResult<'tcx>)>>| {
91+
let mut collect = |iter: LockGuard<'_, HashTable<(K, ActiveKeyStatus<'tcx>)>>| {
8092
for (k, v) in iter.iter() {
81-
if let QueryResult::Started(ref job) = *v {
93+
if let ActiveKeyStatus::Started(ref job) = *v {
8294
active.push((*k, job.clone()));
8395
}
8496
}
@@ -222,7 +234,7 @@ where
222234
Err(_) => panic!(),
223235
Ok(occupied) => {
224236
let ((key, value), vacant) = occupied.remove();
225-
vacant.insert((key, QueryResult::Poisoned));
237+
vacant.insert((key, ActiveKeyStatus::Poisoned));
226238
value.expect_job()
227239
}
228240
}
@@ -319,7 +331,7 @@ where
319331
let shard = query.query_state(qcx).active.lock_shard_by_hash(key_hash);
320332
match shard.find(key_hash, equivalent_key(&key)) {
321333
// The query we waited on panicked. Continue unwinding here.
322-
Some((_, QueryResult::Poisoned)) => FatalError.raise(),
334+
Some((_, ActiveKeyStatus::Poisoned)) => FatalError.raise(),
323335
_ => panic!(
324336
"query '{}' result must be in the cache or the query must be poisoned after a wait",
325337
query.name()
@@ -373,7 +385,7 @@ where
373385
// state map.
374386
let id = qcx.next_job_id();
375387
let job = QueryJob::new(id, span, current_job_id);
376-
entry.insert((key, QueryResult::Started(job)));
388+
entry.insert((key, ActiveKeyStatus::Started(job)));
377389

378390
// Drop the lock before we start executing the query
379391
drop(state_lock);
@@ -382,7 +394,7 @@ where
382394
}
383395
Entry::Occupied(mut entry) => {
384396
match &mut entry.get_mut().1 {
385-
QueryResult::Started(job) => {
397+
ActiveKeyStatus::Started(job) => {
386398
if sync::is_dyn_thread_safe() {
387399
// Get the latch out
388400
let latch = job.latch();
@@ -400,7 +412,7 @@ where
400412
// so we just return the error.
401413
cycle_error(query, qcx, id, span)
402414
}
403-
QueryResult::Poisoned => FatalError.raise(),
415+
ActiveKeyStatus::Poisoned => FatalError.raise(),
404416
}
405417
}
406418
}

0 commit comments

Comments
 (0)