Skip to content

Commit ccd4820

Browse files
committed
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 <[email protected]>
1 parent da56d92 commit ccd4820

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3711,6 +3711,7 @@ version = "0.0.0"
37113711
dependencies = [
37123712
"fluent-bundle",
37133713
"fluent-syntax",
3714+
"intl-memoizer",
37143715
"rustc_data_structures",
37153716
"rustc_macros",
37163717
"rustc_serialize",

Diff for: compiler/rustc_error_messages/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ doctest = false
99
[dependencies]
1010
fluent-bundle = "0.15.2"
1111
fluent-syntax = "0.11"
12+
intl-memoizer = "0.5.1"
1213
rustc_data_structures = { path = "../rustc_data_structures" }
1314
rustc_serialize = { path = "../rustc_serialize" }
1415
rustc_span = { path = "../rustc_span" }

Diff for: compiler/rustc_error_messages/src/lib.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,27 @@ use std::io;
1414
use std::path::Path;
1515
use tracing::{instrument, trace};
1616

17+
#[cfg(parallel_compiler)]
18+
use intl_memoizer::concurrent::IntlLangMemoizer;
19+
#[cfg(not(parallel_compiler))]
20+
use intl_memoizer::IntlLangMemoizer;
21+
1722
pub use fluent_bundle::{FluentArgs, FluentError, FluentValue};
1823
pub use unic_langid::{langid, LanguageIdentifier};
1924

2025
static FALLBACK_FLUENT_RESOURCE: &'static str = include_str!("../locales/en-US/diagnostics.ftl");
2126

22-
pub type FluentBundle = fluent_bundle::FluentBundle<FluentResource>;
27+
pub type FluentBundle = fluent_bundle::bundle::FluentBundle<FluentResource, IntlLangMemoizer>;
28+
29+
#[cfg(parallel_compiler)]
30+
fn new_bundle(locales: Vec<LanguageIdentifier>) -> FluentBundle {
31+
FluentBundle::new_concurrent(locales)
32+
}
33+
34+
#[cfg(not(parallel_compiler))]
35+
fn new_bundle(locales: Vec<LanguageIdentifier>) -> FluentBundle {
36+
FluentBundle::new(locales)
37+
}
2338

2439
#[derive(Debug)]
2540
pub enum TranslationBundleError {
@@ -114,7 +129,7 @@ pub fn fluent_bundle(
114129
// provided locale.
115130
let locale = requested_locale.clone().unwrap_or(fallback_locale);
116131
trace!(?locale);
117-
let mut bundle = FluentBundle::new(vec![locale]);
132+
let mut bundle = new_bundle(vec![locale]);
118133

119134
// Fluent diagnostics can insert directionality isolation markers around interpolated variables
120135
// 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(
176191
let fallback_resource = FluentResource::try_new(FALLBACK_FLUENT_RESOURCE.to_string())
177192
.map_err(TranslationBundleError::from)?;
178193
trace!(?fallback_resource);
179-
let mut fallback_bundle = FluentBundle::new(vec![langid!("en-US")]);
194+
let mut fallback_bundle = new_bundle(vec![langid!("en-US")]);
180195
// See comment in `fluent_bundle`.
181196
fallback_bundle.set_use_isolating(with_directionality_markers);
182197
fallback_bundle.add_resource(fallback_resource).map_err(TranslationBundleError::from)?;

0 commit comments

Comments
 (0)