Skip to content

better error handling for rust.codegen-backends on deserialization #114278

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

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

onur-ozkan
Copy link
Member

@onur-ozkan onur-ozkan commented Jul 31, 2023

Fixes #109315

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2023

r? @clubby789

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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) labels Jul 31, 2023
@onur-ozkan onur-ozkan changed the title validate codegen backend on deserialization validate rust.codegen-backends on deserialization Jul 31, 2023
@onur-ozkan onur-ozkan force-pushed the validate-codegen-backend-config branch from 2d1b9bc to 3ea7fed Compare July 31, 2023 08:47
let available_backends = vec!["llvm", "cranelift", "gcc"];

config.rust_codegen_backends = backends.iter().map(|s| {
if !available_backends.contains(&s.as_str()) {
Copy link
Member

Choose a reason for hiding this comment

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

Applying validation risks making life harder for people who use out-of-tree codegen backends such as rustc_codegen_spirv, and in general, for making new codegen backends (if any ever exist) get off the ground. In order to apply the asked-for help, it should reverse this logic: check for approximate names to the ones we already know and recommend they use the other option instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we can handle these names without getting too worried. An example: when we combine rustc_codegen_ with the backend name, it fails if we use rustc_codegen_gcc, resulting in rustc_codegen_rustc_codegen_gcc. However, we can fix this problem by not adding the rustc_codegen_ prefix if it's already included in the name. So, out-of-tree backends won't be a problem in this situation. What do you think on this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that sounds like a good solution

Copy link
Member

Choose a reason for hiding this comment

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

I'm always a little wary of canonicalizing stuff instead of either simply accepting or rejecting, but it seems plausibly fine in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

So with the latest change, now we panic if in-tree backends are used with rustc_codegen_ prefix, and print a help message if out-of-tree backend is used with rustc_codegen_ prefix. Each message includes the suggestion for fixing the problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we can handle these names without getting too worried. An example: when we combine rustc_codegen_ with the backend name, it fails if we use rustc_codegen_gcc, resulting in rustc_codegen_rustc_codegen_gcc. However, we can fix this problem by not adding the rustc_codegen_ prefix if it's already included in the name. So, out-of-tree backends won't be a problem in this situation. What do you think on this approach?

The reason I didn't follow this solution was because it was going to be too hacky(it didn't work out of the box, codegen backends were failing on the compilation)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@onur-ozkan onur-ozkan force-pushed the validate-codegen-backend-config branch from 3ea7fed to ccefc97 Compare July 31, 2023 19:46
@onur-ozkan onur-ozkan changed the title validate rust.codegen-backends on deserialization better error handling for rust.codegen-backends on deserialization Jul 31, 2023
Signed-off-by: ozkanonur <work@onurozkan.dev>
@onur-ozkan onur-ozkan force-pushed the validate-codegen-backend-config branch from ccefc97 to b602cf5 Compare July 31, 2023 19:57
@clubby789
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 9, 2023

📌 Commit b602cf5 has been approved by clubby789

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 9, 2023
@onur-ozkan
Copy link
Member Author

@bors rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 10, 2023
…-config, r=clubby789

better error handling for `rust.codegen-backends` on deserialization

Fixes rust-lang#109315
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 10, 2023
…-config, r=clubby789

better error handling for `rust.codegen-backends` on deserialization

Fixes rust-lang#109315
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 10, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#114278 (better error handling for `rust.codegen-backends` on deserialization)
 - rust-lang#114674 (Add clubby789 to `users_on_vacation`)
 - rust-lang#114678 (`Expr::can_have_side_effects()` is incorrect for struct/enum/array/tuple literals)
 - rust-lang#114681 (doc (unstable-book): fix a typo)
 - rust-lang#114684 (Remove redundant calls to `resolve_vars_with_obligations`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b9648d4 into rust-lang:master Aug 10, 2023
@rustbot rustbot added this to the 1.73.0 milestone Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codegen-backends = ["rustc_codegen_cranelift"] should give a better error message
5 participants