Skip to content

Commit

Permalink
Fix clippy warnings (bytecodealliance#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjhmelody authored and sstangl committed Oct 24, 2019
1 parent 2b6ea31 commit 1176e4f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cranelift/codegen/meta/src/cdsl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ impl Apply {
pred
}

pub fn rust_builder(&self, defined_vars: &Vec<VarIndex>, var_pool: &VarPool) -> String {
pub fn rust_builder(&self, defined_vars: &[VarIndex], var_pool: &VarPool) -> String {
let mut args = self
.args
.iter()
Expand Down
59 changes: 25 additions & 34 deletions cranelift/src/bugpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,7 @@ impl Mutator for ReplaceInstWithConst {

// Copy result SSA names into our own vector; otherwise we couldn't mutably borrow pos
// in the loop below.
let results = pos
.func
.dfg
.inst_results(prev_inst)
.iter()
.cloned()
.collect::<Vec<_>>();
let results = pos.func.dfg.inst_results(prev_inst).to_vec();

// Detach results from the previous instruction, since we're going to reuse them.
pos.func.dfg.clear_results(prev_inst);
Expand Down Expand Up @@ -390,15 +384,12 @@ impl Mutator for RemoveUnusedEntities {
let mut signatures_usage_map = HashMap::new();
for ebb in func.layout.ebbs() {
for inst in func.layout.ebb_insts(ebb) {
match func.dfg[inst] {
// Add new cases when there are new instruction formats taking a `SigRef`.
InstructionData::CallIndirect { sig_ref, .. } => {
signatures_usage_map
.entry(sig_ref)
.or_insert_with(Vec::new)
.push(SigRefUser::Instruction(inst));
}
_ => {}
// Add new cases when there are new instruction formats taking a `SigRef`.
if let InstructionData::CallIndirect { sig_ref, .. } = func.dfg[inst] {
signatures_usage_map
.entry(sig_ref)
.or_insert_with(Vec::new)
.push(SigRefUser::Instruction(inst));
}
}
}
Expand Down Expand Up @@ -500,15 +491,14 @@ impl Mutator for RemoveUnusedEntities {
let mut global_value_usage_map = HashMap::new();
for ebb in func.layout.ebbs() {
for inst in func.layout.ebb_insts(ebb) {
match func.dfg[inst] {
// Add new cases when there are new instruction formats taking a `GlobalValue`.
InstructionData::UnaryGlobalValue { global_value, .. } => {
global_value_usage_map
.entry(global_value)
.or_insert_with(Vec::new)
.push(inst);
}
_ => {}
// Add new cases when there are new instruction formats taking a `GlobalValue`.
if let InstructionData::UnaryGlobalValue { global_value, .. } =
func.dfg[inst]
{
global_value_usage_map
.entry(global_value)
.or_insert_with(Vec::new)
.push(inst);
}
}
}
Expand All @@ -519,8 +509,9 @@ impl Mutator for RemoveUnusedEntities {
// These can create cyclic references, which cause complications. Just skip
// the global value removal for now.
// FIXME Handle them in a better way.
GlobalValueData::Load { base: _, .. }
| GlobalValueData::IAddImm { base: _, .. } => return None,
GlobalValueData::Load { .. } | GlobalValueData::IAddImm { .. } => {
return None
}
}
}

Expand Down Expand Up @@ -647,11 +638,11 @@ impl Mutator for MergeBlocks {
// we'll start back to this EBB.
self.prev_ebb = Some(pred.ebb);

return Some((
Some((
func,
format!("merged {} and {}", pred.ebb, ebb),
ProgressStatus::ExpandedOrShrinked,
));
))
}

fn did_crash(&mut self) {
Expand Down Expand Up @@ -701,9 +692,9 @@ fn reduce(

match context.check_for_crash(&func) {
CheckResult::Succeed => {
return Err(format!(
"Given function compiled successfully or gave a verifier error."
));
return Err(
"Given function compiled successfully or gave a verifier error.".to_string(),
);
}
CheckResult::Crash(_) => {}
}
Expand Down Expand Up @@ -926,8 +917,8 @@ mod tests {

#[test]
fn test_reduce() {
const TEST: &'static str = include_str!("../tests/bugpoint_test.clif");
const EXPECTED: &'static str = include_str!("../tests/bugpoint_test_expected.clif");
const TEST: &str = include_str!("../tests/bugpoint_test.clif");
const EXPECTED: &str = include_str!("../tests/bugpoint_test_expected.clif");

let test_file = parse_test(TEST, ParseOptions::default()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion cranelift/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::CommandResult;
use cranelift_reader::parse_functions;

pub fn run(files: &[String]) -> CommandResult {
for (i, f) in files.into_iter().enumerate() {
for (i, f) in files.iter().enumerate() {
if i != 0 {
println!();
}
Expand Down
21 changes: 8 additions & 13 deletions cranelift/src/disasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ impl binemit::RelocSink for PrintRelocs {
offset: binemit::CodeOffset,
) {
if self.flag_print {
write!(
&mut self.text,
"reloc_ebb: {} {} at {}\n",
r, offset, where_
)
.unwrap();
writeln!(&mut self.text, "reloc_ebb: {} {} at {}", r, offset, where_).unwrap();
}
}

Expand All @@ -42,9 +37,9 @@ impl binemit::RelocSink for PrintRelocs {
addend: binemit::Addend,
) {
if self.flag_print {
write!(
writeln!(
&mut self.text,
"reloc_external: {} {} {} at {}\n",
"reloc_external: {} {} {} at {}",
r, name, addend, where_
)
.unwrap();
Expand All @@ -53,7 +48,7 @@ impl binemit::RelocSink for PrintRelocs {

fn reloc_jt(&mut self, where_: binemit::CodeOffset, r: binemit::Reloc, jt: ir::JumpTable) {
if self.flag_print {
write!(&mut self.text, "reloc_jt: {} {} at {}\n", r, jt, where_).unwrap();
writeln!(&mut self.text, "reloc_jt: {} {} at {}", r, jt, where_).unwrap();
}
}

Expand All @@ -64,9 +59,9 @@ impl binemit::RelocSink for PrintRelocs {
constant: ir::ConstantOffset,
) {
if self.flag_print {
write!(
writeln!(
&mut self.text,
"reloc_constant: {} {} at {}\n",
"reloc_constant: {} {} at {}",
reloc, constant, code_offset
)
.unwrap();
Expand All @@ -91,7 +86,7 @@ impl PrintTraps {
impl binemit::TrapSink for PrintTraps {
fn trap(&mut self, offset: binemit::CodeOffset, _srcloc: ir::SourceLoc, code: ir::TrapCode) {
if self.flag_print {
write!(&mut self.text, "trap: {} at {}\n", code, offset).unwrap();
writeln!(&mut self.text, "trap: {} at {}", code, offset).unwrap();
}
}
}
Expand All @@ -113,7 +108,7 @@ impl PrintStackmaps {
impl binemit::StackmapSink for PrintStackmaps {
fn add_stackmap(&mut self, offset: binemit::CodeOffset, _: binemit::Stackmap) {
if self.flag_print {
write!(&mut self.text, "add_stackmap at {}\n", offset).unwrap();
writeln!(&mut self.text, "add_stackmap at {}", offset).unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cranelift/src/print_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cranelift_codegen::cfg_printer::CFGPrinter;
use cranelift_reader::parse_functions;

pub fn run(files: &[String]) -> CommandResult {
for (i, f) in files.into_iter().enumerate() {
for (i, f) in files.iter().enumerate() {
if i != 0 {
println!();
}
Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn iterate_files(files: Vec<String>) -> impl Iterator<Item = PathBuf> {
.filter(|f| match f {
Ok(d) => {
// filter out hidden files (starting with .)
!d.file_name().to_str().map_or(false, |s| s.starts_with("."))
!d.file_name().to_str().map_or(false, |s| s.starts_with('.'))
// filter out directories
&& !d.file_type().is_dir()
}
Expand Down Expand Up @@ -96,7 +96,7 @@ fn create_target_isa(isa_spec: &IsaSpec) -> Result<Box<dyn TargetIsa>, String> {
let builder = host_isa_builder()?;
Ok(builder.finish(flags.clone()))
} else {
Err(String::from("A target ISA was specified in the file but should not have been--only the host ISA can be used for running CLIF files"))?
Err(String::from("A target ISA was specified in the file but should not have been--only the host ISA can be used for running CLIF files"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl OwnedFlagsOrIsa {
/// Produce a FlagsOrIsa reference.
pub fn as_fisa(&self) -> FlagsOrIsa {
match *self {
OwnedFlagsOrIsa::Flags(ref flags) => FlagsOrIsa::from(flags),
OwnedFlagsOrIsa::Isa(ref isa) => FlagsOrIsa::from(&**isa),
Self::Flags(ref flags) => FlagsOrIsa::from(flags),
Self::Isa(ref isa) => FlagsOrIsa::from(&**isa),
}
}
}
Expand Down

0 comments on commit 1176e4f

Please sign in to comment.