Skip to content
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

Migrate rustc_codegen_llvm to SessionDiagnostics #101005

Merged
merged 35 commits into from
Nov 10, 2022

Conversation

SLASHLogin
Copy link
Contributor

WIP: Port current implementation of diagnostics to the new SessionDiagnostics.

Part of #100717

@rustbot label +A-translation

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 25, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Aug 25, 2022

r? @davidtwco (I'm still catching up)

@rust-highfive rust-highfive assigned davidtwco and unassigned oli-obk Aug 25, 2022
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This is a great start!

compiler/rustc_codegen_llvm/src/errors.rs Outdated Show resolved Hide resolved
@davidtwco davidtwco mentioned this pull request Aug 25, 2022
84 tasks
@SLASHLogin SLASHLogin force-pushed the rustc_codegen_llvm_diagnostics branch from 773d3c8 to 6b8539a Compare August 26, 2022 21:27
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 27, 2022

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

@SLASHLogin SLASHLogin force-pushed the rustc_codegen_llvm_diagnostics branch from fc3bcde to 79ff769 Compare August 29, 2022 14:04
@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member

davidtwco commented Aug 30, 2022

You might just need to skip these for now, otherwise we would have to change SessionDiagnostic to use a Handler rather than a ParseSess (which might be doable).

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This looks great, left a couple comments

cx.tcx
.sess
.create_err(TargetFeatureDisableOrEnable { features: f, span: Some(span) })
.subdiagnostic(MissingFeatures)
Copy link
Member

Choose a reason for hiding this comment

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

Why can't you just add a #[help] to the type of TargetFeatureDisableOrEnable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TargetFeatureDisableOrEnable is present in llvm_util.rs, but without the help. I was thinking of splitting them into separate diagnostics, and then I could just add #[help] as you proposed.
https://github.com/rust-lang/rust/blob/2227d5117d0d8fe9d897bb3a2d020e75bb3edad5/compiler/rustc_codegen_llvm/src/llvm_util.rs#L497-L502

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other solution could be usage of enums instead of struct here. That would boil down to the same problem as the other comment here.

compiler/rustc_codegen_llvm/src/context.rs Outdated Show resolved Hide resolved
@bors

This comment was marked as resolved.

@Noratrieb
Copy link
Member

Hi, I've seen you changed some diagnostic structs in your PR. After #103345, the way we refer to fluent messages changed. They are now in a flat namespace with the same identifier as in the fluent file. For example, parser::cool_thing is now parser_cool_thing and parser::suggestion just suggestion.
You should rebase to the latest master and change your fluent message references as described above. Thanks!

@SLASHLogin SLASHLogin force-pushed the rustc_codegen_llvm_diagnostics branch from 2227d51 to 48758e7 Compare October 30, 2022 13:38
@rust-log-analyzer

This comment has been minimized.

@SLASHLogin
Copy link
Contributor Author

@davidtwco I've ported remaining two diagnostics and changed old ones, which were implemented manually. However, it seems like SharedEmitter implements Translate such that it always panics, and it fails that one test.

impl Translate for SharedEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
None
}
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
panic!("shared emitter attempted to translate a diagnostic");
}
}

https://github.com/rust-lang/rust/blob/3f66cd3ce40aa58404c901c16c211fff42a3f1a1/compiler/rustc_codegen_llvm/src/back/lto.rs#L93-L96

@SLASHLogin SLASHLogin marked this pull request as ready for review October 31, 2022 11:33
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2022

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

@davidtwco
Copy link
Member

@davidtwco I've ported remaining two diagnostics and changed old ones, which were implemented manually. However, it seems like SharedEmitter implements Translate such that it always panics, and it fails that one test.

Are you able to change rustc_codegen_ssa::back::write::Diagnostic so that the message field takes a rustc_errors::DiagnosticMessage? Then if we remove the call to translate_messages, it should be okay?

msg: self.translate_messages(&diag.message, &fluent_args).to_string(),

