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

Diagnostic Translation #100717

Open
54 of 84 tasks
davidtwco opened this issue Aug 18, 2022 · 110 comments
Open
54 of 84 tasks

Diagnostic Translation #100717

davidtwco opened this issue Aug 18, 2022 · 110 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC S-tracking-impl-incomplete Status: The implementation is incomplete. S-tracking-needs-deep-research Status: This feature needs deep research to solve design or implementation issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@davidtwco
Copy link
Member

davidtwco commented Aug 18, 2022

Important

Please see #132181 for the current status of the compiler's translatable diagnostics infrastructure.


The Rust Diagnostics working group is leading an effort to add support for internationalization of error messages in the compiler, allowing the compiler to produce output in languages other than English. This issue tracks the current status of the effort, which was announced in the "Contribute to the diagnostic translation effort!" post on Inside Rust.

What's the current status?

Diagnostic translation will take a long time to be finished. At a high-level, there are four primary steps:

  • Implement initial translation infrastructure
  • Make diagnostics translatable through migration to new infrastructure (we are here)
  • Set up Pontoon for translators to use
  • Establish translation teams for different languages
  • Implement infrastructure for distributing language packs in collaboration with infrastructure/release teams (as appropriate)

Implementing the initial translation infrastructure provides the groundwork that enables diagnostic messages to be made translatable at all. That initial infrastructure is largely completed - there might be some gaps that we'll discover and patch up as we continue - but it's almost all there.

Next, all of the diagnostics in rustc need to be modified so that they can be translatable. There's some bad news - that's a lot of work. But there's also some good news - that's a lot of highly parallelizable work that you can help with! It doesn't require any familiarity with the Rust compiler, just an eagerness to get involved.

How to get started?

It's very easy to get started, the process looks like the following:

  1. Join our Zulip chat and say hello! Everyone is very friendly and eager to help if you have any trouble.
  2. Set up a development environment for the compiler.
  3. Identify a module to migrate (see "Identifying diagnostics to migrate" below).
  4. Migrate diagnostics (see "Migrate diagnostics" below).
  5. Open a pull request with your changes.
  6. Repeat and profit!

Identifying diagnostics to migrate

Our goal is to migrate every diagnostic in the compiler to be translatable and to switch from using a "diagnostic builder" to using "diagnostic structs". That's a lot of diagnostics, so we're splitting the work up by module in the compiler so that nobody steps on anyone else's toes.

Note: Some of these crates might not have diagnostics in them, in which case we'll just enable our internal lints on them. Some might have lots and lots of work that we can split up further, let us know! If there aren't many crates left, then feel free to leave a comment asking if someone is still working on their crate (check if they commented or have put a PR up recently).

Once you've picked a module (leave a comment letting us know!), how do you find the diagnostics to migrate? We've created rustc-internal lints that you can apply to a module which will produce an error for every diagnostic that hasn't been migrated.

#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

(an example of using these would just be adding them to the top of a file)

After adding these attributes, you can run ./x.py check to build the compiler in check mode (just like cargo check in another project). You'll notice a bunch of errors that will look something like these:

error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
    --> compiler/rustc_parse/src/parser/mod.rs:1443:40
     |
