Skip to content

Commit

Permalink
Merge branch 'main' into anypayloadprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Sep 7, 2024
2 parents add2e5b + e059aaf commit 6378d67
Show file tree
Hide file tree
Showing 350 changed files with 23,935 additions and 226,354 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

27 changes: 17 additions & 10 deletions components/collator/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ use crate::elements::{
NO_CE_SECONDARY, NO_CE_TERTIARY, OPTIMIZED_DIACRITICS_MAX_COUNT, QUATERNARY_MASK,
};
use crate::options::CollatorOptionsBitField;
use crate::provider::CollationDataV1Marker;
use crate::provider::CollationDiacriticsV1Marker;
use crate::provider::CollationJamoV1Marker;
use crate::provider::CollationMetadataV1Marker;
use crate::provider::CollationReorderingV1Marker;
use crate::provider::CollationRootV1Marker;
use crate::provider::CollationSpecialPrimariesV1Marker;
use crate::provider::CollationTailoringV1Marker;
use crate::{AlternateHandling, CollatorOptions, MaxVariable, ResolvedCollatorOptions, Strength};
use core::cmp::Ordering;
use core::convert::TryFrom;
Expand Down Expand Up @@ -55,8 +56,8 @@ impl AnyQuaternaryAccumulator {
#[derive(Debug)]
pub struct Collator {
special_primaries: Option<DataPayload<CollationSpecialPrimariesV1Marker>>,
root: DataPayload<CollationDataV1Marker>,
tailoring: Option<DataPayload<CollationDataV1Marker>>,
root: DataPayload<CollationRootV1Marker>,
tailoring: Option<DataPayload<CollationTailoringV1Marker>>,
jamo: DataPayload<CollationJamoV1Marker>,
diacritics: DataPayload<CollationDiacriticsV1Marker>,
options: CollatorOptionsBitField,
Expand All @@ -72,6 +73,9 @@ impl Collator {
pub fn try_new(locale: &DataLocale, options: CollatorOptions) -> Result<Self, DataError> {
Self::try_new_unstable_internal(
&crate::provider::Baked,
DataPayload::from_static_ref(
crate::provider::Baked::SINGLETON_COLLATION_ROOT_V1_MARKER,
),
DataPayload::from_static_ref(
icu_normalizer::provider::Baked::SINGLETON_CANONICAL_DECOMPOSITION_DATA_V1_MARKER,
),
Expand Down Expand Up @@ -110,7 +114,8 @@ impl Collator {
) -> Result<Self, DataError>
where
D: DataProvider<CollationSpecialPrimariesV1Marker>
+ DataProvider<CollationDataV1Marker>
+ DataProvider<CollationRootV1Marker>
+ DataProvider<CollationTailoringV1Marker>
+ DataProvider<CollationDiacriticsV1Marker>
+ DataProvider<CollationJamoV1Marker>
+ DataProvider<CollationMetadataV1Marker>
Expand All @@ -124,14 +129,17 @@ impl Collator {
provider.load(Default::default())?.payload,
provider.load(Default::default())?.payload,
provider.load(Default::default())?.payload,
provider.load(Default::default())?.payload,
|| provider.load(Default::default()).map(|r| r.payload),
locale,
options,
)
}

#[allow(clippy::too_many_arguments)]
fn try_new_unstable_internal<D>(
provider: &D,
root: DataPayload<CollationRootV1Marker>,
decompositions: DataPayload<CanonicalDecompositionDataV1Marker>,
tables: DataPayload<CanonicalDecompositionTablesV1Marker>,
jamo: DataPayload<CollationJamoV1Marker>,
Expand All @@ -143,7 +151,8 @@ impl Collator {
options: CollatorOptions,
) -> Result<Self, DataError>
where
D: DataProvider<CollationDataV1Marker>
D: DataProvider<CollationRootV1Marker>
+ DataProvider<CollationTailoringV1Marker>
+ DataProvider<CollationDiacriticsV1Marker>
+ DataProvider<CollationMetadataV1Marker>
+ DataProvider<CollationReorderingV1Marker>
Expand Down Expand Up @@ -177,7 +186,7 @@ impl Collator {

let metadata = metadata_payload.get();

let tailoring: Option<DataPayload<crate::provider::CollationDataV1Marker>> =
let tailoring: Option<DataPayload<crate::provider::CollationTailoringV1Marker>> =
if metadata.tailored() {
Some(
provider
Expand Down Expand Up @@ -209,8 +218,6 @@ impl Collator {
}
}

let root: DataPayload<CollationDataV1Marker> = provider.load(Default::default())?.payload;

let tailored_diacritics = metadata.tailored_diacritics();
let diacritics: DataPayload<CollationDiacriticsV1Marker> = provider
.load(if tailored_diacritics {
Expand Down Expand Up @@ -339,7 +346,7 @@ impl Collator {
}

fn compare_impl<I: Iterator<Item = char>>(&self, left_chars: I, right_chars: I) -> Ordering {
let tailoring: &DataPayload<CollationDataV1Marker> =
let tailoring: &DataPayload<CollationTailoringV1Marker> =
if let Some(tailoring) = &self.tailoring {
tailoring
} else {
Expand All @@ -356,7 +363,7 @@ impl Collator {
// should we have a no-op tailoring that contains a
// specially-crafted CodePointTrie that always returns
// a FALLBACK_CE32 after a single branch?
&self.root
self.root.cast_ref()
};

// Sadly, it looks like variable CEs and backward second level
Expand Down
27 changes: 18 additions & 9 deletions components/collator/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const _: () = {
pub use icu_collections as collections;
}
make_provider!(Baked);
impl_collation_data_v1_marker!(Baked);
impl_collation_root_v1_marker!(Baked);
impl_collation_tailoring_v1_marker!(Baked);
impl_collation_diacritics_v1_marker!(Baked);
impl_collation_jamo_v1_marker!(Baked);
impl_collation_metadata_v1_marker!(Baked);
Expand All @@ -70,7 +71,8 @@ const _: () = {
#[cfg(feature = "datagen")]
/// The latest minimum set of markers required by this component.
pub const MARKERS: &[DataMarkerInfo] = &[
CollationDataV1Marker::INFO,
CollationRootV1Marker::INFO,
CollationTailoringV1Marker::INFO,
CollationDiacriticsV1Marker::INFO,
CollationJamoV1Marker::INFO,
CollationMetadataV1Marker::INFO,
Expand Down Expand Up @@ -114,13 +116,20 @@ fn data_ce_to_primary(data_ce: u64, c: char) -> u32 {
/// 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(marker(
CollationDataV1Marker,
"collator/data@1",
// TODO(#3867): Use script fallback
fallback_by = "language",
attributes_domain = "collator",
))]
#[icu_provider::data_struct(
marker(
CollationRootV1Marker,
"collator/root@1",
singleton,
),
marker(
CollationTailoringV1Marker,
"collator/tailoring@1",
// TODO(#3867): Use script fallback
fallback_by = "language",
attributes_domain = "collator",
)
)]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_collator::provider))]
Expand Down
6 changes: 3 additions & 3 deletions components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ fn test_nb_nn_no() {
strs.sort_by(|a, b| collator.compare(a, b));
assert_eq!(strs, expected);
assert_eq!(
DataProvider::<CollationDataV1Marker>::load(
DataProvider::<CollationTailoringV1Marker>::load(
&icu_collator::provider::Baked,
DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
Expand All @@ -1306,7 +1306,7 @@ fn test_nb_nn_no() {
strs.sort_by(|a, b| collator.compare(a, b));
assert_eq!(strs, expected);
assert_eq!(
DataProvider::<CollationDataV1Marker>::load(
DataProvider::<CollationTailoringV1Marker>::load(
&icu_collator::provider::Baked,
DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
Expand All @@ -1326,7 +1326,7 @@ fn test_nb_nn_no() {
strs.sort_by(|a, b| collator.compare(a, b));
assert_eq!(strs, expected);
assert_eq!(
DataProvider::<CollationDataV1Marker>::load(
DataProvider::<CollationTailoringV1Marker>::load(
&icu_collator::provider::Baked,
DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
Expand Down
14 changes: 7 additions & 7 deletions components/datetime/src/any/zoned_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_plurals::provider::OrdinalV1Marker;
use writeable::Writeable;

size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6224);
size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6200);

/// [`ZonedDateTimeFormatter`] is a formatter capable of formatting
/// date/times with time zones from any calendar, selected at runtime. For the difference between this and [`TypedZonedDateTimeFormatter`](crate::TypedZonedDateTimeFormatter),
Expand All @@ -49,7 +49,7 @@ size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6224);
///
/// # Examples
///
/// Using a GMT time zone:
/// Using the UTC time zone:
///
/// ```
/// use icu::calendar::DateTime;
Expand Down Expand Up @@ -82,13 +82,13 @@ size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6224);
/// );
/// ```
///
/// Using a non-GMT time zone, specified by id:
/// Using a custom time zone, specified by id:
///
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::{options::length, ZonedDateTimeFormatter};
/// use icu::locale::locale;
/// use icu::timezone::{CustomTimeZone, GmtOffset, MetazoneCalculator, ZoneVariant, TimeZoneBcp47Id};
/// use icu::timezone::{CustomTimeZone, UtcOffset, MetazoneCalculator, ZoneVariant, TimeZoneBcp47Id};
/// use tinystr::tinystr;
/// use writeable::assert_writeable_eq;
///
Expand All @@ -108,9 +108,9 @@ size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6224);
/// .expect("Failed to construct DateTime.");
/// let any_datetime = datetime.to_any();
///
/// // Create a time zone for America/Chicago at GMT-6:
/// // Create a time zone for America/Chicago at UTC-6:
/// let mut time_zone = CustomTimeZone::new_empty();
/// time_zone.gmt_offset = "-06:00".parse::<GmtOffset>().ok();
/// time_zone.offset = "-06:00".parse().ok();
/// time_zone.time_zone_id = Some(TimeZoneBcp47Id(tinystr!(8, "uschi")));
/// time_zone.zone_variant = Some(ZoneVariant::daylight());
///
Expand Down Expand Up @@ -162,7 +162,7 @@ impl ZonedDateTimeFormatter {
/// options.month = Some(components::Month::Long);
/// options.hour = Some(components::Numeric::Numeric);
/// options.minute = Some(components::Numeric::Numeric);
/// options.time_zone_name = Some(components::TimeZoneName::GmtOffset);
/// options.time_zone_name = Some(components::TimeZoneName::Offset);
///
/// let zdtf = ZonedDateTimeFormatter::try_new_experimental(
/// &locale!("en-u-ca-gregory").into(),
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/fields/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ field_type!(
/// For example: "Pacific Standard Time"
'z' => LowerZ = 0,
/// Field symbol for any of: the ISO8601 basic format with hours, minutes and optional seconds fields, the
/// long localized GMT format, or the ISO8601 extended format with hours, minutes and optional seconds fields.
/// long localized offset format, or the ISO8601 extended format with hours, minutes and optional seconds fields.
'Z' => UpperZ = 1,
/// Field symbol for the localized GMT format of a time zone.
/// Field symbol for the localized offset format of a time zone.
///
/// For example: "GMT-07:00"
'O' => UpperO = 2,
Expand Down
28 changes: 14 additions & 14 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::provider::date_time::{
use crate::time_zone::{
Bcp47IdFormat, ExemplarCityFormat, FallbackTimeZoneFormatterUnit, FormatTimeZone,
FormatTimeZoneError, GenericLocationFormat, GenericNonLocationLongFormat,
GenericNonLocationShortFormat, Iso8601Format, LocalizedGmtFormat,
GenericNonLocationShortFormat, Iso8601Format, LocalizedOffsetFormat,
SpecificNonLocationLongFormat, SpecificNonLocationShortFormat, TimeZoneDataPayloadsBorrowed,
TimeZoneFormatterUnit,
};
Expand All @@ -36,7 +36,7 @@ use icu_calendar::AnyCalendarKind;
use icu_decimal::FixedDecimalFormatter;
use icu_plurals::PluralRules;
use icu_provider::DataPayload;
use icu_timezone::{CustomTimeZone, GmtOffset};
use icu_timezone::{CustomTimeZone, UtcOffset};
use writeable::{Part, Writeable};

/// [`FormattedDateTime`] is a intermediate structure which can be retrieved as
Expand Down Expand Up @@ -752,12 +752,12 @@ where
ZS: ZoneSymbols<'data>,
{
fn write_time_zone_missing(
gmt_offset: Option<GmtOffset>,
offset: Option<UtcOffset>,
w: &mut (impl writeable::PartsWrite + ?Sized),
) -> fmt::Result {
match gmt_offset {
Some(gmt_offset) => w.with_part(Part::ERROR, |w| {
Iso8601Format::default_for_fallback().format_infallible(w, gmt_offset)
match offset {
Some(offset) => w.with_part(Part::ERROR, |w| {
Iso8601Format::default_for_fallback().format_infallible(w, offset)
}),
None => w.with_part(Part::ERROR, |w| "{GMT+?}".write_to(w)),
}
Expand All @@ -777,12 +777,12 @@ where
}
Some(custom_time_zone) => match zone_symbols {
None => {
write_time_zone_missing(custom_time_zone.gmt_offset, w)?;
write_time_zone_missing(custom_time_zone.offset, w)?;
Err(DateTimeWriteError::MissingZoneSymbols)
}
Some(zs) => match ResolvedNeoTimeZoneSkeleton::from_field(field_symbol, field_length) {
None => {
write_time_zone_missing(custom_time_zone.gmt_offset, w)?;
write_time_zone_missing(custom_time_zone.offset, w)?;
Err(DateTimeWriteError::UnsupportedField(field))
}
Some(time_zone) => {
Expand All @@ -792,8 +792,8 @@ where
match do_write_zone(units, &zone_input, payloads, w)? {
Ok(()) => Ok(()),
Err(()) => {
write_time_zone_missing(custom_time_zone.gmt_offset, w)?;
// Return an error since GMT data was missing
write_time_zone_missing(custom_time_zone.offset, w)?;
// Return an error since offset data was missing
Err(DateTimeWriteError::MissingZoneSymbols)
}
}
Expand All @@ -809,9 +809,9 @@ fn select_zone_units(time_zone: ResolvedNeoTimeZoneSkeleton) -> [Option<TimeZone
let mut formatters = (
None,
None,
// Friendly Localized GMT Format (requires "essentials" data)
// Friendly Localized offset Format (requires "essentials" data)
Some(TimeZoneFormatterUnit::WithFallback(
FallbackTimeZoneFormatterUnit::LocalizedGmt(LocalizedGmtFormat {}),
FallbackTimeZoneFormatterUnit::LocalizedOffset(LocalizedOffsetFormat {}),
)),
);
match time_zone {
Expand Down Expand Up @@ -856,11 +856,11 @@ fn select_zone_units(time_zone: ResolvedNeoTimeZoneSkeleton) -> [Option<TimeZone
));
}
// `O`
ResolvedNeoTimeZoneSkeleton::GmtShort => {
ResolvedNeoTimeZoneSkeleton::OffsetShort => {
// TODO: For now, use the long format. This should be GMT-8
}
// `OOOO`, `ZZZZ`
ResolvedNeoTimeZoneSkeleton::GmtLong => {
ResolvedNeoTimeZoneSkeleton::OffsetLong => {
// no-op
}
// 'V'
Expand Down
Loading

0 comments on commit 6378d67

Please sign in to comment.