-
Notifications
You must be signed in to change notification settings - Fork 182
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
Fix baked fallback to work with auxiliary keys #4412
Conversation
@@ -525,17 +525,6 @@ impl BakedExporter { | |||
.insert("icu_locid_transform/compiled_data"); | |||
let search_direct = search(quote!(req.locale)); | |||
let search_iterator = search(quote!(fallback_iterator.get())); | |||
let maybe_err = if keys.contains(&String::from("und")) { | |||
// The loop will terminate on its own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this property of the generated code. It's nice because then it's clear that the loop always terminates with break
, and therefore load
is infallible. This is useful for the reader, and might even be useful for the compiler (load
probably gets inlined). I'd like to keep this property where possible.
The way to do this for keys that have aux keys would be:
- find all aux keys in
keys
- introduce a check before the loop that throws away a request if the aux key is unknown (no need to run fallback)
- if every aux key has a
und-x-foo
, then the loop terminates on its own- if only some aux keys have a
und-x-foo
, that's super weird and should probably be a warning
- if only some aux keys have a
The first step could also be done by adding static information about allowed aux keys to key metadata. I think for neo datetime the aux keys are a static set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, adding auxiliary keys breaks the invariant that any DataLocale
will eventually fall back to und
. Even worse, users can break this invariant because we have DataLocale
on all our constructors instead of having it as an internal type. This is something we need to consider before stabilizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can break the invariant whether or not we have DataLocale on our constructors by invoking DataProvider directly. It's trivial to trigger an infinite loop today by using aux keys.
I don't see how making the function have a break
changes the inlining properties of the function.
I'm not excited about making BakedExporter have special logic about aux keys. It should treat locales as opaque except for calling .is_und()
to terminate the loop.
The UTS 35 locale fallback algorithm concerns itself only with language identifiers, and we still have the invariant that the language identifier eventually falls back to und
. ICU4X additionally has the invariant that Unicode extension keywords eventually are removed. I will open a new PR documenting these invariants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see a future where the DataKeyMetadata specifies behavior regarding aux key fallback for that specific DataKey, but I do think the default behavior should be to not fall back on the aux key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's trivial to trigger an infinite loop today by using aux keys.
It's impossible to do this with stable code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and this PR makes it impossible on experimental, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me but I'll defer to Rob
Possible solution for 1.5:
Conclusions:
LGTM: @sffc @robertbastian |
Rebased and ran datagen again. Given the above agreement, I will proceed to merge this PR since it is increasingly blocking my datetime formatter work. |
I noticed that Baked Data Fallback does not work with auxiliary keys.
LocaleFallbackProvider has the following algorithm:
Baked Data fallback when "und" is not present has the following algorithm:
(When "und" is present, it doesn't include the line that breaks out of the loop.)
This breaks because "en-x-3" falls back to "und-x-3" but not all the way to "und". Example:
I fixed this by doing the following:
.is_und()
is cheap)