Skip to content

Shorten some dependency chains in the compiler #145390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

(I recommend reviewing this commit by commit.)

One of the long dependency chains in the compiler is:

  • Many things depend on rustc_errors.
  • rustc_errors depended on many things prior to this PR, including rustc_target, rustc_type_ir, rustc_hir, and rustc_lint_defs.
  • rustc_lint_defs depended on rustc_hir prior to this PR.
  • rustc_hir depends on rustc_target.
  • rustc_target is large and takes a while.

This PR breaks that chain, through a few steps:

  • The IntoDiagArgs trait, from rustc_errors, moves earlier in the dependency chain. This allows rustc_errors to stop depending on a pile of crates just to implement IntoDiagArgs for their types.
  • Split rustc_hir_id out of rustc_hir, so crates that just need HirId and similar don't depend on all of rust_hir (and thus rustc_target).
  • Make rustc_lint_defs stop depending on rustc_hir.

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Aug 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

These commits modify compiler targets.
(See the Target Tier Policy.)

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

@joshtriplett
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 14, 2025
Shorten some dependency chains in the compiler
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 14, 2025
@rust-log-analyzer

This comment was marked as outdated.

@joshtriplett joshtriplett force-pushed the rustc-diag-value-earlier branch from 35d6871 to 54f2e7b Compare August 14, 2025 11:34
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 14, 2025
@joshtriplett
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 14, 2025
Shorten some dependency chains in the compiler
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 14, 2025

☀️ Try build successful (CI)
Build commit: 0847c11 (0847c1164841cdb4610f0754850945481c8e48ff, parent: 2c1ac85679678dfe5cce7ea8037735b0349ceaf3)

@rust-timer

This comment has been minimized.

@Kobzol
Copy link
Member

Kobzol commented Aug 14, 2025

(Not sure if we'll see any changes in the bootstrap timings for this, because bootstrap is benchmarked with -j1, so all crates are compiled serially).

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0847c11): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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)
4.7% [4.7%, 4.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [-0.2%, 4.7%] 3

Max RSS (memory usage)

Results (primary -1.4%)

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

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

Cycles

Results (primary 3.8%)

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

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

Binary size

Results (primary 0.1%, secondary -0.1%)

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

mean range count
Regressions ❌
(primary)
0.3% [0.3%, 0.3%] 3
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 2
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 7
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 7
All ❌✅ (primary) 0.1% [-0.0%, 0.3%] 10

Bootstrap: 470.224s -> 470.269s (0.01%)
Artifact size: 377.49 MiB -> 377.39 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 14, 2025
@joshtriplett
Copy link
Member Author

@Kobzol Fair enough. It's really the CI time that I'm hoping improves here, and that does normal parallel builds.

The clap_derive benchmark seems spurious. Does that seem likely to be noise, here?

@joshtriplett
Copy link
Member Author

@rust-timer build 0847c11 include=clap_derive

@petrochenkov
Copy link
Contributor

Why do rustc_errors and rustc_attr_parsing depend on HirId at all?
That doesn't look right to me from the design point of view.

@Kobzol
Copy link
Member

Kobzol commented Aug 14, 2025

@Kobzol Fair enough. It's really the CI time that I'm hoping improves here, and that does normal parallel builds.

The clap_derive benchmark seems spurious. Does that seem likely to be noise, here?

image

Yeah that's noise. (you can't perf. the same commit twice, btw 😅)

@bjorn3
Copy link
Member

bjorn3 commented Aug 14, 2025

Why do rustc_errors and rustc_attr_parsing depend on HirId at all?
That doesn't look right to me from the design point of view.

rustc_attr_parsing needs the id of the item the attribute was applied to for calling tcx.emit_node_span_lint through a trait defined in rustc_errors.

@joshtriplett
Copy link
Member Author

you can't perf. the same commit twice, btw 😅

TIL. Would be nice to be able to re-run a single perf test.

@joshtriplett joshtriplett removed the perf-regression Performance regression. label Aug 14, 2025
@Kobzol
Copy link
Member

Kobzol commented Aug 14, 2025

We're currently redesigning rustc-perf, maybe in the new version it might work, but I don't promise anything.

@joshtriplett joshtriplett force-pushed the rustc-diag-value-earlier branch from 54f2e7b to e0a9bde Compare August 14, 2025 21:28
@joshtriplett
Copy link
Member Author

Fixed some cases of trait impls that were using a cfg(feature = "nightly")-gated import but not gated themselves.

@rust-log-analyzer

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just make this a module in rustc_span?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we just make this a module in rustc_span?

We could. It'd be straightforward enough to merge. I hadn't because rustc_span is so widely used that I didn't want to make it any larger, and it generally seems easier to merge crates than to split them. (And because I thought that might be a harder sell.)

@joshtriplett joshtriplett force-pushed the rustc-diag-value-earlier branch from e0a9bde to 6ef4052 Compare August 14, 2025 23:48
@rust-log-analyzer

This comment was marked as outdated.

@joshtriplett joshtriplett force-pushed the rustc-diag-value-earlier branch from 6ef4052 to fea6a65 Compare August 15, 2025 00:08
@bors
Copy link
Collaborator

bors commented Aug 15, 2025

☔ The latest upstream changes (presumably #145450) made this pull request unmergeable. Please resolve the merge conflicts.

`rustc_errors` depends on numerous crates, solely to implement its
`IntoDiagArg` trait on types from those crates. Many crates depend on
`rustc_errors`, and it's on the critical path.

We can't swap things around to make all of those crates depend on
`rustc_errors` instead, because `rustc_errors` would end up in
dependency cycles.

Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far
fewer dependencies, and then have most of these crates depend on
`rustc_error_messages`.

This allows `rustc_errors` to drop dependencies on several crates,
including the large `rustc_target`.

(This doesn't fully reduce dependency chains yet, as `rustc_errors`
still depends on `rustc_hir` which depends on `rustc_target`. That will
get fixed in a subsequent commit.)
Some crates depend on `rustc_hir` but only want `HirId` and similar id
types. `rustc_hir` is a heavy dependency, since it pulls in
`rustc_target`. Split these types out into their own crate
`rustc_hir_id`.

This allows `rustc_errors` to drop its direct dependency on `rustc_hir`.

(`rustc_errors` still depends on `rustc_hir` indirectly through
`rustc_lint_defs`; a subsequent commit will fix that.)
`rustc_lint_defs` uses `rustc_hir` solely for the `Namespace` type,
which it only needs the static description from. Use the static
description directly, to eliminate the dependency on `rustc_hir`.

This reduces a long dependency chain:
- Many things depend on `rustc_errors`
- `rustc_errors` depends on `rustc_lint_defs`
- `rustc_lint_defs` depended on `rustc_hir` prior to this commit
- `rustc_hir` depends on `rustc_target`
…hir`

`rustc_mir_dataflow` only uses `DefId`, which is a re-export from
`rustc_span`.
`rustc_traits` only uses `DefId`, which is a re-export from
`rustc_span`.
@joshtriplett joshtriplett force-pushed the rustc-diag-value-earlier branch from fea6a65 to 76ec917 Compare August 16, 2025 11:29
@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2025

This PR was rebased onto a different master commit! Check out the changes with our range-diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

10 participants