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

Making IterableDataProvider #[no_std] #5176

Merged
merged 5 commits into from
Jul 8, 2024

Conversation

robertbastian
Copy link
Member

By using BTreeSet instead of HashSet. This removes the std feature from icu_provider_adapters.

Also removed DataLocale::is_empty, which is the same as DataLocale::is_und, but "und" is a better description of that state.

@robertbastian robertbastian requested review from sffc, Manishearth and a team as code owners July 4, 2024 10:09
sffc
sffc previously approved these changes Jul 4, 2024
Copy link
Member

@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.

Nothing is blocking but I would like to see all three resolved if not here then in a follow-up

Comment on lines +132 to +133
.then_with(|| self.locale.langid.total_cmp(&other.locale.langid))
.then_with(|| self.locale.keywords.cmp(&other.locale.keywords))
Copy link
Member

Choose a reason for hiding this comment

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

Issue: self.locale.langid and self.locale.keywords are private fields of DataLocale and they should not be being read by DataIdentifier; when we change DataLocale to have a different set of private fields, it should stay that way. I'm not sure why you removed DataLocale::total_cmp.

Copy link
Member Author

Choose a reason for hiding this comment

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

DataIdentifier and DataLocale are very tightly coupled. I'm removing DataLocale::total_cmp because nobody should be putting a DataLocale in a BTreeMap, downstream code should always deal with DataIdentifiers.

Copy link
Member

Choose a reason for hiding this comment

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

If the fields are private, it's not correct for code from a different struct to read them. You could make DataLocale::total_cmp be pub(crate) if you don't want people using it. But I won't block the PR on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

The fields are module-private, and are used from code in the same module.

Copy link
Member

Choose a reason for hiding this comment

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

The types could be freely moved between module; I anticipate that DataLocale may make its way elsewhere, such as into icu_preferences. I would strongly prefer to keep the fields with struct-private behavior. It's not worth blocking the PR, but you've stated before, and I agree, that small issues should be resolved now instead of later.

Comment on lines -480 to -482
pub fn is_empty(&self) -> bool {
self == <&DataLocale>::default()
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think I prefer is_empty since that is what we use in Language and LanguageIdentifier. Also, is_und is ambiguous because does it return true or false for something like und-CH?

Copy link
Member Author

@robertbastian robertbastian Jul 4, 2024

Choose a reason for hiding this comment

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

It's called is_und on LanguageIdentifier. The language identifier is "und", it's not empty ("").

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh whoops. This is unreleased, and I think is_und is a better name, so I'd rather change LanguageIdentifier.

Copy link
Member

Choose a reason for hiding this comment

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

This PR introduces an inconsistency which should be resolved before 2.0. I approved the LanguageIdentifier change a month or so ago because I think is_empty is the correct name. It sounds like we need to bikeshed.

if provider.iter_ids_for_marker(marker)? != HashSet::from_iter([Default::default()])
{
let supported = provider.iter_ids_for_marker(marker)?;
if supported.len() != 1 || !supported.first().unwrap().is_default() {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Write this in a way that avoids the unwrap. Something like

if !matches!((iter.next(), iter.next()), (Some(DataIdentifier::DEFAULT), None)) { ... }
Copy link
Member

Choose a reason for hiding this comment

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

^ This wasn't resolved, either

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think your suggestion is an improvement.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is to remove the unwrap. I offered a one-liner to do so. I would normally block a PR on this but since it is in the export code I won't block on it.

@robertbastian robertbastian requested a review from sffc July 5, 2024 10:51
sffc
sffc previously approved these changes Jul 5, 2024
Copy link
Member

@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.

None of my three editorial suggestions were resolved. If you merge, please make another PR resolving them.

Copy link
Member

@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.

Approving, but please file follow-up issues for at least the question about is_und naming and maybe the other editorial comments.

@robertbastian robertbastian merged commit c8a8801 into unicode-org:main Jul 8, 2024
28 checks passed
@robertbastian robertbastian deleted the std branch July 16, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants