Use clippy (#276)
* cton-util: fix some clippy unnecessary pass-by-value warnings * clippy: ignore too many arguments / cyclomatic complexity in module since these functions are taking args coming from the command line, i dont think this is actually a valid lint, morally the arguments are all from one structure * cton-util: take care of remaining clippy warnings * cton-reader: fix all non-suspicious clippy warnings * cton-reader: disable clippy at site of suspicious lint * cton-frontend: disable clippy at the site of an invalid lint * cton-frontend: fix clippy warnings, or ignore benign ones * clippy: ignore the camelcase word WebAssembly in docs * cton-wasm: fix clippy complaints or ignore benign ones * cton-wasm tests: fix clippy complaints * cretonne: starting point turns off all clippy warnings * cretonne: clippy fixes, or lower allow() to source of problem * cretonne: more clippy fixes * cretonne: fix or disable needless_lifetimes lint this linter is buggy when the declared lifetime is used for another type constraint. * cretonne: fix clippy complaint about Pass::NoPass * rustfmt * fix prev minor api changes clippy suggested * add clippy to test-all * cton-filetests: clippy fixes * simplify clippy reporting in test-all * cretonne: document clippy allows better * cretonne: fix some more clippy lints * cretonne: fix clippy lints (mostly doc comments) * cretonne: allow all needless_lifetimes clippy warnings remove overrides at the false positives * rustfmt
This commit is contained in:
@@ -36,6 +36,8 @@ use environ::{FuncEnvironment, GlobalValue};
|
||||
use std::{i32, u32};
|
||||
use std::vec::Vec;
|
||||
|
||||
// Clippy warns about "flags: _" but its important to document that the flags field is ignored
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(unneeded_field_pattern))]
|
||||
/// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted
|
||||
/// a return.
|
||||
pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
@@ -45,7 +47,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
environ: &mut FE,
|
||||
) {
|
||||
if !state.reachable {
|
||||
return translate_unreachable_operator(op, builder, state);
|
||||
return translate_unreachable_operator(&op, builder, state);
|
||||
}
|
||||
|
||||
// This big match treats all Wasm code operators.
|
||||
@@ -198,9 +200,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
builder.switch_to_block(frame.following_code());
|
||||
builder.seal_block(frame.following_code());
|
||||
// If it is a loop we also have to seal the body loop block
|
||||
match frame {
|
||||
ControlStackFrame::Loop { header, .. } => builder.seal_block(header),
|
||||
_ => {}
|
||||
if let ControlStackFrame::Loop { header, .. } = frame {
|
||||
builder.seal_block(header)
|
||||
}
|
||||
state.stack.truncate(frame.original_stack_size());
|
||||
state.stack.extend_from_slice(
|
||||
@@ -857,15 +858,17 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
}
|
||||
}
|
||||
|
||||
// Clippy warns us of some fields we are deliberately ignoring
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(unneeded_field_pattern))]
|
||||
/// Deals with a Wasm instruction located in an unreachable portion of the code. Most of them
|
||||
/// are dropped but special ones like `End` or `Else` signal the potential end of the unreachable
|
||||
/// portion so the translation state muts be updated accordingly.
|
||||
fn translate_unreachable_operator(
|
||||
op: Operator,
|
||||
op: &Operator,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
) {
|
||||
match op {
|
||||
match *op {
|
||||
Operator::If { ty: _ } => {
|
||||
// Push a placeholder control stack entry. The if isn't reachable,
|
||||
// so we don't have any branches anywhere.
|
||||
@@ -877,27 +880,25 @@ fn translate_unreachable_operator(
|
||||
}
|
||||
Operator::Else => {
|
||||
let i = state.control_stack.len() - 1;
|
||||
match state.control_stack[i] {
|
||||
ControlStackFrame::If {
|
||||
branch_inst,
|
||||
ref mut reachable_from_top,
|
||||
..
|
||||
} => {
|
||||
if *reachable_from_top {
|
||||
// We have a branch from the top of the if to the else.
|
||||
state.reachable = true;
|
||||
// And because there's an else, there can no longer be a
|
||||
// branch from the top directly to the end.
|
||||
*reachable_from_top = false;
|
||||
if let ControlStackFrame::If {
|
||||
branch_inst,
|
||||
ref mut reachable_from_top,
|
||||
..
|
||||
} = state.control_stack[i]
|
||||
{
|
||||
if *reachable_from_top {
|
||||
// We have a branch from the top of the if to the else.
|
||||
state.reachable = true;
|
||||
// And because there's an else, there can no longer be a
|
||||
// branch from the top directly to the end.
|
||||
*reachable_from_top = false;
|
||||
|
||||
// We change the target of the branch instruction
|
||||
let else_ebb = builder.create_ebb();
|
||||
builder.change_jump_destination(branch_inst, else_ebb);
|
||||
builder.seal_block(else_ebb);
|
||||
builder.switch_to_block(else_ebb);
|
||||
}
|
||||
// We change the target of the branch instruction
|
||||
let else_ebb = builder.create_ebb();
|
||||
builder.change_jump_destination(branch_inst, else_ebb);
|
||||
builder.seal_block(else_ebb);
|
||||
builder.switch_to_block(else_ebb);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Operator::End => {
|
||||
@@ -1057,10 +1058,10 @@ fn translate_br_if(
|
||||
builder.ins().brnz(val, br_destination, inputs);
|
||||
}
|
||||
|
||||
fn translate_br_if_args<'state>(
|
||||
fn translate_br_if_args(
|
||||
relative_depth: u32,
|
||||
state: &'state mut TranslationState,
|
||||
) -> (ir::Ebb, &'state [ir::Value]) {
|
||||
state: &mut TranslationState,
|
||||
) -> (ir::Ebb, &[ir::Value]) {
|
||||
let i = state.control_stack.len() - 1 - (relative_depth as usize);
|
||||
let (return_count, br_destination) = {
|
||||
let frame = &mut state.control_stack[i];
|
||||
|
||||
@@ -121,7 +121,7 @@ impl DummyEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
/// The FuncEnvironment implementation for use by the `DummyEnvironment`.
|
||||
/// The `FuncEnvironment` implementation for use by the `DummyEnvironment`.
|
||||
pub struct DummyFuncEnvironment<'dummy_environment> {
|
||||
pub mod_info: &'dummy_environment DummyModuleInfo,
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
#![deny(missing_docs,
|
||||
trivial_numeric_casts,
|
||||
unused_extern_crates)]
|
||||
#![cfg_attr(feature="clippy",
|
||||
plugin(clippy(conf_file="../../clippy.toml")))]
|
||||
#![cfg_attr(feature="cargo-clippy",
|
||||
allow(new_without_default, redundant_field_names))]
|
||||
|
||||
extern crate wasmparser;
|
||||
extern crate cton_frontend;
|
||||
|
||||
@@ -25,7 +25,7 @@ fn testsuite() {
|
||||
// Ignore files starting with `.`, which could be editor temporary files
|
||||
if let Some(stem) = p.path().file_stem() {
|
||||
if let Some(stemstr) = stem.to_str() {
|
||||
return !stemstr.starts_with(".");
|
||||
return !stemstr.starts_with('.');
|
||||
}
|
||||
}
|
||||
false
|
||||
@@ -35,7 +35,7 @@ fn testsuite() {
|
||||
let flags = Flags::new(&settings::builder());
|
||||
for path in paths {
|
||||
let path = path.path();
|
||||
handle_module(path, &flags);
|
||||
handle_module(&path, &flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ fn return_at_end() {
|
||||
let mut flag_builder = settings::builder();
|
||||
flag_builder.enable("return_at_end").unwrap();
|
||||
let flags = Flags::new(&flag_builder);
|
||||
handle_module(PathBuf::from("../../wasmtests/return_at_end.wat"), &flags);
|
||||
handle_module(&PathBuf::from("../../wasmtests/return_at_end.wat"), &flags);
|
||||
}
|
||||
|
||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
@@ -54,7 +54,7 @@ fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn handle_module(path: PathBuf, flags: &Flags) {
|
||||
fn handle_module(path: &PathBuf, flags: &Flags) {
|
||||
let data = match path.extension() {
|
||||
None => {
|
||||
panic!("the file extension is not wasm or wat");
|
||||
@@ -103,7 +103,7 @@ fn handle_module(path: PathBuf, flags: &Flags) {
|
||||
translate_module(&data, &mut dummy_environ).unwrap();
|
||||
for func in &dummy_environ.info.function_bodies {
|
||||
verifier::verify_function(func, flags)
|
||||
.map_err(|err| panic!(pretty_verifier_error(func, None, err)))
|
||||
.map_err(|err| panic!(pretty_verifier_error(func, None, &err)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user