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

Restore behavior when primary bundle is missing #106923

Merged
merged 4 commits into from
Feb 24, 2023
Merged

Restore behavior when primary bundle is missing #106923

merged 4 commits into from
Feb 24, 2023

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented Jan 15, 2023

Fixes #106755 by restoring some of the behavior prior to #106427

Still, I have no idea how this debug assertion can even hit while using en-US as primary bundle.

r? @davidtwco

@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2023

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

Please see the contribution instructions for more information.

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Jan 15, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2023

rustc_errors::translation was changed

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

@davidtwco
Copy link
Member

Still, I have no idea how this debug assertion can even hit while using en-US as primary bundle.

If I remember correctly, we lazily load the primary bundle contents, maybe there's a code path that triggers a translation without triggering the lazy load?

@mejrs
Copy link
Contributor Author

mejrs commented Jan 31, 2023

Still, I have no idea how this debug assertion can even hit while using en-US as primary bundle.

If I remember correctly, we lazily load the primary bundle contents, maybe there's a code path that triggers a translation without triggering the lazy load?

If there is one I can't find it, but I do not know this code well.

@davidtwco
Copy link
Member

I think we probably want the patch that you have now, so that we can have partially translated primary bundles and not ICE repeatedly when using a debug build.

However, the reason that this fails is that when the default locale is requested, then we ended up just creating an empty bundle with no translated messages, and the patch below fixes that, so when the default locale is requested (and no testing Fluent resource is provided), then we just don't create a primary bundle at all.

diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 1882d4b698e..32aa90afa9b 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -176,6 +176,10 @@ pub fn fluent_bundle(

     let fallback_locale = langid!("en-US");
     let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
+    trace!(?requested_fallback_locale);
+    if requested_fallback_locale && additional_ftl_path.is_none() {
+        return Ok(None);
+    }

     // If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
     // provided locale.
@@ -194,7 +198,7 @@ pub fn fluent_bundle(
     bundle.set_use_isolating(with_directionality_markers);

     // If the user requests the default locale then don't try to load anything.
-    if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
+    if let Some(requested_locale) = requested_locale {
         let mut found_resources = false;
         for sysroot in user_provided_sysroot.iter_mut().chain(sysroot_candidates.iter_mut()) {
             sysroot.push("share");

@davidtwco
Copy link
Member

Oh also, I'd appreciate if you added a test for this.

@mejrs
Copy link
Contributor Author

mejrs commented Feb 2, 2023

Thanks, that fixes the problem. However I am not sure how to add a test for it, because it requires a rustc built with debug assertions.

@davidtwco
Copy link
Member

Thanks, that fixes the problem. However I am not sure how to add a test for it, because it requires a rustc built with debug assertions.

Just a test with -Ztranslate-lang=en-US that shows the correct output should be enough - some of the builders have debug assertions enabled and the behaviour should now be the same with or without those assertions.

@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 2023

rustc_error_messages was changed

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

@bors

This comment was marked as resolved.

@mejrs
Copy link
Contributor Author

mejrs commented Feb 23, 2023

Also @davidtwco I rebased

<<<<<<< HEAD
                // Always yeet out for errors on debug (unless
                // `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
                // local runs of the test suites, of builds with debug assertions, to test the
                // behaviour in a normal build).
                Some(Err(primary))
                    if cfg!(debug_assertions)
                        && env::var("RUSTC_TRANSLATION_NO_DEBUG_ASSERT").is_err() =>
                {
                    do yeet primary
                }
=======
                // If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
                // just that the primary bundle doesn't contain the message being translated, so
                // proceed to the fallback bundle.
                Some(Err(
                    primary @ TranslateError::One {
                        kind: TranslateErrorKind::MessageMissing, ..
                    },
                )) => translate_with_bundle(self.fallback_fluent_bundle())
                    .map_err(|fallback| primary.and(fallback))?,

                // However, when errors are produced from translation, then that means the translation
                // is broken (e.g. `{$foo}` exists in a translation but `foo` isn't provided).
                //
                // In debug builds, assert so that compiler devs can spot the broken translation and
                // fix it..
                Some(Err(primary)) if cfg!(debug_assertions) => do yeet primary,
>>>>>>> 6b812c48ce6 (Restore behavior when primary bundle is missing)

as

                // If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
                // just that the primary bundle doesn't contain the message being translated, so
                // proceed to the fallback bundle.
                Some(Err(
                    primary @ TranslateError::One {
                        kind: TranslateErrorKind::MessageMissing, ..
                    },
                )) => translate_with_bundle(self.fallback_fluent_bundle())
                    .map_err(|fallback| primary.and(fallback))?,

                // Always yeet out for errors on debug (unless
                // `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
                // local runs of the test suites, of builds with debug assertions, to test the
                // behaviour in a normal build).
                Some(Err(primary))
                    if cfg!(debug_assertions)
                        && env::var("RUSTC_TRANSLATION_NO_DEBUG_ASSERT").is_err() =>
                {
                    do yeet primary
                }

I think that is right.

@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 23, 2023

📌 Commit 4c13a21 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 Feb 23, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 23, 2023
Restore behavior when primary bundle is missing

Fixes rust-lang#106755 by restoring some of the behavior prior to rust-lang#106427

Still, I have no idea how this debug assertion can even hit while using `en-US` as primary  bundle.

r? `@davidtwco`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 23, 2023
Restore behavior when primary bundle is missing

Fixes rust-lang#106755 by restoring some of the behavior prior to rust-lang#106427

Still, I have no idea how this debug assertion can even hit while using `en-US` as primary  bundle.

r? ``@davidtwco``
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 24, 2023
Rollup of 10 pull requests

Successful merges:

 - rust-lang#106541 (implement const iterator using `rustc_do_not_const_check`)
 - rust-lang#106918 (Rebuild BinaryHeap on unwind from retain)
 - rust-lang#106923 (Restore behavior when primary bundle is missing)
 - rust-lang#108169 (Make query keys `Copy`)
 - rust-lang#108287 (Add test for bad cast with deferred projection equality)
 - rust-lang#108370 (std: time: Avoid to use "was created" in elapsed() description)
 - rust-lang#108377 (Fix ICE in 'duplicate diagnostic item' diagnostic)
 - rust-lang#108388 (parser: provide better suggestions and errors on closures with braces missing)
 - rust-lang#108391 (Fix `is_terminal`'s handling of long paths on Windows.)
 - rust-lang#108401 (diagnostics: remove inconsistent English article "this" from E0107)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6826a96 into rust-lang:master Feb 24, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 24, 2023
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.

ICE: failed while formatting fluent string with debug assertions
5 participants