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

Preliminary Changes for Updating Cargo #32547

Merged
merged 5 commits into from
Jul 21, 2023

Conversation

apfitzge
Copy link
Contributor

@apfitzge apfitzge commented Jul 19, 2023

Problem

We've been sitting on an oldish version of Cargo that spits out a ton of warning on nightly. This is extremely frustrating as we need to look more carefully at our output warning to make sure they are not from changes we made, instead of just checking if there are warnings.

Summary of Changes

Wanted to begin tackling some of the clippy warnings and errors that have been introduced since our cargo freeze. This is a step towards upgrading, but does not include fixes necessary to upgrade.

  • ee65ea3 - don't need to call default() here to create PhantomData
  • 040b0f7 - new lint incorrect_clone_impl_on_copy_type doesn't like if Clone != Copy for Copyable types. Ignore this lint on our CloneZeroed macro.
  • 1245cef - bitflags doesn't work as expected with Zero-flags. This is even a listed edge-case in the docs https://docs.rs/bitflags/latest/bitflags/#zero-flags. I replaced the single use of the NONE with empty().
  • b00cc2e - new lint useless_vec which detects usage of vec![...] where we could just use [...].

Fixes #

@apfitzge apfitzge force-pushed the 2023-07-19/cargo_upgrade_prelim branch from c3fc19b to b00cc2e Compare July 20, 2023 17:49
@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Merging #32547 (9b08354) into master (3fbfac4) will decrease coverage by 0.1%.
The diff coverage is 100.0%.

@@            Coverage Diff            @@
##           master   #32547     +/-   ##
=========================================
- Coverage    82.0%    82.0%   -0.1%     
=========================================
  Files         780      780             
  Lines      210789   210782      -7     
=========================================
- Hits       172985   172910     -75     
- Misses      37804    37872     +68     

@apfitzge apfitzge marked this pull request as ready for review July 20, 2023 20:18
Copy link
Contributor

@brooksprumo brooksprumo 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 tackling these! I had started on various rust 1.71.0 clippy fixes, but didn't get to all of them.

We may end up having to wait until rust 1.72.0 to resolve the cargo fmt issue w.r.t. let-else, but maybe we can at least bump nightly a bit more.

@@ -426,6 +426,7 @@ pub fn derive_clone_zeroed(input: proc_macro::TokenStream) -> proc_macro::TokenS
let name = &item_struct.ident;
quote! {
impl Clone for #name {
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment indicating (1) why this is needed, and (2) when it can be removed/re-evaluated?

I think it'll be helpful to have that information here in the code, in case it becomes hard to find this PR later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this lint: https://rust-lang.github.io/rust-clippy/master/index.html#/incorrect_clone_impl_on_copy_type

If both Clone and Copy are implemented, they must agree. This is done by dereferencing self in Clone’s implementation. Anything else is incorrect.

In this case, we are "manually" implementing Clone to make sure all padding bytes are zeroed out.
Based on that description I don't think we'll ever be able to remove the allow, since it's a correct flagging of this scenario.
IIRC rust makes no guarantees for Copy in terms of padding bytes bein zero (probably not since it's just a memcpy?) - would defer to @Lichtso since he's the one who added the macro.

In anycase I will add a comment on why this allow is there/necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We want a custom copy operation. Probably should derive both copy and clone, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not possible to derive a custom Copy in rust as far as I am aware - it's a special trait that effectively allows types to be memcpy'd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-thinking about this, I'm not sure we even want these types to be Copy. It's probably safer to only support Clone w/ our zeroed padding stuff.
Otherwise it doesn't really protect us from sending something over the network w/ non-zero padding because we could have just copied our value instead of cloning?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can try unimplementing Copy for these types, but that might result in a lot of .clone() where implicit deref happened before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I think that sounds reasonable. I'm going to add this clippy-lint allow for now, and just self-assign an issue for experimenting with removing Copy.
Without removing Copy this allow is necessary to make clippy happy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

Lgtm. The #[allow(clippy::incorrect_clone_impl_on_copy_type)] is the one interesting change, but isn't a change of behavior from what we already have. Should we want/need to change this later, we always can.

With that, I'm fine to merge the PR. If you'd like to wait for @Lichtso, that's also fine by me.

@apfitzge apfitzge merged commit a7eda70 into solana-labs:master Jul 21, 2023
13 checks passed
@apfitzge apfitzge deleted the 2023-07-19/cargo_upgrade_prelim branch July 21, 2023 20:43
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