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

Add missing keys to CollatorPreferences #5950

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

jedel1043
Copy link
Contributor

Adds support for kn and kf on CollatorPreferences.

@hsivonen
Copy link
Member

hsivonen commented Jan 2, 2025

Looks OK to me, but I let @zbraniecki review the macro usage.

@zbraniecki
Copy link
Member

Thank you for the PR! The only thing I'd like to ponder over is that you're introducing an example where our sepration of Preferences and Options gets blurry - the developer sets an option, and user may set another. We have to decide who takes precedence.

@jedel1043
Copy link
Contributor Author

jedel1043 commented Jan 2, 2025

@zbraniecki FWIW, on ECMA402 explicit configs take priority over unicode keys, so I expressed that here. If we want to add more flexibility for it, I think we can add an option to explicitly prioritise either one of them.

CollationCaseFirst::Upper => CaseFirst::UpperFirst,
CollationCaseFirst::Lower => CaseFirst::LowerFirst,
CollationCaseFirst::False => CaseFirst::Off,
_ => unreachable!("`CaseFirst` and `CollationCaseFirst` must always be in sync."),
Copy link
Member

Choose a reason for hiding this comment

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

q: Should we panic here or debug_assert and in release select [default]?

CaseFirst::Off => CollationCaseFirst::False,
CaseFirst::LowerFirst => CollationCaseFirst::Lower,
CaseFirst::UpperFirst => CollationCaseFirst::Upper,
}
Copy link
Member

Choose a reason for hiding this comment

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

Why you don't need a catch case despite CaseFirst being non-exhaustive?

Should we switch Options to use CollactionCaseFirst from Preferences then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#[non_exhaustive] only applies for external crates that use the enum.

I preserved the old enum because I wanted to avoid unnecessary breaking changes, but we can switch to that if preferred.

Copy link
Member

Choose a reason for hiding this comment

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

We have a shot at doing it in 2.0, I think i'd prefer that. @sffc @Manishearth @robertbastian - you ok with that?

Copy link
Member

Choose a reason for hiding this comment

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

I have a slight preference for removing the settings from options and moving them to preferences in 2.0

Copy link
Member

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be clear – we would move the relevant options to CollatorPreferences, using the structs on icu_locale_core, and the rest of the options would still be in CollatorOptions, is that right?

Copy link
Member

Choose a reason for hiding this comment

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

correct!

@jedel1043
Copy link
Contributor Author

Ok, switched it to use preference keyword structs and removed the old config structs. Had to slightly adjust the documentation to mention CollatorPreferences, but it should be feature-complete.

@jedel1043 jedel1043 requested a review from zbraniecki January 6, 2025 06:19
@zbraniecki
Copy link
Member

Oh, interesting. Am I correct to read your PR as - you removed the two preferences from Options, and allow for setting it by the developer by overriding Preferences?

In other words if the developer wants to set one of those two, they interact with Preferences bag, not Options bag anymore?

@jedel1043
Copy link
Contributor Author

jedel1043 commented Jan 6, 2025

@zbraniecki Yes. That way, the problem we had about priority is solved in an arguably cleaner way, since users can either extend the implicit locale preferences with explicit preferences to give priority to the latter, or do the opposite to give priority to the former.

@zbraniecki
Copy link
Member

Yes. That way, the problem we had about priority is solved in an arguably cleaner way, since users can either extend the implicit locale preferences with explicit preferences to give priority to the latter, or do the opposite to give priority to the former.

Ok, so you think this is even a cleaner approach! I value your perspective as an implementer. I think I have a hard time deciding on the tradeoffs around it.
My main concern would be that Preferences are intended to be out of control for developers - they accept it (from Locale and from Regional Prefs of their system) and pass it on. The Options on the other hand are meant to be set by the developer. I thought this is a nice clean design but of course reality check is that there are cases where Prefs and Options duplicate and you brought up this here.

With your change we're telling developers to touch Preferences manually. The value of it is that, as you rightly pointed out, it is clean and allows developers to control which direction they want to merge - options->prefs, or prefs->options. ECMA-402 specifies one, but that doesn't mean everyone has to repeat it.

The downsides are:

  1. we make the distinction between Prefs and Options murky. "Prefs are for customers, but if you want to set X, modify them, as you do with Options"
  2. we're now explicitly requiring implementers to think of this nuance and risk getting it wrong or not at all.

I think I'm fine with that as the benefit outweights the cost for me but wanted to have this explicit paper trail of this decision to revisit in the future.

zbraniecki
zbraniecki previously approved these changes Jan 6, 2025
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! thank you!

sffc
sffc previously approved these changes Jan 13, 2025
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.

Need to discuss the re-export in #5915 but otherwise this looks great; thanks!

Comment on lines 324 to 327
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationCaseFirst;
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationNumericOrdering;
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationType;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: don't pub use; clients should import these from icu::locale.

Unless we want to re-export them? I'm not opposed to that, but we don't do it elsewhere. #5915

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I think I also prefer clients importing from icu::locale.

@jedel1043 jedel1043 dismissed stale reviews from sffc and zbraniecki via aaf1bd8 January 14, 2025 22:59
@jedel1043 jedel1043 force-pushed the collator-missing-prefs branch from 0f26ab8 to aaf1bd8 Compare January 14, 2025 22:59
@jedel1043
Copy link
Contributor Author

Ok, made some more changes which include renaming the export from CollationCaseFirst to CaseFirst on the root of icu_collator. This aligns with @sffc's comment, and I think it looks a lot cleaner.

@jedel1043 jedel1043 requested review from sffc and zbraniecki January 14, 2025 23:07
@sffc sffc added the discuss-priority Discuss at the next ICU4X meeting label Jan 14, 2025
@@ -285,12 +322,13 @@ extern crate alloc;
pub use comparison::Collator;
pub use comparison::CollatorBorrowed;
pub use comparison::CollatorPreferences;
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationCaseFirst as CaseFirst;
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationNumericOrdering as NumericOrdering;
pub use icu_locale_core::preferences::extensions::unicode::keywords::CollationType;
pub use options::AlternateHandling;
Copy link
Member

Choose a reason for hiding this comment

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

Observation: in icu_datetime, options is a public module/namespace. But icu_collator re-exports the things from the top level.

Copy link
Member

Choose a reason for hiding this comment

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

@zbraniecki
Copy link
Member

Thank you for your work on this @jedel1043 !

@zbraniecki zbraniecki merged commit fc8240b into unicode-org:main Jan 15, 2025
28 checks passed
@jedel1043 jedel1043 deleted the collator-missing-prefs branch January 15, 2025 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss-priority Discuss at the next ICU4X meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants