Skip to content

Move metadata generation #145834

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 1 commit into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

It's currently done within start_codegen, which is called from codegen_and_build_linker, and it gets included in the codegen timing section. All this is surprising, because it's not part of codegen.

This commit moves it into run_compiler, just before the call to codegen_and_build_linker. This is a more sensible place for it. The commit also adds some extra non-obvious information about the has_errors_or_delayed_bugs check, which I learned when I tried moving metadata generation earlier.

Likewise, the nearby rustc_delayed_bug_from_inside_query code is also moved, because (a) it's not part of codegen, and (b) it needs to be nearby.

r? @bjorn3

It's currently done within `start_codegen`, which is called from
`codegen_and_build_linker`, and it gets included in the codegen timing
section. All this is surprising, because it's not part of codegen.

This commit moves it into `run_compiler`, just before the call to
`codegen_and_build_linker`. This is a more sensible place for it.
The commit also adds some extra non-obvious information about the
`has_errors_or_delayed_bugs` check, which I learned when I tried
moving metadata generation earlier.

Likewise, the nearby `rustc_delayed_bug_from_inside_query` code is also
moved, because (a) it's not part of codegen, and (b) it needs to be
nearby.
@nnethercote nnethercote marked this pull request as ready for review August 25, 2025 05:34
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2025
@nnethercote
Copy link
Contributor Author

The background here: I was trying to see if metadata generation could be moved significantly earlier to increase the amount of overlap provided by compilation pipelining. This turns out to be difficult; lots of things start to break if metadata generation precedes some or all of analysis. But I figured I could do this cleanup and improve some comments with some things I learned.

@Kobzol
Copy link
Member

Kobzol commented Aug 25, 2025

Oh, I guess that metadata generation was part of the "backend" section, as recorded in rustc-perf and --json=timings. But I suppose that it does indeed make more sense to move it to the "frontend" section, as metadata generation also happens in cargo check.

// during codegen, obscuring the original problem.
if let Some(guar) = tcx.sess.dcx().has_errors_or_delayed_bugs() {
guar.raise_fatal();
}
Copy link
Member

Choose a reason for hiding this comment

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

This way it is easy to forget to call this function before calling codegen_and_build_linker. rustc_interface is meant to be called directly by custom drivers if rustc_driver doesn't provide enough flexibility. For example for rustdoc. mutest-rs also uses it directly. Also by moving this call before report_symbol_names, errors in the latter no longer block codegen. Maybe instead just move the tcx.sess.timings.start_section(tcx.sess.dcx(), TimingSection::Codegen); later in codegen_and_build_linker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

4 participants