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

Resolve more pattern types into &str references #305

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

Conversation

JasperDeSutter
Copy link
Contributor

The most important change is in fluent-bundle/src/resolver/pattern.rs, the rest is adding missing codepaths that were previously only done through WriteValue and are now also needed in ResolveValue.

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 the WriteValue methods as before.

When resolving into a FluentValue::Error, the WriteValue is called to get "{error}" formatting instead of an empty string.

@JasperDeSutter
Copy link
Contributor Author

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.

@gregtatum
Copy link
Member

@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.

@gregtatum
Copy link
Member

I'm back from the holidays, but may still need a few days to get caught up for reviews.

Copy link
Member

@gregtatum gregtatum left a 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (optional): Is it possible to trigger this error in a test? It appears uncovered.

image

Copy link
Contributor Author

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.

fluent-bundle/src/resolver/pattern.rs Show resolved Hide resolved
fluent-bundle/src/resolver/scope.rs Show resolved Hide resolved
@alerque
Copy link
Collaborator

alerque commented May 6, 2024

Rebased to update commit messages, get current CI jobs to run, and run cargo clippy on each commit. Working on rebase to main now.

@alerque
Copy link
Collaborator

alerque commented May 6, 2024

...and also fixed the rustfmt issue.

Copy link
Collaborator

@alerque alerque left a 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;
Copy link
Contributor Author

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.

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.

None yet

3 participants