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

Remove ChunksFixed which contains one line of unsafe code. #1736

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

briansmith
Copy link
Owner

See the individual commit messages.

chunks_fixed.rs didn't have a license header when it should have. That means that the original LoC total is 14 LoC lower than it should have been. Thus this change is +13 -48 -14 (net -49) LoC, which combined with PR #1732's net +58 means that this project cost 11 LoC using the most naive metric of complexity we can get.

Unlike in PR #1732, here we're using potentially-panicking array slicing or equivalent (e.g. copy_from_slice). So we're trading static guarantee of not panicking for static guarantee of safety. In this code it is obvious that no panic will be occur so it's not a giant deal. We do the same elsewhere, unfortunately.

I don't feel super great about that. However, I think it does help us evaluate using zerocopy or other dependencies (ideally an improved standard library and/or language) to eliminate use of potentially-panicking APIs in addition to eliminating use of unsafe and/or making our unsafe use safer.

@briansmith briansmith self-assigned this Oct 13, 2023
@briansmith
Copy link
Owner Author

@joshlf PTAL.

@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #1736 (1d4e416) into main (a9b8882) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1736      +/-   ##
==========================================
- Coverage   96.02%   96.00%   -0.03%     
==========================================
  Files         138      137       -1     
  Lines       20794    20790       -4     
  Branches      226      226              
==========================================
- Hits        19968    19959       -9     
- Misses        790      792       +2     
- Partials       36       39       +3     
Files Coverage Δ
src/aead/chacha20_poly1305_openssh.rs 87.65% <100.00%> (ø)
src/digest/sha1.rs 100.00% <100.00%> (ø)
src/polyfill.rs 100.00% <ø> (ø)

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

for &'a [T; $unchuncked_len]
{
#[inline(always)]
fn chunks_fixed(self) -> &'a [[T; $chunk_len]; $chunked_len] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you've been asking about other places zerocopy might help: this method should be able to be replaced by transmute_ref!, at least in contexts where T and Self are concrete types.

Take a step towards removing the `unsafe` in `ChunksFixed`'s implementation.
This is the last step in the removal of `ChunksFixed`, which contains
one line of `unsafe` code.
@briansmith briansmith merged commit 6920c4f into main Oct 31, 2023
137 of 138 checks passed
@briansmith briansmith deleted the b/chunksfixed branch October 31, 2023 18:15
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