Skip to content

Add Validation and FullAnalysis output types, allow for early returns - #163670

Open
blyxyas wants to merge 1 commit into
rust-lang:mainfrom
blyxyas:go-to-stage-flag
Open

blyxyas wants to merge 1 commit into
rust-lang:mainfrom
blyxyas:go-to-stage-flag

Conversation

@blyxyas

@blyxyas blyxyas commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

View all comments

View all comments

Add a Validation and FullAnalysis nightly output type. This allows us to encode metadata and exit both before and after executing analysis.

Old Body

Adds a go-to-stage flag, this flag makes the compiler exit after a certain stage. Currently it recognizes end (the default which is effectively a no-op), analysis for stopping after analysis and
nameres for stopping just after name resolution.

analysis is similar to --emit=metadata without link, and nameres will be used for the probe run in Cargo (See blyxyas/incr-systems#4)

Related to blyxyas/incr-systems#3 and rust-lang/goals#641
r? @jackh726

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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 Oct 2, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@jackh726 jackh726 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we should add a new flag here - I think we should be reusing --emit.

I think we likely need a couple things:

  1. We need to ANALYSIS and ANALYSIS_FULL (or similar) output types to stop immediately after required and full analyses.
  2. I don't think we should be doing something like "if emitting depinfo and nothing else" but rather "needs XYZ". Because we may want to do `--emit=depinfo,metadata"

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 5, 2026
@blyxyas blyxyas changed the title Add unstable go-to-stage option Add Validation and FullAnalysis output types, allow for early returns Oct 8, 2026
@rust-log-analyzer

This comment has been minimized.

@jackh726 jackh726 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few thoughts. Please squash too.

View changes since this review

Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved
Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved
Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved

@celinval celinval left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have a question, should the new output types be behind a unstable flag?

View changes since this review

Comment thread compiler/rustc_session/src/config.rs Outdated
shorthand: "validation",
extension: "rmeta",
description: "Generates metadata and exits after doing only validation and required analysis",
default_filename: "libCRATE_NAME.rmeta",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you considered giving it either a different extension or at least a different name? The extension could even be validation.rmeta. All the other output files have have different types.

With the current name schema it's not clear to me what will be the content of libCRATE_NAME.rmeta if user pass --emit=validation,full-analysis,rmeta.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Originally I gave it the same name because Cargo would know what kind of run it is. But having it in the filename is good for other build systems, thanks

Comment thread compiler/rustc_session/src/config.rs Outdated
Validation => {
shorthand: "validation",
extension: "rmeta",
description: "Generates metadata and exits after doing only validation and required analysis",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming the compiler will only exit if other outputs weren't required, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved

if sess.opts.output_types.stop_before_codegen() {
return None;
}

@bjorn3 bjorn3 Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

codegen_and_build_linker already emits crate metadata through start_codegen. Why not move this into start_codegen after metadata emission and remove the above encode_and_write_metadata?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that moving this check into codegen_and_build_linker would make the overall compiler workflow harder to follow (which is already a big problem). And would give codegen_and_build_linker even another responsability.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Regular crate metadata is already handled there even for check-only builds. I think putting crate metadata subsets elsewhere would be even harder to follow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that we should move that metadata emission out of start_codegen, not the other way around. Having an --emit=dep-info,metadata compilation call a start_codegen function is extremely confusing. But that should be another PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Skipping start_codegen for --emit=dep-info,metadata would mean that we did have to either duplicate the incr comp finalization code or split up Linker::link in nonsensical ways. Returning None for stop_before_codegen() will break incr comp as the incr comp session never gets finalized in Linker::link(). return None inside this function is only meant for errors or custom drivers that want to abort early without caring for incr comp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that we did have to either duplicate the incr comp finalization code or split up Linker::link in nonsensical ways

My gripe with metadata inside link is not that that it's not returned early, but that it goes too far only because link_rlib and gives too many responsabilities to link.

I've opened #165524 to get some responsabilities out of link and start_codegen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With that PR landed we still have the issue that returning None here breaks incr comp as Linker::link is responsible for finalizing the incr comp session.

Comment thread compiler/rustc_metadata/src/fs.rs Resolved
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved
Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved
Comment thread compiler/rustc_driver_impl/src/lib.rs Resolved
Comment thread compiler/rustc_interface/src/passes.rs Resolved
@rust-log-analyzer

This comment has been minimized.

github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Nov 19, 2026
…n, r=bjorn3

Cleanup, Get emitting metadata out of codegen

Related to rust-lang/rust#163670 (comment)

While metadata is not completely out of `link`, emitting or modifying it is now done outside `link` and `start_codegen`.
Other miscellaneous non-codegen things are also taken out of `link`.

Best reviewed commit by commit.

r? @jackh726

@bjorn3 bjorn3 Nov 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor: Can you remove some whitespace from the table to make it aligned again?

View changes since the review

@bjorn3

bjorn3 commented Nov 19, 2026

Copy link
Copy Markdown
Member

Would it make sense to move the OutputTypes move and run_required_analysis refactor to a separate PR? The former seems like the change in this PR that is most prone to random conflicts and both changes are IMO nice improvements independent of the rest of the changes in this PR.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

@rustbot rustbot added the T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. label Nov 19, 2026
@rustbot

This comment has been minimized.

@blyxyas

blyxyas commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Would it make sense to move the OutputTypes move and run_required_analysis refactor to a separate PR?

I don't have a preference, I'm open to do it if you think it's worthwhile

@rust-log-analyzer

This comment has been minimized.

@bjorn3

bjorn3 commented Nov 19, 2026

Copy link
Copy Markdown
Member

I think it would be.

@blyxyas

blyxyas commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

I've opened #166270, I'll remove those changes from here

@rustbot

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 23, 2026
…jorn3

Output type refactors & change analysis query into required_analysis

Split from rust-lang#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
Rollup merge of #166270 - blyxyas:output-type-refactors, r=bjorn3

Output type refactors & change analysis query into required_analysis

Split from #163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
@rust-bors

This comment has been minimized.

github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Nov 23, 2026
Output type refactors & change analysis query into required_analysis

Split from rust-lang/rust#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Nov 24, 2026
Output type refactors & change analysis query into required_analysis

Split from rust-lang/rust#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 24, 2026
Output type refactors & change analysis query into required_analysis

Split from rust-lang/rust#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Nov 26, 2026
Output type refactors & change analysis query into required_analysis

Split from rust-lang/rust#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
mehmettoplu-rs pushed a commit to mehmettoplu-rs/rustc_codegen_gcc that referenced this pull request Nov 27, 2026
Output type refactors & change analysis query into required_analysis

Split from rust-lang/rust#163670

We split OutputType from `config.rs` to `output.rs`, and because we only use full_analysis a single time in each compilation (at least currently), convert it to a regular function, and have `required_analysis` be the query.

r? @bjorn3
@rustbot

rustbot commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

This branch has not been deployed

No deployments
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-run-make Area: port run-make Makefiles to rmake.rs A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants