-
Notifications
You must be signed in to change notification settings - Fork 176
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
Use Pattern
more directly
#5531
Use Pattern
more directly
#5531
Conversation
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.
Praise: I'm in favor of this change and the work you did looks quite good. I have some suggestions/nits/issues about some corners.
/// | ||
/// To parse a pattern string, use [`FromStr::from_str`]. | ||
/// | ||
/// # Examples |
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.
Nit: Bring back the example, please
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 is a moot examples because users don't have to do store-juggling anymore.
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.
Stores are still public, yes?
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.
No
utils/pattern/src/frontend/serde.rs
Outdated
#[allow(clippy::unwrap_used)] // todo does this work? | ||
Self(Pattern::try_from_boxed_store(Default::default()).unwrap()) |
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.
Why do you need to impl Default?
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.
To use this in CLDR JSON.
94d671a
to
4691344
Compare
@robertbastian I want to add custom baked constructors in order to fix #5230, but it would directly conflict with this PR. Are you planning to finish/merge this soon? |
13a4b0f
to
6b6a535
Compare
44de101
to
5a02124
Compare
This reverts commit 6b6a535.
5a02124
to
ca82adb
Compare
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.
(almost done reviewing)
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.
Good work; nothing blocks landing this PR, which I prefer to do in order to prevent bitrot, but there are a few small things I'd like to see fixed in a follow-up
deserialize_with = "icu_pattern::deserialize_option_borrowed_cow" | ||
) | ||
)] | ||
pub standard_pattern: Option<Cow<'data, DoublePlaceholderPattern>>, |
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.
Thought: I think we should do as you suggested in the other issue. We can export a ZeroCow
type from zerovec
that has the correct Serde impls and reduces one layer of struct construction in the Bake impl. (Not in this PR)
utils/pattern/src/frontend/serde.rs
Outdated
D: serde::Deserializer<'de>, | ||
{ | ||
Ok(Self( | ||
Pattern::<B>::try_from_str(&<Cow<str>>::deserialize(deserializer)?, Default::default()) |
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.
Nit: I think <Cow<str>>::deserialize
always deserializes to a String. serde_derive
has special-case code that essentially adds a deserialize_with
if Syn sees a Cow<str>
. It doesn't actually specialize Cow<str>
to borrow when possible.
utils/pattern/src/implementations.rs
Outdated
unsafe impl VarULE for Pattern<SinglePlaceholder, str> { | ||
unsafe impl<B> VarULE for Pattern<B> | ||
where | ||
B: PatternBackend<Store = str>, |
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.
Suggestion: does this work with B::Store: VarULE
?
Cool this triggers an ICE |
|
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.
LGTM up to this point
The ICE says: found_trait_ref:
expected_trait_ref:
So something about I see some HRTBs in this PR which probably doesn't help. Also, this only happens in Initial guess: what happens if you change the |
Oh I just noticed this in the error output, too
So it's in Serde |
@robertbastian ICE fixed. Ready to land? |
it's not pretty that you have to add the generics when using |
We switched from exercising one compiler bug to another. Adding the generics is required due to rust-lang/rust#130180 (see #5510 (comment)) |
The way to actually fix this, I think, is to introduce a new type such as |
Removed the
Store
generic fromPattern
. It now always uses the unsizedPatternBackend::Store
. Instead of usingPattern<B, String>
for the owned version, it's nowBox<Pattern<B>>
Implemented
ToOwned
forPattern
so that we can useCow<Pattern<B>>
. The owned type isBox<Pattern<B>>
Replaced the
FromStr
implementation bytry_from_str
, which returnsBox<Self>
Removed the
PluralPatterns
type, this now usesPluralElementsPackedCow<Pattern<B>>
directlyChanged pattern JSON serialization to use actual pattern string, instead of vecs of itemsChanged CLDR parsing to use patterns directly in CLDR JSON structs