Skip to content

Commit f16da8b

Browse files
authored
Unrolled build for #153997
Rollup merge of #153997 - nnethercote:closure-consistency, r=petrochenkov Use closures more consistently in `dep_graph.rs`. This file has several methods that take a `FnOnce() -> R` closure: - `DepGraph::with_ignore` - `DepGraph::with_query_deserialization` - `DepGraph::with_anon_task` - `DepGraphData::with_anon_task_inner` It also has two methods that take a faux closure via an `A` argument and a `fn(TyCtxt<'tcx>, A) -> R` argument: - DepGraph::with_task - DepGraphData::with_task The rationale is that the faux closure exercises tight control over what state they have access to. This seems silly when (a) they are passed a `TyCtxt`, and (b) when similar nearby functions take real closures. And they are more awkward to use, e.g. requiring multiple arguments to be gathered into a tuple. This commit changes the faux closures to real closures. r? @Zalathar
2 parents 14196db + deb901c commit f16da8b

6 files changed

Lines changed: 35 additions & 47 deletions

File tree

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,9 @@ fn codegen_cgu_content(
380380

381381
fn module_codegen(
382382
tcx: TyCtxt<'_>,
383-
(global_asm_config, cgu_name, token): (
384-
Arc<GlobalAsmConfig>,
385-
rustc_span::Symbol,
386-
ConcurrencyLimiterToken,
387-
),
383+
global_asm_config: Arc<GlobalAsmConfig>,
384+
cgu_name: rustc_span::Symbol,
385+
token: ConcurrencyLimiterToken,
388386
) -> OngoingModuleCodegen {
389387
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
390388

@@ -513,8 +511,14 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
513511
let (module, _) = tcx.dep_graph.with_task(
514512
dep_node,
515513
tcx,
516-
(global_asm_config.clone(), cgu.name(), concurrency_limiter.acquire(tcx.dcx())),
517-
module_codegen,
514+
|| {
515+
module_codegen(
516+
tcx,
517+
global_asm_config.clone(),
518+
cgu.name(),
519+
concurrency_limiter.acquire(tcx.dcx()),
520+
)
521+
},
518522
Some(rustc_middle::dep_graph::hash_result),
519523
);
520524
IntoDynSyncSend(module)

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ pub fn compile_codegen_unit(
8383
let (module, _) = tcx.dep_graph.with_task(
8484
dep_node,
8585
tcx,
86-
(cgu_name, target_info, lto_supported),
87-
module_codegen,
86+
|| module_codegen(tcx, cgu_name, target_info, lto_supported),
8887
Some(dep_graph::hash_result),
8988
);
9089
let time_to_codegen = start_time.elapsed();
@@ -96,7 +95,9 @@ pub fn compile_codegen_unit(
9695

9796
fn module_codegen(
9897
tcx: TyCtxt<'_>,
99-
(cgu_name, target_info, lto_supported): (Symbol, LockedTargetInfo, bool),
98+
cgu_name: Symbol,
99+
target_info: LockedTargetInfo,
100+
lto_supported: bool,
100101
) -> ModuleCodegen<GccContext> {
101102
let cgu = tcx.codegen_unit(cgu_name);
102103
// Instantiate monomorphizations without filling out definitions yet...

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ pub(crate) fn compile_codegen_unit(
6565
let (module, _) = tcx.dep_graph.with_task(
6666
dep_node,
6767
tcx,
68-
cgu_name,
69-
module_codegen,
68+
|| module_codegen(tcx, cgu_name),
7069
Some(dep_graph::hash_result),
7170
);
7271
let time_to_codegen = start_time.elapsed();

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,8 +2477,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
24772477
tcx.dep_graph.with_task(
24782478
dep_node,
24792479
tcx,
2480-
path,
2481-
|tcx, path| {
2480+
|| {
24822481
with_encode_metadata_header(tcx, path, |ecx| {
24832482
// Encode all the entries and extra information in the crate,
24842483
// culminating in the `CrateRoot` which points to all of it.

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum QuerySideEffect {
5252
/// the side effect dep node as a dependency.
5353
CheckFeature { symbol: Symbol },
5454
}
55+
5556
#[derive(Clone)]
5657
pub struct DepGraph {
5758
data: Option<Arc<DepGraphData>>,
@@ -274,17 +275,19 @@ impl DepGraph {
274275
}
275276

276277
#[inline(always)]
277-
pub fn with_task<'tcx, A: Debug, R>(
278+
pub fn with_task<'tcx, OP, R>(
278279
&self,
279280
dep_node: DepNode,
280281
tcx: TyCtxt<'tcx>,
281-
task_arg: A,
282-
task_fn: fn(tcx: TyCtxt<'tcx>, task_arg: A) -> R,
282+
op: OP,
283283
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
284-
) -> (R, DepNodeIndex) {
284+
) -> (R, DepNodeIndex)
285+
where
286+
OP: FnOnce() -> R,
287+
{
285288
match self.data() {
286-
Some(data) => data.with_task(dep_node, tcx, task_arg, task_fn, hash_result),
287-
None => (task_fn(tcx, task_arg), self.next_virtual_depnode_index()),
289+
Some(data) => data.with_task(dep_node, tcx, op, hash_result),
290+
None => (op(), self.next_virtual_depnode_index()),
288291
}
289292
}
290293

@@ -309,44 +312,27 @@ impl DepGraph {
309312
}
310313

311314
impl DepGraphData {
312-
/// Starts a new dep-graph task. Dep-graph tasks are specified
313-
/// using a free function (`task`) and **not** a closure -- this
314-
/// is intentional because we want to exercise tight control over
315-
/// what state they have access to. In particular, we want to
316-
/// prevent implicit 'leaks' of tracked state into the task (which
317-
/// could then be read without generating correct edges in the
318-
/// dep-graph -- see the [rustc dev guide] for more details on
319-
/// the dep-graph).
320-
///
321-
/// Therefore, the task function takes a `TyCtxt`, plus exactly one
322-
/// additional argument, `task_arg`. The additional argument type can be
323-
/// `()` if no argument is needed, or a tuple if multiple arguments are
324-
/// needed.
325-
///
326-
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
327315
#[inline(always)]
328-
pub fn with_task<'tcx, A: Debug, R>(
316+
pub fn with_task<'tcx, OP, R>(
329317
&self,
330318
dep_node: DepNode,
331319
tcx: TyCtxt<'tcx>,
332-
task_arg: A,
333-
task_fn: fn(tcx: TyCtxt<'tcx>, task_arg: A) -> R,
320+
op: OP,
334321
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
335-
) -> (R, DepNodeIndex) {
322+
) -> (R, DepNodeIndex)
323+
where
324+
OP: FnOnce() -> R,
325+
{
336326
// If the following assertion triggers, it can have two reasons:
337327
// 1. Something is wrong with DepNode creation, either here or
338328
// in `DepGraph::try_mark_green()`.
339329
// 2. Two distinct query keys get mapped to the same `DepNode`
340330
// (see for example #48923).
341331
self.assert_dep_node_not_yet_allocated_in_current_session(tcx.sess, &dep_node, || {
342-
format!(
343-
"forcing query with already existing `DepNode`\n\
344-
- query-key: {task_arg:?}\n\
345-
- dep-node: {dep_node:?}"
346-
)
332+
format!("forcing query with already existing `DepNode`: {dep_node:?}")
347333
});
348334

349-
let with_deps = |task_deps| with_deps(task_deps, || task_fn(tcx, task_arg));
335+
let with_deps = |task_deps| with_deps(task_deps, op);
350336
let (result, edges) = if tcx.is_eval_always(dep_node.kind) {
351337
(with_deps(TaskDepsRef::EvalAlways), EdgesVec::new())
352338
} else {

compiler/rustc_query_impl/src/execution.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ fn execute_job_incr<'tcx, C: QueryCache>(
447447
dep_graph_data.with_task(
448448
dep_node,
449449
tcx,
450-
(query, key),
451-
|tcx, (query, key)| (query.invoke_provider_fn)(tcx, key),
450+
|| (query.invoke_provider_fn)(tcx, key),
452451
query.hash_value_fn,
453452
)
454453
});

0 commit comments

Comments
 (0)