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

chore: update rust to 1.76.0 and fix new clippy lints #1522

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

Stebalien
Copy link
Member

Some of the lints were... kind of 🙄, but it's easier to appease the animated paperclip than to argue with it.

Some of the lints were... kind of 🙄, but it's easier to appease the
animated paperclip than to argue with it.
@@ -164,7 +164,7 @@ fn verification_and_weights_for_verified_and_unverified_deals() {
data: verified_deal_1.piece_cid,
size: verified_deal_1.piece_size,
},
s_response.activated.get(0).unwrap()
Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy does not like get(0).

Copy link
Member

Choose a reason for hiding this comment

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

.first() or .front() is

easier to read and has the same result

but, that's just like your opinion, man

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 generally agree. I switched it to indexing ([0]) where it made sense.

@@ -173,7 +173,7 @@ fn verification_and_weights_for_verified_and_unverified_deals() {
data: verified_deal_2.piece_cid,
size: verified_deal_2.piece_size,
},
s_response.activated.get(1).unwrap()
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 fixed the others because this is simpler anyways.

@@ -4982,11 +4982,11 @@ fn notify_pledge_changed(rt: &impl Runtime, pledge_delta: &TokenAmount) -> Resul

fn get_claims(
rt: &impl Runtime,
ids: &Vec<ext::verifreg::ClaimID>,
ids: &[ext::verifreg::ClaimID],
Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy does not like &Vec<u8>.

@@ -628,7 +628,7 @@ fn extend_expiration2_drop_claims() {
let extension = 42 * rt.policy().wpost_proving_period;
let new_expiration = old_sector.expiration + extension;

let claim_ids = vec![400, 500];
let claim_ids = [400, 500];
Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy does not like "useless vecs".

Comment on lines -156 to -159
match self.hamt.for_each(|k, v| {
let key = K::from_bytes(k).context_code(ExitCode::USR_ILLEGAL_STATE, "invalid key")?;
f(key, v).map_err(|e| anyhow!(e))
}) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy was unhappy about all the code in the match part of the match statement, so I just got rid of the match entirely.

Copy link
Member

Choose a reason for hiding this comment

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

this is probably a good call though, I find this kind of complex conditional construct puts unnecessary pressure on my mental stack

.collect()
invocs.iter().enumerate().fold(String::new(), |mut s, (i, invoc)| {
use std::fmt::Write;
let _ = writeln!(s, "{}: [{}:{}],", i, invoc.to, invoc.method);
Copy link
Member Author

Choose a reason for hiding this comment

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

clippy did not like creating lots of small strings, this new version will build a single string.

Copy link
Member

Choose a reason for hiding this comment

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

When Clippy is making you replace a map+collect with a fold and macros, I think it has gone rather out of its swim lane!

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I mean, it's replacing one macro with another. It's point is valid: calling format! repeatedly will allocate a lot of strings while repeatedly calling write! on the same string won't.

In this case, it doesn't matter. But this could definitely have a performance impact if this were performance critical code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but it's a linter, not a performance coach. It's supposed (IMO) to make the code more readable, not faster.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's supposed to teach you when there may be a "better" way to do things. I do wish there were a more elegant way to write this particular code, but the suggestion is valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Think of it this way: rust is big and complicated, you likely wouldn't learn half the language or about half the new features without something looking over your shoulder and telling you when there's a better way to do something.

Copy link
Member

Choose a reason for hiding this comment

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

I do wish there were a more elegant way to write this particular code

there is, if you resist the functional siren song

use std::fmt::Write;
let mut s = String::new();
for (i, invoc) in invocs.iter().enumerate() {
    let _ = write!(&mut s, "{}: [{}:{}],\n", i, invoc.to, invoc.method);
}
s

simple, clear, maintainable

Copy link
Member Author

Choose a reason for hiding this comment

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

🧜‍♀️

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

👍 simple enough

what are the implications of bumping to 1.76 for the bundled versions? I'm guessing we need to make sure this is held off from v13?

.collect()
invocs.iter().enumerate().fold(String::new(), |mut s, (i, invoc)| {
use std::fmt::Write;
let _ = writeln!(s, "{}: [{}:{}],", i, invoc.to, invoc.method);
Copy link
Member

Choose a reason for hiding this comment

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

When Clippy is making you replace a map+collect with a fold and macros, I think it has gone rather out of its swim lane!

@Stebalien
Copy link
Member Author

what are the implications of bumping to 1.76 for the bundled versions? I'm guessing we need to make sure this is held off from v13?

Basically:

  • I needed to bump the version above v73 in the ref-fvm for a new version of wasmtime.
  • I figured I might as well bump it to the latest version everywhere.
  • Now's a great time to test this and try to catch any regressions...

In terms of implications? Yeah, we shouldn't use this in v13. But that branch has been cut so it should be safe to merge this to master.

@Stebalien Stebalien added this pull request to the merge queue Feb 12, 2024
Merged via the queue into master with commit 6e78144 Feb 12, 2024
14 checks passed
@Stebalien Stebalien deleted the steb/update-rust branch February 12, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ☑️ Done (Archive)
Development

Successfully merging this pull request may close these issues.

3 participants