Skip to content

Commit e9e3179

Browse files
committed
chore: fix clippy
1 parent 3c243ec commit e9e3179

12 files changed

Lines changed: 71 additions & 86 deletions

File tree

src/constant_offsets.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ pub fn run(func: &mut FunctionBody, cfg: &CFGInfo) {
250250

251251
for (_, param) in &block_def.params {
252252
// Insert the common-base computations where needed.
253-
if let Some(common_base_const) = offset_base_const.get(&param) {
253+
if let Some(common_base_const) = offset_base_const.get(param) {
254254
new_insts.push(*common_base_const);
255-
new_insts.push(*offset_base.get(&param).unwrap());
255+
new_insts.push(*offset_base.get(param).unwrap());
256256
}
257257
}
258258

@@ -271,8 +271,8 @@ pub fn run(func: &mut FunctionBody, cfg: &CFGInfo) {
271271
// Update the offset embedded in the Operator
272272
// and use the `base` value instead as the
273273
// address arg.
274-
let mut op = op.clone();
275-
let mut args = args.iter().cloned().collect::<Vec<_>>();
274+
let mut op = *op;
275+
let mut args = args.to_vec();
276276
let common_base = *offset_base.get(&base).unwrap();
277277
let offset = *min_offset_from.get(&base).unwrap();
278278
assert!(offset <= 0);

src/dce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn op_can_be_removed(op: &Operator) -> bool {
2020
// If the *only* side-effect is a possible trap, we can remove
2121
// the op if otherwise unused, because we're assuming the
2222
// program doesn't trap.
23-
op if op.effects() == &[SideEffect::Trap] => true,
23+
op if op.effects() == [SideEffect::Trap] => true,
2424
// `table.size` and `memory.size` technically access state
2525
// tracked via side-effects, but can otherwise be removed if
2626
// unused. Likewise for table element and global accesses.

src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn shadow_stack_escapes(func: &FunctionBody, cfg: &CFGInfo) -> EscapeAnalysisRes
7070
return EscapeAnalysisResult::Escapes;
7171
}
7272
}
73-
&Terminator::Return { ref values } => {
73+
Terminator::Return { values } => {
7474
if values.iter().any(|v| tainted.contains(v)) {
7575
log::trace!("taint on return value causes escape");
7676
return EscapeAnalysisResult::Escapes;
@@ -110,7 +110,7 @@ fn shadow_stack_escapes(func: &FunctionBody, cfg: &CFGInfo) -> EscapeAnalysisRes
110110
}
111111

112112
pub(crate) fn remove_shadow_stack_if_non_escaping(func: &mut FunctionBody, cfg: &CFGInfo) {
113-
if let EscapeAnalysisResult::NonEscaping(values_to_remove) = shadow_stack_escapes(func, &cfg) {
113+
if let EscapeAnalysisResult::NonEscaping(values_to_remove) = shadow_stack_escapes(func, cfg) {
114114
log::trace!("removing shadow stack operations: {:?}", values_to_remove);
115115
let ty_u32 = func.type_pool.single(Type::I32);
116116
let const_zero = func.values.push(ValueDef::Operator(

src/eval.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ pub(crate) fn partially_evaluate<'a>(
122122
// Expand function bodies of any function named in a directive.
123123
let mut funcs = HashMap::default();
124124
for directive in &directives {
125-
if !funcs.contains_key(&directive.func) {
125+
if let std::collections::hash_map::Entry::Vacant(e) = funcs.entry(directive.func) {
126126
let mut f = module.clone_and_expand_body(directive.func)?;
127127

128128
if let Some(path) = &output_ir {
129129
let mut generic_ir_file = path.clone();
130-
generic_ir_file.push(&format!("generic_{}.txt", directive.func));
130+
generic_ir_file.push(format!("generic_{}.txt", directive.func));
131131
std::fs::write(
132132
&generic_ir_file,
133133
format!("{}", f.display_verbose("", Some(&module))),
@@ -150,7 +150,7 @@ pub(crate) fn partially_evaluate<'a>(
150150

151151
f.convert_to_max_ssa(Some(cut_blocks));
152152

153-
funcs.insert(directive.func, (f, cfg, stats));
153+
e.insert((f, cfg, stats));
154154
}
155155
}
156156

@@ -196,7 +196,7 @@ pub(crate) fn partially_evaluate<'a>(
196196
live.sort();
197197
writeln!(&mut s, "# {}: {:?}", block, live).unwrap();
198198
}
199-
writeln!(&mut s, "").unwrap();
199+
writeln!(&mut s).unwrap();
200200
writeln!(&mut s, "{}", body.display_verbose("", Some(&module))).unwrap();
201201
s
202202
} else {
@@ -259,7 +259,7 @@ pub(crate) fn partially_evaluate<'a>(
259259

260260
if let Some(path) = &output_ir {
261261
let mut specialized_ir_file = path.clone();
262-
specialized_ir_file.push(&format!("specialized_{}_to_{}.txt", directive.func, func));
262+
specialized_ir_file.push(format!("specialized_{}_to_{}.txt", directive.func, func));
263263
std::fs::write(&specialized_ir_file, ir).unwrap();
264264
}
265265

@@ -483,10 +483,8 @@ fn find_cut_blocks(
483483
let changed = new != current;
484484
highest_same_ctx_ancestor[succ] = new;
485485
log::trace!("highest same-context ancestor for {}: {}", succ, new);
486-
if changed {
487-
if queue_set.insert(succ) {
488-
queue.push(succ);
489-
}
486+
if changed && queue_set.insert(succ) {
487+
queue.push(succ);
490488
}
491489
});
492490
}
@@ -569,10 +567,7 @@ enum EvalResult {
569567
}
570568
impl EvalResult {
571569
fn is_handled(&self) -> bool {
572-
match self {
573-
&EvalResult::Unhandled => false,
574-
_ => true,
575-
}
570+
!matches!(self, &EvalResult::Unhandled)
576571
}
577572
}
578573

@@ -1106,7 +1101,7 @@ impl<'a> Evaluator<'a> {
11061101
ref if_true,
11071102
ref if_false,
11081103
} => {
1109-
assert!(!state.pending_specialize.is_some());
1104+
assert!(state.pending_specialize.is_none());
11101105
let (cond, abs_cond) = self.use_value(state.context, orig_block, new_block, cond);
11111106
// Update pending context with new stack if necessary.
11121107
match abs_cond.as_const_truthy() {
@@ -1147,7 +1142,7 @@ impl<'a> Evaluator<'a> {
11471142
},
11481143
}
11491144
}
1150-
&Terminator::Br { ref target } => {
1145+
Terminator::Br { target } => {
11511146
if let Some((index, lo, hi)) = state.pending_specialize.take() {
11521147
log::trace!(
11531148
"Branch to target {} with PendingSpecialize on {}",
@@ -1192,7 +1187,7 @@ impl<'a> Evaluator<'a> {
11921187
ref targets,
11931188
ref default,
11941189
} => {
1195-
assert!(!state.pending_specialize.is_some());
1190+
assert!(state.pending_specialize.is_none());
11961191
let (value, abs_value) =
11971192
self.use_value(state.context, orig_block, new_block, value);
11981193
if let Some(selector) = abs_value.as_const_u32() {
@@ -1238,7 +1233,7 @@ impl<'a> Evaluator<'a> {
12381233
}
12391234
}
12401235
}
1241-
&Terminator::Return { ref values } => {
1236+
Terminator::Return { values } => {
12421237
let values = values
12431238
.iter()
12441239
.map(|&value| {
@@ -1255,6 +1250,7 @@ impl<'a> Evaluator<'a> {
12551250
self.func.blocks[new_block].terminator = new_term;
12561251
}
12571252

1253+
#[allow(clippy::too_many_arguments)]
12581254
fn abstract_eval(
12591255
&mut self,
12601256
orig_block: Block,
@@ -1319,6 +1315,7 @@ impl<'a> Evaluator<'a> {
13191315
Ok(EvalResult::Normal(ret))
13201316
}
13211317

1318+
#[allow(clippy::too_many_arguments)]
13221319
fn abstract_eval_intrinsic(
13231320
&mut self,
13241321
orig_block: Block,
@@ -1470,7 +1467,7 @@ impl<'a> Evaluator<'a> {
14701467
} else if Some(function_index) == self.intrinsics.pop_stack {
14711468
log::trace!("pop_stack: current stack is {:?}", state.flow.stack);
14721469
self.stats.virtstack_reads += 1;
1473-
if state.flow.stack.len() > 0 {
1470+
if !state.flow.stack.is_empty() {
14741471
let (_, reg) = state.flow.stack.remove(0);
14751472
let (value, abs) = match reg {
14761473
RegValue::Value { data, abs, .. } => (data, abs),
@@ -1664,6 +1661,7 @@ impl<'a> Evaluator<'a> {
16641661
}
16651662
}
16661663

1664+
#[allow(clippy::too_many_arguments)]
16671665
fn abstract_eval_regs(
16681666
&mut self,
16691667
_inst: Value,
@@ -2286,7 +2284,7 @@ impl<'a> Evaluator<'a> {
22862284
//
22872285
// Also look at `locals` and find locals present in pred and
22882286
// not in some succ, and sync them.
2289-
for (_, &block) in &self.block_map {
2287+
for &block in self.block_map.values() {
22902288
if self.func.blocks[block].succs.is_empty() {
22912289
continue;
22922290
}

src/filter.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn gen_replacement_bytecode(
7575
_ => {
7676
anyhow::ensure!(results.len() <= 1);
7777
anyhow::ensure!(results.len() <= args.len());
78-
if args.len() > 0 && results.len() > 0 {
78+
if !args.is_empty() && !results.is_empty() {
7979
anyhow::ensure!(
8080
args[0] == results[0],
8181
"Intrinsic's first arg is different type than result"
@@ -127,12 +127,9 @@ impl Rewrite {
127127
// Scan globals section once to count globals so that we know
128128
// the indices of the new globals that we add.
129129
for payload in parser.clone().parse_all(module) {
130-
match payload? {
131-
Payload::GlobalSection(globals) => {
132-
weval_globals += globals.count();
133-
break;
134-
}
135-
_ => {}
130+
if let Payload::GlobalSection(globals) = payload? {
131+
weval_globals += globals.count();
132+
break;
136133
}
137134
}
138135

@@ -471,18 +468,15 @@ impl Rewrite {
471468
let mut func_names = wasm_encoder::NameMap::new();
472469
for subsection in name_reader {
473470
let subsection = subsection?;
474-
match subsection {
475-
wasmparser::Name::Function(names) => {
476-
for name in names {
477-
let name = name?;
478-
if let Some(&FuncRemap::Index(new_index)) =
479-
self.func_remap.get(&name.index)
480-
{
481-
func_names.append(new_index, name.name);
482-
}
471+
if let wasmparser::Name::Function(names) = subsection {
472+
for name in names {
473+
let name = name?;
474+
if let Some(&FuncRemap::Index(new_index)) =
475+
self.func_remap.get(&name.index)
476+
{
477+
func_names.append(new_index, name.name);
483478
}
484479
}
485-
_ => {}
486480
}
487481
}
488482
names.functions(&func_names);

src/image.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ impl Image {
199199
let table = self
200200
.main_table
201201
.ok_or_else(|| anyhow::anyhow!("no main table"))?;
202-
Ok(self
203-
.tables
202+
self.tables
204203
.get(&table)
205204
.unwrap()
206205
.get(idx as usize)
207206
.copied()
208-
.ok_or_else(|| anyhow::anyhow!("func ptr out of bounds"))?)
207+
.ok_or_else(|| anyhow::anyhow!("func ptr out of bounds"))
209208
}
210209

211210
pub(crate) fn append_data(&mut self, id: Memory, data: Vec<u8>) {
@@ -216,7 +215,7 @@ impl Image {
216215
let padding = padded_len - data_len;
217216
image
218217
.image
219-
.extend(data.into_iter().chain(std::iter::repeat(0).take(padding)));
218+
.extend(data.into_iter().chain(std::iter::repeat_n(0, padding)));
220219
log::debug!(
221220
"Appending data ({} bytes, {} padding): went from {} bytes to {} bytes",
222221
data_len,

src/intrinsics.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,16 @@ pub(crate) fn find_global_data_by_exported_func(module: &Module, name: &str) ->
152152
// I32Add of a global (the GOT memory base) and an I32Const.
153153

154154
let extract_const_value = |value| match &body.values[value] {
155-
ValueDef::Operator(Operator::I32Const { value }, _, _) => Some(*value as u32),
155+
ValueDef::Operator(Operator::I32Const { value }, _, _) => Some(*value),
156156
ValueDef::Operator(Operator::I32Add, args, _) => {
157157
let args = &body.arg_pool[*args];
158158
match (&body.values[args[0]], &body.values[args[1]]) {
159159
(
160160
ValueDef::Operator(Operator::GlobalGet { global_index }, _, _),
161161
ValueDef::Operator(Operator::I32Const { value }, _, _),
162-
) => match module.globals[*global_index].value {
163-
Some(global_value) => Some((global_value as u32) + *value),
164-
_ => None,
165-
},
162+
) => module.globals[*global_index]
163+
.value
164+
.map(|global_value| (global_value as u32) + *value),
166165
_ => None,
167166
}
168167
}

src/liveness.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ impl<'a> Liveness<'a> {
9898
changed = true;
9999
}
100100
}
101-
if changed {
102-
if workqueue_set.insert(pred) {
103-
workqueue.push_back(pred);
104-
}
101+
if changed && workqueue_set.insert(pred) {
102+
workqueue.push_back(pred);
105103
}
106104
}
107105
}

src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod state;
2020
mod stats;
2121
mod value;
2222

23-
const STUBS: &'static str = include_str!("../lib/weval-stubs.wat");
23+
const STUBS: &str = include_str!("../lib/weval-stubs.wat");
2424

2525
#[derive(Clone, Debug, StructOpt)]
2626
pub enum Command {
@@ -151,6 +151,7 @@ async fn wizen_impl(
151151
}
152152

153153
/// Weval a wasm.
154+
#[allow(clippy::too_many_arguments)]
154155
pub fn weval(
155156
input_module: PathBuf,
156157
output_module: PathBuf,
@@ -173,11 +174,7 @@ pub fn weval(
173174
let input_hash = cache::compute_hash(&raw_bytes[..]);
174175

175176
// Open the cache and read-only cache, if any.
176-
let cache = cache::Cache::open(
177-
cache.as_ref().map(|p| p.as_path()),
178-
cache_ro.as_ref().map(|p| p.as_path()),
179-
input_hash,
180-
)?;
177+
let cache = cache::Cache::open(cache.as_deref(), cache_ro.as_deref(), input_hash)?;
181178

182179
// Optionally, Wizen the module first.
183180
let module_bytes = if do_wizen {
@@ -193,8 +190,7 @@ pub fn weval(
193190
if verbose {
194191
eprintln!("Parsing the module...");
195192
}
196-
let mut frontend_opts = waffle::FrontendOptions::default();
197-
frontend_opts.debug = true;
193+
let frontend_opts = waffle::FrontendOptions { debug: true };
198194
let module = waffle::Module::from_wasm_bytes(&module_bytes[..], &frontend_opts)?;
199195

200196
// Build module image.

src/state.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::value::{AbstractValue, WasmVal};
3939
use fxhash::FxHashMap as HashMap;
4040
use std::collections::hash_map::Entry;
4141
use std::collections::{BTreeMap, BTreeSet};
42-
use waffle::entity::{EntityRef, EntityVec, PerEntity};
42+
use waffle::entity::{EntityVec, PerEntity};
4343
use waffle::{Block, FunctionBody, Global, Type, Value};
4444

4545
waffle::declare_entity!(Context, "context");
@@ -64,7 +64,7 @@ pub(crate) struct Contexts {
6464

6565
impl Contexts {
6666
pub(crate) fn create(&mut self, parent: Option<Context>, elem: ContextElem) -> Context {
67-
let parent = parent.unwrap_or(Context::invalid());
67+
let parent = parent.unwrap_or_default();
6868
match self.dedup.entry((parent, elem.clone())) {
6969
Entry::Occupied(o) => *o.get(),
7070
Entry::Vacant(v) => {
@@ -242,7 +242,7 @@ fn map_meet_with<
242242
*val = bot.clone();
243243
changed |= old != *val;
244244
} else {
245-
to_remove.push(k.clone());
245+
to_remove.push(*k);
246246
changed = true;
247247
}
248248
}
@@ -421,8 +421,8 @@ impl FunctionState {
421421
}
422422

423423
// Set specialization globals, if any.
424-
for i in 0..num_globals {
425-
self.specialization_globals.push(args[i].clone());
424+
for arg in args.iter().take(num_globals) {
425+
self.specialization_globals.push(arg.clone());
426426
}
427427
}
428428
}

0 commit comments

Comments
 (0)