-
Notifications
You must be signed in to change notification settings - Fork 97
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
Resolve more pattern types into &str references #305
base: main
Are you sure you want to change the base?
Resolve more pattern types into &str references #305
Conversation
Before these changes, Cow::Borrowed was returned 14 out of 174 times in fluent-bundle test cases. After the changes, I'm seeing 67 out of 174. |
@JasperDeSutter I didn't get a chance to finish reviewing all of your PRs before the holidays. I'll be back in the new year. |
I'm back from the holidays, but may still need a few days to get caught up for reviews. |
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.
Thanks for the PR! I am only marking as "Request Changes" so that I can see your response to my feedback. The PR looks good, I had a few minor comments and suggestions. Some of them are optional, which if you don't have the time, I can merge without them.
Please re-flag me for review, and we can get this merged!
return variant.value.resolve(scope); | ||
} | ||
} | ||
scope.add_error(ResolverError::MissingDefault); |
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.
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 unreachable code since a default variant is required, which is checked by the parser already. I think this doesn't warrant an explicit resolver error since we know it wont ever arise. A panic would be better suited IMO.
5615698
to
7ad6779
Compare
98f63ba
to
908d6c7
Compare
Rebased to update commit messages, get current CI jobs to run, and run |
908d6c7
to
ae6fa28
Compare
ae6fa28
to
b3b2124
Compare
...and also fixed the |
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.
Thanks for the contribution(s).
It looks like this could use a few new unit tests.
.map_or_else(|| value.into(), |transform| transform(value).into()); | ||
} | ||
ast::PatternElement::Placeable { expression } => { | ||
let before = scope.placeables; |
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.
There's a ~7% performance regression in the resolve_to_str benchmark that I can't explain yet. It can be observed by commenting out the code in this match arm.
The most important change is in
fluent-bundle/src/resolver/pattern.rs
, the rest is adding missing codepaths that were previously only done throughWriteValue
and are now also needed inResolveValue
.There are more cases where we can resolve to a borrowed str than just the TextElement case. For example there might be a select that resolves into a single TextElement, or a TermReference which is a simple string.
With these changes,
ResolveValue
methods will be called until a pattern with more than 1 element is found, which needs string concatenation and is handled by theWriteValue
methods as before.When resolving into a
FluentValue::Error
, theWriteValue
is called to get "{error}" formatting instead of an empty string.