1443 |     let mut err = sess.span_diagnostic.struct_span_err(
     |                                        ^^^^^^^^^^^^^^^

error: diagnostics should be created using translatable messages
    --> compiler/rustc_parse/src/parser/mod.rs:1443:40
     |
1443 |     let mut err = sess.span_diagnostic.struct_span_err(
     |                                        ^^^^^^^^^^^^^^^

There will be two errors for each diagnostic that isn't migrated:

  1. "diagnostics should be created using translatable messages"
    • This error occurs when a diagnostic function is being invoked with something that isn't a translatable message (like a string literal or a formatted string).
      • e.g. err.label("an example label") instead of err.label(fluent::example_label)
      • fluent::example_label corresponds to a message in a "Fluent resource" which we can provide different versions of for each language.
  2. "diagnostics should only be created in Diagnostic/Subdiagnostic impls"
    • This error occurs when a diagnostic function is being called outside of an impl of Diagnostic or Subdiagnostic. One of our goals with this migration is to move all diagnostic emission logic into impls on structs, as it helps keep the compiler tidy and works towards other goals of the diagnostics working group.
    • There are two ways to resolve this:
      1. Using a diagnostic derive to implement them automatically (preferred!)
      2. Implementing one of these traits (Diagnostic for errors and warnings, LintDiagnostic for lints, or Subdiagnsostic for parts of an error/warning/lint) manually.
    • See "Migrate diagnostics" for more on these.

We'll know we're finished when we can leave those attributes on every module in the compiler.

Migrate diagnostics

Okay, so you've got a diagnostic in front of you that you need to migrate.. now what?

While migrating diagnostics, there might be cases you run into that we've not run across yet. Let us know in Zulip, you might be able to experiment and teach us how to translate some diagnostics, or there may be an opportunity to extend our core infrastructure (e.g. the derives). Don't worry though, you can always skip a diagnostic and leave it for someone else too.

Where to get help?

Discussion is primarily happening in the #i18n stream on Zulip. Ask any questions you have in that chat and someone will try to help. If you don't get a response, feel free to ping @davidtwco or @t-compiler/wg-diagnostics.

One-off tasks

Sometimes there are one-off tasks which improve compiler infrastructure around translation or just make things easier to use, these are listed below, feel free to comment to take them:

Completed

In-progress

To-do

@davidtwco davidtwco added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC S-tracking-impl-incomplete Status: The implementation is incomplete. A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic A-diagnostics Area: Messages for errors, warnings, and lints labels Aug 18, 2022
@nidnogg
Copy link
Contributor

nidnogg commented Aug 18, 2022

I took up rustc_const_eval and rustc_expand for the time being. Kudos for the further write-up! 🚀

@JeanCASPAR
Copy link
Contributor

I'm migrating rustc_ast_lowering

@IntQuant
Copy link
Contributor

I'll probably look into migrating rustc_infer

@Xiretza
Copy link
Contributor

Xiretza commented Aug 18, 2022

I'm working on rustc_parse.

@5225225
Copy link
Contributor

5225225 commented Aug 18, 2022

I'm doing the zero diagnostic crates in one PR, will constantly edit this comment to keep track of which ones they were.

rustc_apfloat rustc_arena rustc_ast rustc_ast_pretty rustc_data_structures rustc_error_codes rustc_error_messages rustc_feature rustc_fs_util rustc_graphviz rustc_hir rustc_hir_pretty rustc_index rustc_lexer rustc_lint_defs rustc_llvm rustc_log rustc_macros rustc_parse_format rustc_query_impl rustc_serialize rustc_smir rustc_span rustc_target rustc_traits

Easy ones to do (please leave a comment if you claim them!)

@superblaubeere27
Copy link

I'm working on rustc_typeck.

@JhonnyBillM
Copy link
Contributor

JhonnyBillM commented Aug 18, 2022

Working on:

  1. rustc_type_ir (zero diagnostic) - PR: Add diagnostics lints to rustc_type_ir module #100721
  2. rustc_symbol_mangling - PR: Migrate symbol_mangling module to new diagnostics structs #100831
  3. rustc_transmute (zero diagnostic) - PR: Add diagnostics lints to rustc_transmute module (zero diags) #100842
  4. rustc_errors

@CleanCut
Copy link
Contributor

@5225225 rustc_log seems to be zero diagnostics as well. Do you want to add that to your PR?

I'll continue to look for something unclaimed and small...

@CleanCut
Copy link
Contributor

[ ] rustc_transmute (currently being worked on by @nobody)

🤷🏻‍♂️ I can't find this one. Should I be on a branch other than master?

@5225225
Copy link
Contributor

5225225 commented Aug 18, 2022

Update your checkout. It's on master, but I think it's fairly new. (I believe it's the safe transmute people)

@CleanCut
Copy link
Contributor

Update your checkout. It's on master, but I think it's fairly new. (I believe it's the safe transmute people)

🤦🏻‍♂️ Thanks! I was working off a clone of my fork. I'm glad I discovered this now.

@5225225
Copy link
Contributor

5225225 commented Aug 18, 2022

Also if you want something small, rustc_monomorphize has 16 errors.

@CleanCut
Copy link
Contributor

Also if you want something small, rustc_monomorphize has 16 errors.

Working on rustc_monomorphize

@finalchild
Copy link
Contributor

Working on rustc_ast_passes

@Facel3ss1
Copy link
Contributor

Working on rustc_ty_utils

@compiler-errors
Copy link
Member

I marked off all of the crates in @5225225's #100723

@CleanCut
Copy link
Contributor

CleanCut commented Aug 18, 2022

I can't figure out how to do an optional #[note = "..."]. If someone could take a look at my draft PR and steer me in the right direction, that'd be most helpful. 😄

Update: The documentatation I was looking at was inaccurate. You need to do #[note(...)].

@Rejyr
Copy link
Contributor

Rejyr commented Aug 18, 2022

Working on rustc_lint

@gabrielBusta
Copy link
Contributor

Working on rustc_trait_selection

@evopen
Copy link
Contributor

evopen commented Aug 19, 2022

working on rustc_query_system

@AndyJado
Copy link
Contributor

AndyJado commented Aug 19, 2022

working on rustc_borrowck -- commented on Aug 19, 2022

🙇 kinda burned out, hoping someone could take it.

@beowolx
Copy link
Contributor

beowolx commented Aug 19, 2022

Working on rustc_session:

Currently, rustc_session has 98 functions that need to be migrated. I'keep this post updated with my progress.

@5225225
Copy link
Contributor

5225225 commented Aug 19, 2022

Working on rustc_mir_dataflow

@davidtwco
Copy link
Member Author

It's so exciting to wake up to all this interest and progress, I've updated the list with what everyone is working on.

@hampuslidin
Copy link
Contributor

I would like to work on rustc_attr.

@davidtwco
Copy link
Member Author

davidtwco commented Aug 19, 2022

A bonus task for someone who is interested, @compiler-errors makes the good suggestion that we could replace emit_err, emit_warn and emit_fatal (after #100694) with a single function which is generic over the EmissionGuarantee-impl'ing type that separates these different kinds of diagnostics.

Hm, maybe we should expose some sess.struct_$SOMETHING (like struct_diagnostic?) that is generic over EmissionGuarantee, then make the SessionDiagnostic derive generic, i.e.

impl<'tcx> SessionDiagnostic for UnusedGenericParams {
  fn into_diagnostic<T: EmissionGuarantee>( .. ) -> DiagnosticBuilder<'tcx, T> {
    let mut diag = sess.struct_diagnostic(rustc_errors:..);
    ..
  }
}

Like, ideally we shouldn't care what kind of DiagnosticBuilder (i.e. what kind of emission) we want when designing this struct. We should be able to do tcx.emit_err(Foo); or tcx.emit_warn(Foo); etc.

(#100730 (comment))

Update: @Xiretza is handling this one, see next few comments and Zulip discussion.

antoyo pushed a commit to antoyo/rust that referenced this issue Jun 19, 2023
…ics, r=davidtwco

Migrate rustc_codegen_gcc to SessionDiagnostics

As part of rust-lang#100717 this pr migrates diagnostics to `SessionDiagnostics` for the `rustc_codegen_gcc` crate.

``@rustbot`` label +A-translation
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 29, 2023
…r=davidtwco

Migrate some rustc_builtin_macros to SessionDiagnostic

Part of rust-lang#100717.

`@rustbot` label +A-translation
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 29, 2023
…r=davidtwco

Migrate some rustc_builtin_macros to SessionDiagnostic

Part of rust-lang#100717.

``@rustbot`` label +A-translation
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 30, 2023
…r=davidtwco

Migrate some rustc_builtin_macros to SessionDiagnostic

Part of rust-lang#100717.

```@rustbot``` label +A-translation
@dayo05
Copy link
Contributor

dayo05 commented Jul 3, 2023

I'm going to work on rustc_errors

@CraftSpider
Copy link
Contributor

I'm picking up the apparently abandoned rustc_hir_typeck

@JeanCASPAR
Copy link
Contributor

I'm taking rustc_resolve, which seems abandoned.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 4, 2024
…, r=davidtwco

Migrate some rustc_builtin_macros to SessionDiagnostic

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Part of rust-lang#100717.
pick up abandoned pr: rust-lang#101935
`@rustbot` label +A-translation
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 4, 2024
Rollup merge of rust-lang#126405 - He1pa:translate_builtin_macro_diag, r=davidtwco

Migrate some rustc_builtin_macros to SessionDiagnostic

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Part of rust-lang#100717.
pick up abandoned pr: rust-lang#101935
`@rustbot` label +A-translation
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 12, 2024
…stic, r=nnethercote

Get rid of some `#[allow(rustc::untranslatable_diagnostic)]`

`@rustbot` label +A-translation
cc rust-lang#100717
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 12, 2024
…stic, r=nnethercote

Get rid of some `#[allow(rustc::untranslatable_diagnostic)]`

``@rustbot`` label +A-translation
cc rust-lang#100717
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 12, 2024
…stic, r=nnethercote

Get rid of some `#[allow(rustc::untranslatable_diagnostic)]`

```@rustbot``` label +A-translation
cc rust-lang#100717
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 12, 2024
…stic, r=nnethercote

Get rid of some `#[allow(rustc::untranslatable_diagnostic)]`

`@rustbot` label +A-translation
cc rust-lang#100717
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 12, 2024
Rollup merge of rust-lang#128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote

Get rid of some `#[allow(rustc::untranslatable_diagnostic)]`

`@rustbot` label +A-translation
cc rust-lang#100717
@jieyouxu
Copy link
Member

Important

Please see #132181 for the current status of the compiler's translatable diagnostics infrastructure.

@jieyouxu jieyouxu added S-tracking-needs-deep-research Status: This feature needs deep research to solve design or implementation issues. S-tracking-impl-incomplete Status: The implementation is incomplete. and removed S-tracking-impl-incomplete Status: The implementation is incomplete. labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC S-tracking-impl-incomplete Status: The implementation is incomplete. S-tracking-needs-deep-research Status: This feature needs deep research to solve design or implementation issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests