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

Add ResourceKey attributes and LocaleFallbackProvider #2115

Merged
merged 20 commits into from
Jul 13, 2022

Conversation

sffc
Copy link
Member

@sffc sffc commented Jun 26, 2022

Nearing completion on #1109

@jira-pull-request-webhook
Copy link

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

@sffc sffc marked this pull request as ready for review June 26, 2022 03:58
@sffc sffc requested review from Manishearth and a team as code owners June 26, 2022 03:58
@sffc
Copy link
Member Author

sffc commented Jun 26, 2022

I cleaned up the commit history so that it is reviewable commit-by-commit if you prefer.

@@ -37,6 +37,20 @@ impl fmt::Display for DataRequest {
}
}

// XXX: DataRequest should technically not implement `Borrow<ResourceOptions>` since it has
Copy link
Member Author

@sffc sffc Jun 26, 2022

Choose a reason for hiding this comment

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

@Manishearth I did this because I need a &DataRequest to pass down to the inner provider in the fallback provider. I can't pass ownership of the inner ResourceOptions to the iterator, because I need to build a DataRequest out of it at each step, and I can't have a local DataRequest and hand a &mut ResourceOptions to the iterator because I can't immutably borrow the DataRequest while one of its fields is on mutable loan. BorrowMut has the signature that I need, but according to docs.rs, it is not supposed to be used for borrowing a specific field, due to restrictions on Ord behavior.

Suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

We're misusing BorrowMut there already i think, we should be using AsMut

(that's what AsRefMut is called, it's confusing, legacy stuff, sorry)

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

overall seems pretty good!

do we have any end to end tests? fine if they're happening later

@sffc
Copy link
Member Author

sffc commented Jun 27, 2022

overall seems pretty good!

do we have any end to end tests? fine if they're happening later

There are docs tests in this PR that are effectively end-to-end.

@robertbastian robertbastian self-requested a review June 29, 2022 16:58
provider/adapters/src/fallback/adapter.rs Show resolved Hide resolved
provider/adapters/src/fallback/adapter.rs Show resolved Hide resolved
provider/adapters/src/fallback/adapter.rs Outdated Show resolved Hide resolved
while !fallback_iterator.get().options.is_empty() {
let result = self.inner.load_any(key, fallback_iterator.get());
if !result_is_err_missing_resource_options(&result) {
return result;
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually want to return data errors with the fallback_iterator.get() options set, or do we want to hide that from the client?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm catching MissingResourceOptions because that's the soft error that we can recover from. If the error is something else more severe, like a Serde deserialization error or a type mismatch error, then we should propagate it. In languages with try/catch statements, you only catch the error you want to handle, and that's what I'm doing here

Copy link
Member

Choose a reason for hiding this comment

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

I understand. But any error from the underlying provider that you don't catch will have the modified request as it's context. This might be confusing, so I propose that you also add the original request:

return result.map_err(|e| e.with_req(key, &base_req));

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

provider/adapters/src/fallback/adapter.rs Outdated Show resolved Hide resolved
provider/adapters/src/helpers.rs Show resolved Hide resolved
provider/core/src/resource.rs Show resolved Hide resolved
@sffc sffc mentioned this pull request Jul 8, 2022
@sffc sffc requested a review from robertbastian July 11, 2022 05:29
@sffc
Copy link
Member Author

sffc commented Jul 11, 2022

Notes for why I think we should keep the metadata in the string:

  • Keeps the path string as the all-inclusive serialization format for keys
  • More explicit
  • Cah switch between language-based and region-based fallback (which may affect the assignment of data to locales) without incrementing the version number

@robertbastian
Copy link
Member

Cah switch between language-based and region-based fallback (which may affect the assignment of data to locales) without incrementing the version number

Without incrementing the version number, but because the path and hash change this will amount to the same. If we keep the metadata out of the path we can change it in code and reuse the same data.

Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

Please address my outstanding comments

@sffc
Copy link
Member Author

sffc commented Jul 12, 2022

Cah switch between language-based and region-based fallback (which may affect the assignment of data to locales) without incrementing the version number

Without incrementing the version number, but because the path and hash change this will amount to the same. If we keep the metadata out of the path we can change it in code and reuse the same data.

I'm saying that the data files may actually need to change and we can't re-use the same ones. For example, CLDR JSON pre-resolves data into all locales it supports, like en-GB. However, en-GB data may change when the fallback is changed. It would be fraught to treat the same data path as supporting both language and region fallback at the same time.

@sffc sffc mentioned this pull request Jul 13, 2022
@sffc sffc requested a review from robertbastian July 13, 2022 06:09
Comment on lines +571 to +576
impl AsMut<ResourceOptions> for ResourceOptions {
fn as_mut(&mut self) -> &mut ResourceOptions {
self
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Curious what this is needed for?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are bounds in adapters/src/fallback/mod.rs that use AsMut<ResourceOptions> (rather than &mut ResourceOptions), and for whatever reason AsMut<T> isn't blanket-impled for all T

Copy link
Member Author

Choose a reason for hiding this comment

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

Also see the conversation in #2115 (comment)

provider/adapters/src/fallback/adapter.rs Show resolved Hide resolved
robertbastian
robertbastian previously approved these changes Jul 13, 2022
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

approval conditional on the error context thing

@sffc sffc merged commit 3465386 into unicode-org:main Jul 13, 2022
@sffc sffc deleted the rk-attributes branch July 13, 2022 23:47
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.

3 participants