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

Disabling Isolation Marks in Fluent #46

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

fosskers
Copy link
Contributor

This PR is a proposed solution to #45.

@fosskers fosskers marked this pull request as ready for review November 22, 2020 02:05
@fosskers fosskers marked this pull request as draft November 22, 2020 02:05
@fosskers fosskers mentioned this pull request Nov 22, 2020
10 tasks
@fosskers
Copy link
Contributor Author

I repinned my i18n-embed dependency to my branch to test the fix, and it works. I no longer see the box characters printed.

@fosskers fosskers marked this pull request as ready for review November 22, 2020 04:34
@fosskers
Copy link
Contributor Author

Here's the usage in a commit which outputs the text as expected: fosskers/aura@53c657d#diff-c81b5030f3913711f46fce5ce5bc3cce4be2e370de609b1830661df8474fce11R18

///
/// Default: `true`.
pub fn set_use_isolating(&self, value: bool) {
for bundle in self.language_config.write().language_bundles.as_mut_slice() {
Copy link
Contributor Author

@fosskers fosskers Nov 22, 2020

Choose a reason for hiding this comment

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

Rust surprised me here. I'm able to get mutable access to the a nested field several levels down, and yet we're borrowing the parent immutably with &self.

And a question with regard to write(): I see from its docs that it blocks the thread. Is my overall approach to getting down to the internal bundle a good one?

Copy link
Owner

Choose a reason for hiding this comment

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

language_config is wrapped in an RwLock which gives it safe interior mutability with the use of runtime checks. The downside in this case is that threads will block if they try to access it when someone holds the write lock to it, but I hoped that it would not be common to be making changes to the language_config during a performance critical piece of code, thus it would at least be better than using a Mutex. It also has the property that the write lock cannot be obtained until all the read locks have been dropped.

I guess we need to be careful not to introduce a deadlock if this method will be called within another method that already holds the lock, seems like that's not the case here so it looks good to me.

@kellpossible kellpossible linked an issue Nov 23, 2020 that may be closed by this pull request
///
/// Default: `true`.
pub fn set_use_isolating(&self, value: bool) {
for bundle in self.language_config.write().language_bundles.as_mut_slice() {
Copy link
Owner

Choose a reason for hiding this comment

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

language_config is wrapped in an RwLock which gives it safe interior mutability with the use of runtime checks. The downside in this case is that threads will block if they try to access it when someone holds the write lock to it, but I hoped that it would not be common to be making changes to the language_config during a performance critical piece of code, thus it would at least be better than using a Mutex. It also has the property that the write lock cannot be obtained until all the read locks have been dropped.

I guess we need to be careful not to introduce a deadlock if this method will be called within another method that already holds the lock, seems like that's not the case here so it looks good to me.

/// information.
///
/// Default: `true`.
pub fn set_use_isolating(&self, value: bool) {
Copy link
Owner

@kellpossible kellpossible Nov 23, 2020

Choose a reason for hiding this comment

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

perhaps we could add a unit/integration test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, perhaps it would sufficient to check the byte lengths of the output strings? I'll add a commit today.

Copy link
Owner

Choose a reason for hiding this comment

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

I guess so, or to be more specific you could check if the string contains the expected special characters or not. One test with it enabled, and one without it enabled.

@kellpossible kellpossible linked an issue Nov 23, 2020 that may be closed by this pull request
@fosskers
Copy link
Contributor Author

Done! Should be good to go. Note the comment I added about calling set_use_isolating after loading languages.

@kellpossible
Copy link
Owner

Awesome! Looks good now, I'll try to merge it and push a new release today, thanks for all the help!

@kellpossible kellpossible merged commit 0b05df6 into kellpossible:master Nov 24, 2020
@fosskers fosskers deleted the colin/bidi-isolation-marks branch November 24, 2020 15:52
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.

Disabling Bidirectional Isolation in Fluent i18n-embed (fluent): Visual artifacts around inserted arguments
2 participants