Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch PluralRules Data to ZeroVec #1240

Merged
merged 30 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26de9b9
Separate runtime and reference rules in PluralRules.
zbraniecki Oct 13, 2021
fb3034f
Add ZeroVec::borrowed_from_slice()
Manishearth Oct 18, 2021
830549a
Add RelationULE::as_relation()
Manishearth Oct 18, 2021
a1ed16e
Add encoding/decoding for andor/plurals/operand
Manishearth Oct 18, 2021
92d4889
fix encode
Manishearth Oct 20, 2021
ce1e773
fix from_byte_slice_unchecked
Manishearth Oct 20, 2021
66bf8cd
slightly better impl
Manishearth Oct 20, 2021
978c6e3
Plug it all together
zbraniecki Oct 28, 2021
5fd0dbb
Fix tests
zbraniecki Oct 29, 2021
bad24b0
Apply feedback
zbraniecki Nov 3, 2021
562602b
Add RelationULE doc
zbraniecki Nov 4, 2021
1f5c9c3
Apply feedback
zbraniecki Nov 5, 2021
85bef5f
Add inlines and docs
zbraniecki Nov 5, 2021
2aca97a
Uncomment tests
zbraniecki Nov 5, 2021
02eba1c
Apply reviewers feedback
zbraniecki Nov 8, 2021
55f1f30
Fix tests and apply feedback
zbraniecki Nov 10, 2021
c6925e8
Revise postcard file
zbraniecki Nov 10, 2021
af0a5bf
Fix provider benchmarks
zbraniecki Nov 10, 2021
53bdb26
Fix more tests
zbraniecki Nov 10, 2021
ac11dae
Add rountrip test
zbraniecki Nov 11, 2021
4344425
Fix another test
zbraniecki Nov 11, 2021
d3ac05c
Fix more tests
zbraniecki Nov 11, 2021
e64d626
Update postcard
zbraniecki Nov 11, 2021
aa05c79
Fix readme
zbraniecki Nov 11, 2021
3059542
Regenerate diplomat ffi
zbraniecki Nov 11, 2021
8e64819
Fix diplomat example
zbraniecki Nov 11, 2021
4d8696f
Fix test-cpp
zbraniecki Nov 11, 2021
365f8bd
Update safety comment
zbraniecki Nov 12, 2021
460b5b6
Apply feedback
zbraniecki Nov 15, 2021
8db9c46
No need to guard local type used for debug test. DCE will take care o…
zbraniecki Nov 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions components/datetime/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};
use alloc::string::String;
use icu_locid::Locale;
use icu_plurals::{provider::PluralRuleStringsV1Marker, PluralRuleType, PluralRules};
use icu_plurals::{provider::PluralRulesV1Marker, PluralRuleType, PluralRules};
use icu_provider::prelude::*;

use crate::{
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct DateTimeFormat<'data> {
pub(super) locale: Locale,
pub(super) patterns: DataPayload<'data, PatternPluralsFromPatternsV1Marker>,
pub(super) symbols: Option<DataPayload<'data, DateSymbolsV1Marker>>,
pub(super) ordinal_rules: Option<PluralRules>,
pub(super) ordinal_rules: Option<PluralRules<'data>>,
}

