Skip to content

Use closures more consistently in dep_graph.rs.#153997

Open
nnethercote wants to merge 1 commit intorust-lang:mainfrom
nnethercote:closure-consistency
Open

Use closures more consistently in dep_graph.rs.#153997
nnethercote wants to merge 1 commit intorust-lang:mainfrom
nnethercote:closure-consistency

Conversation

@nnethercote
Copy link
Contributor

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

It's not clear why these two are different. They are more awkward to use, e.g. requiring multiple arguments to be gathered into a tuple. This commit changes the latter cases to closures.

The commit also changes the types and names of the closures from the awkward op: OP to the more standard f: F.

r? @Zalathar

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

It's not clear why these two are different. They are more awkward to
use, e.g. requiring multiple arguments to be gathered into a tuple. This
commit changes the latter cases to closures.

The commit also changes the types and names of the closures from
the awkward `op: OP` to the more standard `f: F`.
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2026

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Mar 17, 2026
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2026

Zalathar is not on the review rotation at the moment.
They may take a while to respond.

@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 17, 2026
Use closures more consistently in `dep_graph.rs`.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 17, 2026
}

pub fn with_ignore<OP, R>(&self, op: OP) -> R
pub fn with_ignore<F, R>(&self, f: F) -> R
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn with_ignore<F, R>(&self, f: F) -> R
pub fn with_ignore<R>(&self, f: impl FnOnce() -> R) -> R

I prefer using APITs because then you don't have to think whether to name it F or OP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I generally prefer impl Fn* if there isn't a specific need to name the function type.

@Zalathar
Copy link
Member

Based on comments, I think there was historically a desire to make sure that dep-graph tasks didn't accidentally pull in other untracked state via closure capture.

But given the existing inconsistency, and the fact that passing tcx gives access to the kitchen sink anyway, there probably isn't any harm in just using normal closures at this point.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 17, 2026

☀️ Try build successful (CI)
Build commit: 283c322 (283c322d1c3e0fd24ba3187d32027674e634f7e5, parent: b711f95f86b6489b91fdc55c876ed5f95a8d4560)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (283c322): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary -1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.5%, -1.3%] 2
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) - - 0

Bootstrap: 481.409s -> 481.18s (-0.05%)
Artifact size: 394.91 MiB -> 396.71 MiB (0.45%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants