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

fmt: remove crash! macro #5589

Merged
merged 13 commits into from
Dec 15, 2023
Merged

Conversation

Arp-1
Copy link
Contributor

@Arp-1 Arp-1 commented Nov 27, 2023

Related to issue: #5487
This removes crash! usage from fmt.

@uutils uutils deleted a comment from github-actions bot Nov 28, 2023
@uutils uutils deleted a comment from github-actions bot Nov 28, 2023
None => {
return Err(USimpleError::new(
1,
"Failed to find a k-p linebreak solution. This should never happen.",
Copy link
Member

Choose a reason for hiding this comment

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

I think this text is right actually, this can, as far as I can tell, never happen. This is because the min_by_key call only returns None if the slice is empty, but the active slice is initialized with at least one value. Maybe an unreachable! call is more appropriate here. Although, I would also love to see the code refactored so that this case is eliminated. For example, we could also choose to just unwrap_or(0) on this min_by_key call, because active is initialized with 0. I'll leave that decision up to you :)

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 makes sense. Will mark the arm unreachable! as unwrap_or can give the impression that the default value can possibly be picked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to remove it completely.

Copy link

GNU testsuite comparison:

GNU test failed: tests/tail/inotify-dir-recreate. tests/tail/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

@Arp-1
Copy link
Contributor Author

Arp-1 commented Nov 30, 2023

@tertsdiepraam I've made the requested changes. I see another related PR on this issue, please let me know if these changes are now redundant. Also, on another note, I see that some unrelated tests are failing, ....is this supposed to happen?

@tertsdiepraam
Copy link
Member

Ah I missed that there were two PRs. I don't think we should discard these changes necessarily. The other PR simply changes crash! to unreachable! which is correct, but it would be even better if we can get rid of that case altogether. We can always merge that PR and merge this later as well. Also, yeah, sometimes we have unrelated tests that fail 😕 It's an ongoing effort to fix those

@Arp-1
Copy link
Contributor Author

Arp-1 commented Nov 30, 2023

Thank you for your response @tertsdiepraam !
I've removed the usage of crash! fully in this PR by using flat_map and collect. I'm very new to rust and honestly don't have a good understanding of rust's memory model - but unless this new code discards and reallocates the vector data on heap, I don't see any other issues in the code immediately.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

I like it! Great work! I think this is the right way to go about it. I just think we should avoid the iter method to simplify a bit.

Comment on lines 368 to 369
.iter()
.flat_map(|&&(mut best_idx)| {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.iter()
.flat_map(|&&(mut best_idx)| {
.map(|&(mut best_idx)| {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

}
}
})
.collect()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.collect()
.unwrap_or_default()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail/inotify-dir-recreate is no longer failing!

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

Great! Many thanks!

@tertsdiepraam tertsdiepraam merged commit 3a7a3bf into uutils:main Dec 15, 2023
52 of 55 checks passed
@Arp-1 Arp-1 deleted the fmt-remove-crash-macro branch December 15, 2023 15:37
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.

2 participants