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

Refactoring icu-data-provider crate. #198

Merged
merged 5 commits into from
Aug 28, 2020
Merged

Refactoring icu-data-provider crate. #198

merged 5 commits into from
Aug 28, 2020

Conversation

sffc
Copy link
Member

@sffc sffc commented Aug 7, 2020

Key changes in this PR:

  • Heavily refactored the code in the data-provider directory
  • Split Request into new structs, DataKey and DataEntry
  • Added DataEntryCollection, IterableDataProvider, and DataExporter traits
  • Added a new type InvariantDataProvider for development use

Note: I added a dependency on erased_serde. I need it for implementing the DataExporter trait. Unfortunately that crate is not at v1 yet. I could put DataExporter (and IterableDataProvider) behind a feature, but I will need to sprinkle the code with a lot of #[cfg]s, since the core traits are pulling in the erased_serde symbols.

@coveralls
Copy link

coveralls commented Aug 7, 2020

Pull Request Test Coverage Report for Build fe8b6a6d70cd30cc22ea6276137d06646f1a2070-PR-198

  • 176 of 276 (63.77%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.07%) to 89.652%

Changes Missing Coverage Covered Lines Changed/Added Lines %
components/data-provider/src/cloneable_any.rs 0 3 0.0%
components/data-provider/src/structs/plurals.rs 19 22 86.36%
components/data-provider/src/data_entry.rs 44 50 88.0%
components/data-provider/src/data_key.rs 67 78 85.9%
components/data-provider/src/structs/decimal.rs 4 16 25.0%
components/data-provider/src/data_provider.rs 10 39 25.64%
components/data-provider/src/error.rs 0 36 0.0%
Totals Coverage Status
Change from base Build 49431d732d0f523098676f0bf5a1e65e0680904d: -2.07%
Covered Lines: 1802
Relevant Lines: 2010

💛 - Coveralls

@sffc sffc force-pushed the sffc-dp1 branch 2 times, most recently from b20611b to 8206f63 Compare August 7, 2020 09:31
@sffc sffc marked this pull request as ready for review August 7, 2020 09:43
@sffc sffc requested a review from a team as a code owner August 7, 2020 09:43
@sffc sffc requested a review from zbraniecki August 7, 2020 09:43
@sffc
Copy link
Member Author

sffc commented Aug 7, 2020

Not sure why macOS is failing. I investigated but can't find the cause. I've re-run it a few times, and sometimes it fails in data-provider, and sometimes in locale. See #201

@sffc
Copy link
Member Author

sffc commented Aug 7, 2020

The macOS test passed at least once in this PR:

https://github.com/unicode-org/icu4x/actions/runs/198964202

The code version on that passing run (b20611b) is identical to the current head of this branch (ed79fef):

https://github.com/unicode-org/icu4x/compare/b20611b..ed79fef

zbraniecki
zbraniecki previously approved these changes Aug 18, 2020
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm!

components/data-provider/src/data_entry.rs Show resolved Hide resolved
components/data-provider/src/data_key.rs Show resolved Hide resolved
components/data-provider/src/structs/mod.rs Outdated Show resolved Hide resolved
components/data-provider/src/cloneable_any.rs Outdated Show resolved Hide resolved
components/data-provider/src/data_entry.rs Outdated Show resolved Hide resolved
components/data-provider/src/structs/plurals.rs Outdated Show resolved Hide resolved
@sffc sffc requested a review from zbraniecki August 26, 2020 03:21
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm!

I also pinged @Manishearth online to get additional eyes on the DataRequest/DataResponse pair and he responded with:

manish: it seems okay, but might be nice to have a more performant set of APIs that aren't using trait objects
zibi: what would they use?
manish: yeah i'm also not sure if it's possible
but you could have a direct API that's get_response<T>(Request) -> Result<T>
load<T>(&self, req: &DataRequest) -> Result<T, DataError>
and use that to write one that uses trait objects

I don't think this should be blocking, but putting it here for your consideration Shane. Maybe a follow-up issue?

Some(variant.clone())
} else {
None
},
Copy link
Member

Choose a reason for hiding this comment

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

could you use &data_entry.variant.cloned() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

What is cloned() a method on? Here's the error when I make this change:

error[E0599]: no method named `cloned` found for enum `std::option::Option<std::borrow::Cow<'static, str>>` in the current scope
   --> components/data-provider/src/data_entry.rs:81:37
    |
81  |                 &data_entry.variant.cloned(),
    |                                     ^^^^^^ method not found in `std::option::Option<std::borrow::Cow<'static, str>>`
    | 
   ::: /home/sffc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/option.rs:156:1
    |
156 | pub enum Option<T> {
    | ------------------ doesn't satisfy `_: std::iter::Iterator`
    |
    = note: the method `cloned` exists but the following trait bounds were not satisfied:
            `std::option::Option<std::borrow::Cow<'static, str>>: std::iter::Iterator`
            which is required by `&mut std::option::Option<std::borrow::Cow<'static, str>>: std::iter::Iterator`

Copy link

Choose a reason for hiding this comment

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

I think they meant clone().

    components: [
        // Does not actually clone if the variant is borrowed
        data_entry.variant.clone(),
        Some(Cow::Owned(data_entry.langid.to_string())),
    ],

Copy link
Member Author

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Thanks for the review! I'm going to merge this despite the open comment thread.

Some(variant.clone())
} else {
None
},
Copy link
Member Author

Choose a reason for hiding this comment

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

What is cloned() a method on? Here's the error when I make this change:

error[E0599]: no method named `cloned` found for enum `std::option::Option<std::borrow::Cow<'static, str>>` in the current scope
   --> components/data-provider/src/data_entry.rs:81:37
    |
81  |                 &data_entry.variant.cloned(),
    |                                     ^^^^^^ method not found in `std::option::Option<std::borrow::Cow<'static, str>>`
    | 
   ::: /home/sffc/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/option.rs:156:1
    |
156 | pub enum Option<T> {
    | ------------------ doesn't satisfy `_: std::iter::Iterator`
    |
    = note: the method `cloned` exists but the following trait bounds were not satisfied:
            `std::option::Option<std::borrow::Cow<'static, str>>: std::iter::Iterator`
            which is required by `&mut std::option::Option<std::borrow::Cow<'static, str>>: std::iter::Iterator`

@sffc sffc merged commit 7f7c1f4 into master Aug 28, 2020
@sffc sffc deleted the sffc-dp1 branch August 28, 2020 01:56
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.

5 participants