impl<'data> DateTimeFormat<'data> {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'data> DateTimeFormat<'data> {
D: DataProvider<'data, DateSymbolsV1Marker>
+ DataProvider<'data, DatePatternsV1Marker>
+ DataProvider<'data, DateSkeletonPatternsV1Marker>
+ DataProvider<'data, PluralRuleStringsV1Marker>,
+ DataProvider<'data, PluralRulesV1Marker>,
{
let locale = locale.into();

Expand All @@ -113,7 +113,7 @@ impl<'data> DateTimeFormat<'data> {

let ordinal_rules = if let PatternPlurals::MultipleVariants(_) = &patterns.get().0 {
Some(PluralRules::try_new(
langid.clone(),
locale.clone(),
data_provider,
PluralRuleType::Ordinal,
)?)
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'data> DateTimeFormat<'data> {
locale: T,
patterns: DataPayload<'data, PatternPluralsFromPatternsV1Marker>,
symbols: Option<DataPayload<'data, DateSymbolsV1Marker>>,
ordinal_rules: Option<PluralRules>,
ordinal_rules: Option<PluralRules<'data>>,
) -> Self {
let locale = locale.into();

Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
pub(crate) symbols: Option<&'l provider::gregory::DateSymbolsV1>,
pub(crate) datetime: &'l T,
pub(crate) locale: &'l Locale,
pub(crate) ordinal_rules: Option<&'l PluralRules>,
pub(crate) ordinal_rules: Option<&'l PluralRules<'data>>,
}

impl<'l, 'data, T> Writeable for FormattedDateTime<'l, 'data, T>
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/zoned_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use alloc::string::String;
use icu_locid::{LanguageIdentifier, Locale};
use icu_plurals::{provider::PluralRuleStringsV1Marker, PluralRuleType, PluralRules};
use icu_plurals::{provider::PluralRulesV1Marker, PluralRuleType, PluralRules};
use icu_provider::{DataProvider, DataRequest, ResourceOptions, ResourcePath};

use crate::{
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'data> ZonedDateTimeFormat<'data> {
+ DataProvider<'data, provider::time_zones::MetaZoneSpecificNamesLongV1Marker>
+ DataProvider<'data, provider::time_zones::MetaZoneSpecificNamesShortV1Marker>
+ ?Sized,
PP: DataProvider<'data, PluralRuleStringsV1Marker> + ?Sized,
PP: DataProvider<'data, PluralRulesV1Marker>,
{
let locale = locale.into();
let langid: LanguageIdentifier = locale.clone().into();
Expand All @@ -131,7 +131,7 @@ impl<'data> ZonedDateTimeFormat<'data> {

let ordinal_rules = if let PatternPlurals::MultipleVariants(_) = &patterns.get().0 {
Some(PluralRules::try_new(
langid.clone(),
locale.clone(),
plural_provider,
PluralRuleType::Ordinal,
)?)
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use icu_datetime::{
DateTimeFormat, DateTimeFormatOptions, ZonedDateTimeFormat,
};
use icu_locid::{LanguageIdentifier, Locale};
use icu_plurals::provider::PluralRuleStringsV1Marker;
use icu_plurals::provider::PluralRulesV1Marker;
use icu_provider::prelude::*;
use icu_provider::struct_provider::StructProvider;
use patterns::{
Expand Down Expand Up @@ -65,11 +65,11 @@ impl<'data> DataProvider<'data, DatePatternsV1Marker> for MultiKeyStructProvider
}
}

impl<'data> DataProvider<'data, PluralRuleStringsV1Marker> for MultiKeyStructProvider<'data> {
impl<'data> DataProvider<'data, PluralRulesV1Marker> for MultiKeyStructProvider<'data> {
fn load_payload(
&self,
_req: &DataRequest,
) -> Result<DataResponse<'data, PluralRuleStringsV1Marker>, icu_provider::DataError> {
) -> Result<DataResponse<'data, PluralRulesV1Marker>, icu_provider::DataError> {
Err(icu_provider::DataError::MissingPayload)
}
}
Expand Down
4 changes: 3 additions & 1 deletion components/plurals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ icu_provider = { version = "0.4", path = "../../provider/core", features = ["mac
icu_locid = { version = "0.4", path = "../locid" }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
displaydoc = { version = "0.2.3", default-features = false }
zerovec = { version = "0.4", path = "../../utils/zerovec", features = ["yoke"] }
num_enum = { version = "0.5", default_features = false }

[dev-dependencies]
criterion = "0.3"
Expand All @@ -57,7 +59,7 @@ bench = false # This option is required for Benchmark CI
std = ["icu_locid/std", "icu_provider/std"]
default = ["provider_serde"]
bench = []
provider_serde = ["serde"]
provider_serde = ["serde", "zerovec/serde"]

[[bench]]
name = "operands"
Expand Down
6 changes: 3 additions & 3 deletions components/plurals/benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use icu_provider::prelude::*;

fn parser(c: &mut Criterion) {
use icu_plurals::rules::parse_condition;
use icu_plurals::rules::reference::parse_condition;

let fixture_data = helpers::get_plurals_data();

Expand All @@ -19,7 +19,7 @@ fn parser(c: &mut Criterion) {
let mut rules = vec![];

for langid in &fixture_data.langs {
let data_payload: DataPayload<icu_plurals::provider::PluralRuleStringsV1Marker> = provider
let data_payload: DataPayload<icu_plurals::provider::PluralRulesV1Marker> = provider
.load_payload(&DataRequest {
resource_path: ResourcePath {
key: icu_plurals::provider::key::CARDINAL_V1,
Expand Down Expand Up @@ -57,7 +57,7 @@ fn parser(c: &mut Criterion) {

#[cfg(feature = "bench")]
c.bench_function("plurals/parser/lex", |b| {
use icu_plurals::rules::Lexer;
use icu_plurals::rules::reference::Lexer;
b.iter(|| {
for rule in &rules {
let _ = Lexer::new(black_box(rule.as_bytes())).count();
Expand Down
123 changes: 0 additions & 123 deletions components/plurals/src/data.rs

This file was deleted.

2 changes: 1 addition & 1 deletion components/plurals/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::rules::parser::ParserError;
use crate::rules::reference::parser::ParserError;
use displaydoc::Display;
use icu_provider::prelude::DataError;

Expand Down
Loading