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

Consider having private fields for DataLocale #5989

Open
Manishearth opened this issue Jan 14, 2025 · 6 comments
Open

Consider having private fields for DataLocale #5989

Manishearth opened this issue Jan 14, 2025 · 6 comments
Labels
C-locale Component: Locale identifiers, BCP47

Comments

@Manishearth
Copy link
Member

Split off from #5785

After #5988, DataLocale is now in locale_core.

#5875 wanted it to have private fields, but locale fallback (in the locale crate) makes heavy use of these fields, reading from them and mutating them. The fallback iterator steps operate on &mut DataLocale. Migrating this to encapsulated private fields seems to be of little benefit.

The main benefit of private fields is to signpost users away from writing directly to the fields (they should use the Locale/LanguageIdentifier From impls). We're unlikely to change the composition of this type any time soon, the stability benefit is not why we want this. Perhaps we can mark these hidden? Or do nothing?

cc @zbraniecki @sffc @robertbastian

@Manishearth Manishearth added the discuss Discuss at a future ICU4X-SC meeting label Jan 14, 2025
@sffc
Copy link
Member

sffc commented Feb 4, 2025

I think keep them the way they are, in a non_exhaustive struct. We can add things, but it would likely break behavior anyway if we removed things.

@sffc sffc added the needs-approval One or more stakeholders need to approve proposal label Feb 4, 2025
@robertbastian
Copy link
Member

We should align them with the other types in icu_locale_core. Exhaustive struct, public fields, macro constructor, from/into other types, etc.

@sffc
Copy link
Member

sffc commented Feb 4, 2025

Exhaustive struct

No, because this concept of a "data locale" is not yet in a spec; it is a design doc that got some review. Even if/when we turn it into a spec, it should sit as a preview for a while.

public fields

Yes

macro constructor

Seems unnecessary, but we could add it.

from/into other types

Yes

@robertbastian
Copy link
Member

No, because this concept of a "data locale" is not yet in a spec; it is a design doc that got some review. Even if/when we turn it into a spec, it should sit as a preview for a while.

Data Locale 1.0 never had to change...

@zbraniecki
Copy link
Member

I am with Shane here - I don't think what we now have as Data Locale is what we would want to expose as stable public struct. It seems keeping it hidden as an internal struct is correct.

@robertbastian
Copy link
Member

  • @robertbastian My opinion was to see if anyone agrees. We should make them easier to construct. For locales, we have the tuple of language/region/script.
  • @sffc How would you get these outside the crate?
  • @robertbastian You could call .langauge to get a ref. And we can do that because they implement Copy. So we can make mutable accessors.
  • @sffc What's better about than mutable accessors than public fields?
  • @robertbastian I guess it just needs to be non_exhaustive for now. But then it's painful to construct.
  • @sffc We need the constructor either way.
  • @robertbastian Are you confident that we will keep the 5 fields in 3.0?
  • @sffc It's harmless to keep the 5 fields until 3.0. We don't currently use the subdivision fields in our data. We could drop them, but it's also fine to keep them. I could see DataLocale only having language/script/region. The 1.0 data model for DataLocale had language/script/region plus variants and extensions.-
  • @zbraniecki I think you answered my question, what are the odds that we use these fields in the next two years? If we see a path to using these fields, then yeah, let's keep them. They should be annotated/documented to help future generations know why they are there.

Consensus to keep the status quo, and add more convenience constructors. Maybe add a macro.

@sffc sffc added C-locale Component: Locale identifiers, BCP47 and removed discuss Discuss at a future ICU4X-SC meeting needs-approval One or more stakeholders need to approve proposal labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-locale Component: Locale identifiers, BCP47
Projects
None yet
Development

No branches or pull requests

4 participants