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

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

Conversation

jedel1043
Copy link
Contributor

Adds support for kn and kf on CollatorPreferences.

@jedel1043 jedel1043 force-pushed the collator-missing-prefs branch from ffa47b4 to 2849caa Compare January 1, 2025 19:26
@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.

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!

@zbraniecki zbraniecki requested review from sffc and Manishearth January 6, 2025 21:06
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