Skip to content

Commit

Permalink
Datagen fallback modes and singletons (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jun 21, 2023
1 parent f43d9f6 commit 6f8a531
Show file tree
Hide file tree
Showing 31 changed files with 433 additions and 138 deletions.
4 changes: 2 additions & 2 deletions components/calendar/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub struct EraStartDate {
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(
marker(JapaneseErasV1Marker, "calendar/japanese@1"),
marker(JapaneseExtendedErasV1Marker, "calendar/japanext@1")
marker(JapaneseErasV1Marker, "calendar/japanese@1", singleton),
marker(JapaneseExtendedErasV1Marker, "calendar/japanext@1", singleton)
)]
#[derive(Debug, PartialEq, Clone, Default)]
#[cfg_attr(
Expand Down
13 changes: 9 additions & 4 deletions components/collator/data/data/macros/collator_dia_v1.data.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion components/collator/data/data/macros/collator_jamo_v1.data.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion components/collator/data/data/macros/collator_prim_v1.data.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions components/collator/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ impl<'data> CollationDataV1<'data> {
"collator/dia@1",
extension_key = "co",
fallback_by = "collation",
fallback_supplement = "collation"
fallback_supplement = "collation",
singleton,
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_collator::provider))]
Expand All @@ -216,7 +217,7 @@ pub struct CollationDiacriticsV1<'data> {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(CollationJamoV1Marker = "collator/jamo@1")]
#[icu_provider::data_struct(marker(CollationJamoV1Marker, "collator/jamo@1", singleton))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_collator::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand Down Expand Up @@ -420,7 +421,11 @@ impl CollationMetadataV1 {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(CollationSpecialPrimariesV1Marker = "collator/prim@1")]
#[icu_provider::data_struct(marker(
CollationSpecialPrimariesV1Marker,
"collator/prim@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_collator::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {
check_size_of!(5752 | 4544, TypedDateFormatter::<Gregorian>);
check_size_of!(6744 | 5408, TypedDateTimeFormatter::<Gregorian>);

check_size_of!(80, DateTimeError);
check_size_of!(88, DateTimeError);
check_size_of!(176, FormattedDateTime);
check_size_of!(16, FormattedTimeZone::<CustomTimeZone>);
check_size_of!(160, FormattedZonedDateTime);
Expand Down
17 changes: 6 additions & 11 deletions components/locid_transform/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,12 @@ impl LocaleFallbacker {
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
#[cfg(feature = "data")]
pub const fn new() -> Self {
Self {
likely_subtags: DataPayload::from_static_ref(
crate::provider::Baked::SINGLETON_FALLBACK_LIKELYSUBTAGS_V1,
),
parents: DataPayload::from_static_ref(
crate::provider::Baked::SINGLETON_FALLBACK_PARENTS_V1,
),
collation_supplement: Some(DataPayload::from_static_ref(
crate::provider::Baked::SINGLETON_FALLBACK_SUPPLEMENT_CO_V1,
)),
#[allow(clippy::new_ret_no_self)] // keeping constructors together
pub const fn new() -> LocaleFallbackerBorrowed<'static> {
LocaleFallbackerBorrowed {
likely_subtags: crate::provider::Baked::SINGLETON_FALLBACK_LIKELYSUBTAGS_V1,
parents: crate::provider::Baked::SINGLETON_FALLBACK_PARENTS_V1,
collation_supplement: Some(crate::provider::Baked::SINGLETON_FALLBACK_SUPPLEMENT_CO_V1),
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/locid_transform/src/provider/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use icu_provider::prelude::*;
use tinystr::UnvalidatedTinyAsciiStr;
use zerovec::{VarZeroVec, ZeroMap, ZeroSlice};

#[icu_provider::data_struct(AliasesV1Marker = "locid_transform/aliases@1")]
#[icu_provider::data_struct(marker(AliasesV1Marker, "locid_transform/aliases@1", singleton))]
#[derive(PartialEq, Clone, Default)]
#[cfg_attr(
feature = "datagen",
Expand Down
6 changes: 5 additions & 1 deletion components/locid_transform/src/provider/directionality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use super::*;
use icu_provider::prelude::*;
use zerovec::ZeroVec;

#[icu_provider::data_struct(ScriptDirectionV1Marker = "locid_transform/script_dir@1")]
#[icu_provider::data_struct(marker(
ScriptDirectionV1Marker,
"locid_transform/script_dir@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
Expand Down
26 changes: 20 additions & 6 deletions components/locid_transform/src/provider/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use icu_locid::subtags::{Language, Region, Script};
use icu_provider::prelude::*;
use zerovec::ZeroMap;

#[icu_provider::data_struct(LikelySubtagsV1Marker = "locid_transform/likelysubtags@1")]
#[icu_provider::data_struct(marker(
LikelySubtagsV1Marker,
"locid_transform/likelysubtags@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
Expand Down Expand Up @@ -57,7 +61,11 @@ pub struct LikelySubtagsV1<'data> {
pub und: (Language, Script, Region),
}

#[icu_provider::data_struct(LikelySubtagsForLanguageV1Marker = "locid_transform/likelysubtags_l@1")]
#[icu_provider::data_struct(marker(
LikelySubtagsForLanguageV1Marker,
"locid_transform/likelysubtags_l@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
Expand Down Expand Up @@ -123,9 +131,11 @@ impl<'data> LikelySubtagsForLanguageV1<'data> {
}
}

#[icu_provider::data_struct(
LikelySubtagsForScriptRegionV1Marker = "locid_transform/likelysubtags_sr@1"
)]
#[icu_provider::data_struct(marker(
LikelySubtagsForScriptRegionV1Marker,
"locid_transform/likelysubtags_sr@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
Expand Down Expand Up @@ -177,7 +187,11 @@ impl<'data> From<LikelySubtagsV1<'data>> for LikelySubtagsForScriptRegionV1<'dat
}
}

#[icu_provider::data_struct(LikelySubtagsExtendedV1Marker = "locid_transform/likelysubtags_ext@1")]
#[icu_provider::data_struct(marker(
LikelySubtagsExtendedV1Marker,
"locid_transform/likelysubtags_ext@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
Expand Down
15 changes: 12 additions & 3 deletions components/locid_transform/src/provider/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ use zerovec::ZeroMap;
use zerovec::ZeroMap2d;

/// Locale fallback rules derived from likely subtags data.
#[icu_provider::data_struct(LocaleFallbackLikelySubtagsV1Marker = "fallback/likelysubtags@1")]
#[icu_provider::data_struct(marker(
LocaleFallbackLikelySubtagsV1Marker,
"fallback/likelysubtags@1",
singleton
))]
#[derive(Default, Clone, PartialEq, Debug)]
#[cfg_attr(
feature = "datagen",
Expand Down Expand Up @@ -55,7 +59,11 @@ pub const DEFAULT_SCRIPT: Script = script!("Latn");
pub const DEFAULT_REGION: Region = region!("ZZ");

/// Locale fallback rules derived from CLDR parent locales data.
#[icu_provider::data_struct(LocaleFallbackParentsV1Marker = "fallback/parents@1")]
#[icu_provider::data_struct(marker(
LocaleFallbackParentsV1Marker,
"fallback/parents@1",
singleton
))]
#[derive(Default, Clone, PartialEq, Debug)]
#[cfg_attr(
feature = "datagen",
Expand All @@ -74,7 +82,8 @@ pub struct LocaleFallbackParentsV1<'data> {
/// Key-specific supplemental fallback data.
#[icu_provider::data_struct(marker(
CollationFallbackSupplementV1Marker,
"fallback/supplement/co@1"
"fallback/supplement/co@1",
singleton,
))]
#[derive(Default, Clone, PartialEq, Debug)]
#[cfg_attr(
Expand Down
30 changes: 23 additions & 7 deletions components/normalizer/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ use zerovec::ZeroVec;
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(CanonicalDecompositionDataV1Marker = "normalizer/nfd@1")]
#[icu_provider::data_struct(marker(
CanonicalDecompositionDataV1Marker,
"normalizer/nfd@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_normalizer::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand All @@ -46,8 +50,12 @@ pub struct DecompositionDataV1<'data> {
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(
CompatibilityDecompositionSupplementV1Marker = "normalizer/nfkd@1",
Uts46DecompositionSupplementV1Marker = "normalizer/uts46d@1"
marker(
CompatibilityDecompositionSupplementV1Marker,
"normalizer/nfkd@1",
singleton
),
marker(Uts46DecompositionSupplementV1Marker, "normalizer/uts46d@1", singleton)
)]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_normalizer::provider))]
Expand Down Expand Up @@ -95,8 +103,12 @@ impl DecompositionSupplementV1<'_> {
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(
CanonicalDecompositionTablesV1Marker = "normalizer/nfdex@1",
CompatibilityDecompositionTablesV1Marker = "normalizer/nfkdex@1"
marker(CanonicalDecompositionTablesV1Marker, "normalizer/nfdex@1", singleton),
marker(
CompatibilityDecompositionTablesV1Marker,
"normalizer/nfkdex@1",
singleton
)
)]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_normalizer::provider))]
Expand All @@ -118,7 +130,7 @@ pub struct DecompositionTablesV1<'data> {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(CanonicalCompositionsV1Marker = "normalizer/comp@1")]
#[icu_provider::data_struct(marker(CanonicalCompositionsV1Marker, "normalizer/comp@1", singleton))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_normalizer::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand All @@ -138,7 +150,11 @@ pub struct CanonicalCompositionsV1<'data> {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[icu_provider::data_struct(NonRecursiveDecompositionSupplementV1Marker = "normalizer/decomp@1")]
#[icu_provider::data_struct(marker(
NonRecursiveDecompositionSupplementV1Marker,
"normalizer/decomp@1",
singleton
))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake), databake(path = icu_normalizer::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand Down
Loading

0 comments on commit 6f8a531

Please sign in to comment.