I guess you'll also need to keep track of the diagnostic arguments in rustc_codegen_ssa::back::write::Diagnostic too and set those when it recreates the rustc_errors::Diagnostic on the other side.

I'm assuming that diagnostics emitted from SharedEmitter get sent back to another thread where the actual emitter with the translation resources will be available.

@SLASHLogin
Copy link
Contributor Author

I was able to change rustc_codegen_ssa::back::write::Diagnostic so that it takes Vec<(DiagnosticMessage, Style)>, just like in rustc_errors::diagnostic::Diagnostic. I'm also copying arguments from the latter one to the former. However, with this approach, I have to pass new String when recreating rustc_errors::Diagnostic. Additionally, I had to implement IntoDiagnosticArg for DiagnosticArgValue to be able to pass arguments back.
With this solution I was able to pass this UI test, but I'm failing two codegen tests though. Should I commit those changes to this branch, or should I make new PR for it?

@davidtwco
Copy link
Member

I was able to change rustc_codegen_ssa::back::write::Diagnostic so that it takes Vec<(DiagnosticMessage, Style)>, just like in rustc_errors::diagnostic::Diagnostic. I'm also copying arguments from the latter one to the former. However, with this approach, I have to pass new String when recreating rustc_errors::Diagnostic. Additionally, I had to implement IntoDiagnosticArg for DiagnosticArgValue to be able to pass arguments back. With this solution I was able to pass this UI test, but I'm failing two codegen tests though. Should I commit those changes to this branch, or should I make new PR for it?

Feel free to commit them to this branch.

@SLASHLogin SLASHLogin force-pushed the rustc_codegen_llvm_diagnostics branch from eb829d6 to 39895b0 Compare November 9, 2022 13:58
@SLASHLogin
Copy link
Contributor Author

Sorry, I've used GitHub's feature and didn't check properly that it would do the merge commit.

@SLASHLogin
Copy link
Contributor Author

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Nov 9, 2022

@SLASHLogin: 🔑 Insufficient privileges: Not in reviewers

@SLASHLogin
Copy link
Contributor Author

r? davidtwco

@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2022

Could not assign reviewer from: davidtwco.
User(s) davidtwco are either the PR author or are already assigned, and there are no other candidates.
Use r? to specify someone else to assign.

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 9, 2022

📌 Commit caada74 has been approved by davidtwco

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 Nov 9, 2022
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 9, 2022
…nostics, r=davidtwco

Migrate rustc_codegen_llvm to SessionDiagnostics

WIP: Port current implementation of diagnostics to the new SessionDiagnostics.

Part of rust-lang#100717

`@rustbot` label +A-translation
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 9, 2022
…nostics, r=davidtwco

Migrate rustc_codegen_llvm to SessionDiagnostics

WIP: Port current implementation of diagnostics to the new SessionDiagnostics.

Part of rust-lang#100717

``@rustbot`` label +A-translation
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2022
…earth

Rollup of 9 pull requests

Successful merges:

 - rust-lang#101005 (Migrate rustc_codegen_llvm to SessionDiagnostics)
 - rust-lang#103307 (Add context to compiler error message)
 - rust-lang#103464 (Add support for custom mir)
 - rust-lang#103929 (Cleanup Apple-related code in rustc_target)
 - rust-lang#104015 (Remove linuxkernel targets)
 - rust-lang#104020 (Limit efiapi calling convention to supported arches)
 - rust-lang#104156 (Cleanups in autoderef impl)
 - rust-lang#104171 (Update books)
 - rust-lang#104184 (Fix `rustdoc --version` when used with download-rustc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Nov 10, 2022

⌛ Testing commit caada74 with merge 34115d0...

@bors bors merged commit 2206267 into rust-lang:master Nov 10, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 10, 2022
@SLASHLogin SLASHLogin deleted the rustc_codegen_llvm_diagnostics branch November 10, 2022 19:09
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants