about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-04-03 05:32:38 +0100
committerDavid Wood <david.wood@huawei.com>2022-04-05 07:01:03 +0100
commitccd482032672a223ceaa8ab8d7637180a357fdea (patch)
treea3ca7f0a8006c1c3cb086f7b51ac16125b52a6ec
parentda56d92037421f26badff41fe6de841ca4210e6d (diff)
downloadrust-ccd482032672a223ceaa8ab8d7637180a357fdea.tar.gz
rust-ccd482032672a223ceaa8ab8d7637180a357fdea.zip
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 <david.wood@huawei.com>
-rw-r--r--Cargo.lock1
-rw-r--r--compiler/rustc_error_messages/Cargo.toml1
-rw-r--r--compiler/rustc_error_messages/src/lib.rs21
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<FluentResource>;
+pub type FluentBundle = fluent_bundle::bundle::FluentBundle<FluentResource, IntlLangMemoizer>;
+
+#[cfg(parallel_compiler)]
+fn new_bundle(locales: Vec<LanguageIdentifier>) -> FluentBundle {
+    FluentBundle::new_concurrent(locales)
+}
+
+#[cfg(not(parallel_compiler))]
+fn new_bundle(locales: Vec<LanguageIdentifier>) -> 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)?;