From ccd482032672a223ceaa8ab8d7637180a357fdea Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 3 Apr 2022 05:32:38 +0100 Subject: [PATCH] errors: support fluent + parallel compiler Conditional on the parallel compiler being enabled, use a different `IntlLangMemoizer` which supports being sent between threads in `FluentBundle`. Signed-off-by: David Wood --- Cargo.lock | 1 + compiler/rustc_error_messages/Cargo.toml | 1 + compiler/rustc_error_messages/src/lib.rs | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6940406a766..d8cb1133c73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3711,6 +3711,7 @@ version = "0.0.0" dependencies = [ "fluent-bundle", "fluent-syntax", + "intl-memoizer", "rustc_data_structures", "rustc_macros", "rustc_serialize", diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index bda44d691e5..fc84c7c8665 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -9,6 +9,7 @@ doctest = false [dependencies] fluent-bundle = "0.15.2" fluent-syntax = "0.11" +intl-memoizer = "0.5.1" rustc_data_structures = { path = "../rustc_data_structures" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 1b8267524af..88f3b547605 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -14,12 +14,27 @@ use std::io; use std::path::Path; use tracing::{instrument, trace}; +#[cfg(parallel_compiler)] +use intl_memoizer::concurrent::IntlLangMemoizer; +#[cfg(not(parallel_compiler))] +use intl_memoizer::IntlLangMemoizer; + pub use fluent_bundle::{FluentArgs, FluentError, FluentValue}; pub use unic_langid::{langid, LanguageIdentifier}; static FALLBACK_FLUENT_RESOURCE: &'static str = include_str!("../locales/en-US/diagnostics.ftl"); -pub type FluentBundle = fluent_bundle::FluentBundle; +pub type FluentBundle = fluent_bundle::bundle::FluentBundle; + +#[cfg(parallel_compiler)] +fn new_bundle(locales: Vec) -> FluentBundle { + FluentBundle::new_concurrent(locales) +} + +#[cfg(not(parallel_compiler))] +fn new_bundle(locales: Vec) -> FluentBundle { + FluentBundle::new(locales) +} #[derive(Debug)] pub enum TranslationBundleError { @@ -114,7 +129,7 @@ pub fn fluent_bundle( // provided locale. let locale = requested_locale.clone().unwrap_or(fallback_locale); trace!(?locale); - let mut bundle = FluentBundle::new(vec![locale]); + let mut bundle = new_bundle(vec![locale]); // Fluent diagnostics can insert directionality isolation markers around interpolated variables // indicating that there may be a shift from right-to-left to left-to-right text (or @@ -176,7 +191,7 @@ pub fn fallback_fluent_bundle( let fallback_resource = FluentResource::try_new(FALLBACK_FLUENT_RESOURCE.to_string()) .map_err(TranslationBundleError::from)?; trace!(?fallback_resource); - let mut fallback_bundle = FluentBundle::new(vec![langid!("en-US")]); + let mut fallback_bundle = new_bundle(vec![langid!("en-US")]); // See comment in `fluent_bundle`. fallback_bundle.set_use_isolating(with_directionality_markers); fallback_bundle.add_resource(fallback_resource).map_err(TranslationBundleError::from)?;