Skip to content

Commit 701b11a

Browse files
committed
Rename JobOwner to ActiveJobGuard
This commit also adds and updates some relevant comments.
1 parent 1c316d3 commit 701b11a

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

compiler/rustc_middle/src/ty/context/tls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pub struct ImplicitCtxt<'a, 'tcx> {
1616
/// The current `TyCtxt`.
1717
pub tcx: TyCtxt<'tcx>,
1818

19-
/// The current query job, if any. This is updated by `JobOwner::start` in
20-
/// `ty::query::plumbing` when executing a query.
19+
/// The current query job, if any.
2120
pub query: Option<QueryJobId>,
2221

2322
/// Used to prevent queries from calling too deeply.

compiler/rustc_query_impl/src/execution.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>(
8383
Some(())
8484
}
8585

86-
/// A type representing the responsibility to execute the job in the `job` field.
87-
/// This will poison the relevant query if dropped.
88-
struct JobOwner<'tcx, K>
86+
/// Guard object representing the responsibility to execute a query job and
87+
/// mark it as completed.
88+
///
89+
/// This will poison the relevant query key if it is dropped without calling
90+
/// [`Self::complete`].
91+
struct ActiveJobGuard<'tcx, K>
8992
where
9093
K: Eq + Hash + Copy,
9194
{
@@ -139,12 +142,12 @@ where
139142
}
140143
}
141144

142-
impl<'tcx, K> JobOwner<'tcx, K>
145+
impl<'tcx, K> ActiveJobGuard<'tcx, K>
143146
where
144147
K: Eq + Hash + Copy,
145148
{
146149
/// Completes the query by updating the query cache with the `result`,
147-
/// signals the waiter and forgets the JobOwner, so it won't poison the query
150+
/// signals the waiter, and forgets the guard so it won't poison the query.
148151
fn complete<C>(self, cache: &C, key_hash: u64, result: C::Value, dep_node_index: DepNodeIndex)
149152
where
150153
C: QueryCache<Key = K>,
@@ -176,7 +179,7 @@ where
176179
}
177180
}
178181

179-
impl<'tcx, K> Drop for JobOwner<'tcx, K>
182+
impl<'tcx, K> Drop for ActiveJobGuard<'tcx, K>
180183
where
181184
K: Eq + Hash + Copy,
182185
{
@@ -356,11 +359,13 @@ fn execute_job<'tcx, Q, const INCR: bool>(
356359
where
357360
Q: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>,
358361
{
359-
// Use `JobOwner` so the query will be poisoned if executing it panics.
360-
let job_owner = JobOwner { state, key };
362+
// Set up a guard object that will automatically poison the query if a
363+
// panic occurs while executing the query (or any intermediate plumbing).
364+
let job_guard = ActiveJobGuard { state, key };
361365

362366
debug_assert_eq!(qcx.tcx.dep_graph.is_fully_enabled(), INCR);
363367

368+
// Delegate to another function to actually execute the query job.
364369
let (result, dep_node_index) = if INCR {
365370
execute_job_incr(query, qcx, qcx.tcx.dep_graph.data().unwrap(), key, dep_node, id)
366371
} else {
@@ -402,7 +407,9 @@ where
402407
}
403408
}
404409
}
405-
job_owner.complete(cache, key_hash, result, dep_node_index);
410+
411+
// Tell the guard to perform completion bookkeeping, and also to not poison the query.
412+
job_guard.complete(cache, key_hash, result, dep_node_index);
406413

407414
(result, Some(dep_node_index))
408415
}

0 commit comments

Comments
 (0)