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

Implement Extended Currency DataModel #4706

Open
wants to merge 51 commits into
base: main
Choose a base branch
from

Conversation

younies
Copy link
Member

@younies younies commented Mar 19, 2024

No description provided.

@younies younies requested a review from a team as a code owner March 19, 2024 10:57
@younies younies marked this pull request as draft March 19, 2024 10:59
Comment on lines 41 to 45
/// A mapping from each currency's ISO code to its associated formatting patterns.
// Using CurrencyPatternConfig until implementing AsULE for ExtendedCurrencyPatternConfig.
// use short for long right now.
#[cfg_attr(feature = "serde", serde(borrow))]
pub patterns_config: ZeroMap<'data, Count, CurrencyPatternConfig>,
Copy link
Member

@sffc sffc Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I think in general the best way to store things that vary by plural form is to pull out the other variant and store all the others in the map. Something more like

/// For plural form 'other'
pub pattern_config_other: CurrencyPatternConfig,
/// For all other plural forms and explicit forms
pub pattern_config_plurals: ZeroMap<'data, Count, CurrencyPatternConfig>,

This is good because

  1. The fallback to other is infallible
  2. In locales that don't use plurals (like CJK), the ZeroMap becomes empty, which is nice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea, we treated it as default pattern.

@younies younies changed the title Implement Extended Currency Data for Currency Formatter Implement Extended Currency Mar 28, 2024
@younies younies changed the title Implement Extended Currency Implement Extended Currency DataModel Mar 28, 2024
@younies
Copy link
Member Author

younies commented Jun 5, 2024

@sffc and @robertbastian

when I run cargo make testdata

I received the following error message

thread 'provider::tests::make_testdata::make_testdata' panicked at provider/datagen/src/provider/tests/make_testdata.rs:302:9:
Expected violations list does not match found violations!
If the new list is smaller, please update EXPECTED_VIOLATIONS in make-testdata.rs
If it is bigger and that was unexpected, please make sure the key remains zero-copy, or ask ICU4X team members if it is okayto temporarily allow for this key to be allowlisted.
Expected:
[DataKey{datetime/skeletons@1}]
Found:
[DataKey{currency/extended@1}, DataKey{datetime/skeletons@1}]
Expected (transient):
[DataKey{list/and@1}, DataKey{list/or@1}, DataKey{list/unit@1}]
Found (transient):
[DataKey{list/and@1}, DataKey{list/or@1}, DataKey{list/unit@1}]

@sffc
Copy link
Member

sffc commented Jun 5, 2024

It means that DataKey{currency/extended@1} contains allocated data and you need to make it zero-copy.

@sffc
Copy link
Member

sffc commented Jun 5, 2024

It looks like you forgot to add #[cfg_attr(feature = "serde", serde(borrow))] on all of the fields. If you don't have that annotation, they always get deserialized as fully owned (allocated).

@younies
Copy link
Member Author

younies commented Jun 5, 2024

It looks like you forgot to add #[cfg_attr(feature = "serde", serde(borrow))] on all of the fields. If you don't have that annotation, they always get deserialized as fully owned (allocated).

@sffc : thanks for the notice, but even I applied this, still I get the same message

Expected violations list does not match found violations!
If the new list is smaller, please update EXPECTED_VIOLATIONS in make-testdata.rs
If it is bigger and that was unexpected, please make sure the key remains zero-copy, or ask ICU4X team members if it is okayto temporarily allow for this key to be allowlisted.
Expected:
[DataKey{datetime/skeletons@1}]
Found:
[DataKey{currency/extended@1}, DataKey{datetime/skeletons@1}]
Expected (transient):
[DataKey{list/and@1}, DataKey{list/or@1}, DataKey{list/unit@1}]
Found (transient):
[DataKey{list/and@1}, DataKey{list/or@1}, DataKey{list/unit@1}]

@robertbastian
Copy link
Member

Serde is too limited to borrow through an Option, you need to use one of the methods in provider/core/src/serde/borrow_de_utils.rs

@sffc
Copy link
Member

sffc commented Jun 5, 2024

serde-rs/serde#2016 again

@robertbastian
Copy link
Member

Wow they locked that thread.

@sffc
Copy link
Member

sffc commented Jun 5, 2024

Since the Serde issue doesn't keep track of linked issues any more, let's start using #1556 to keep track of all the cases where we've wasted time re-discovering and re-working-around this issue (which I still hold to be fully in scope for Serde core)

@younies younies marked this pull request as ready for review June 6, 2024 09:56
@younies younies requested a review from Manishearth as a code owner June 6, 2024 09:56
@younies
Copy link
Member Author

younies commented Jun 6, 2024

right now, I added those fields to the display_names map in order to avoid this :)

actually, this will reduce the datasize by replacing the none case with empty.

@younies younies removed the request for review from Manishearth June 6, 2024 11:06
@sffc
Copy link
Member

sffc commented Jun 7, 2024

This looks good, but I would like to see a way to reduce the number of currency JSON files generated in testdata if possible? Thoughts @robertbastian?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants