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

Fix many clippy warnings across Kani #1287

Merged
merged 3 commits into from
Jun 17, 2022
Merged

Conversation

tedinski
Copy link
Contributor

Description of changes:

  1. Apply many of clippy's suggested fixes to code where (1) the fix was actually better (2) it was simple.
  2. For some I thought were "wrong" I added a couple #![allow(... directives.
  3. For others, I just left them for now, I think some should be done but require more thinking than I wanted for this PR.

Resolved issues:

Call-outs:

Testing:

  • How is this change tested? existing regression

  • Is this a refactor change? yep

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@tedinski tedinski requested a review from a team as a code owner June 16, 2022 22:27
@@ -510,7 +514,7 @@ impl Expr {

/// `union {double d; uint64_t bp} u = {.bp = 0x1234}; >>> u.d <<<`
pub fn double_constant_from_bitpattern(bp: u64) -> Self {
let c = unsafe { std::mem::transmute(bp) };
let c = f64::from_bits(bp);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice to get rid of an unsafe transmute here

@@ -1446,12 +1450,12 @@ impl Expr {
}
}
None => {
for i in 0..fields.len() {
if fields[i].is_padding() {
for field in fields {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an issue for this PR, but this whole function looks more complicated that it needs to be.

@@ -138,7 +138,7 @@ impl Location {
file.into(),
function.intern(),
line,
col.map(|x| x.try_into().unwrap()),
col,
Copy link
Contributor

Choose a reason for hiding this comment

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

lol

let (prefix, name) = if orig_name.starts_with("tag-") {
(&orig_name[..4], &orig_name[4..])
let (prefix, name) = if let Some(tag) = orig_name.strip_prefix("tag-") {
("tag-", tag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Impressed clippy found this pattern

@@ -113,7 +113,7 @@ fn try_parse_args(cur_args: Vec<String>, name: &str, line: &str) -> Vec<String>
let name = format!("{}-flags:", name);
let mut split = line.split(&name).skip(1);
let args: Vec<String> = if let Some(rest) = split.next() {
rest.trim().split_whitespace().map(String::from).collect()
rest.split_whitespace().map(String::from).collect()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change the semantics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! That's apparently why clippy has this lint. :)

} else {
None
}
args.unwind.or(harness_metadata.unwind_value).or(args.default_unwind)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is easier to read :)

@@ -206,7 +206,7 @@ impl ToIrep for ExprValue {
}
//TODO, determine if there is an endineness problem here
ExprValue::DoubleConstant(i) => {
let c: u64 = unsafe { std::mem::transmute(*i) };
let c: u64 = i.to_bits();
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@@ -405,8 +405,7 @@ impl ToIrep for StmtBody {
StmtBody::Assume { cond } => code_irep(IrepId::Assume, vec![cond.to_irep(mm)]),
StmtBody::AtomicBlock(stmts) => {
let mut irep_stmts = vec![code_irep(IrepId::AtomicBegin, vec![])];
irep_stmts
.append(&mut stmts.into_iter().map(|x| x.to_irep(mm)).collect::<Vec<Irep>>());
irep_stmts.append(&mut stmts.iter().map(|x| x.to_irep(mm)).collect());
Copy link
Contributor

Choose a reason for hiding this comment

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

Bye bye turbo🐠

@@ -46,7 +46,8 @@ impl From<RoundingMode> for BigInt {
}
}

/// Constructor
// TODO: This file should be refactored. This is a bit "OO" style when it doesn't have to be.
Copy link
Contributor

Choose a reason for hiding this comment

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

tracking issue

@tedinski tedinski mentioned this pull request Jun 17, 2022
@tedinski tedinski merged commit 12660b8 into model-checking:main Jun 17, 2022
@tedinski tedinski deleted the rampage branch June 17, 2022 18:38
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