mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
auto clippy fixes
This commit is contained in:
parent
72c85efc83
commit
ef39bad7c6
146 changed files with 750 additions and 1005 deletions
|
@ -105,7 +105,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
is_debug_mode: bool,
|
||||
) -> Result<Self, std::string::String> {
|
||||
let module =
|
||||
WasmModule::preload(arena, module_bytes, false).map_err(|e| format!("{:?}", e))?;
|
||||
WasmModule::preload(arena, module_bytes, false).map_err(|e| format!("{e:?}"))?;
|
||||
Self::for_module(arena, arena.alloc(module), import_dispatcher, is_debug_mode)
|
||||
}
|
||||
|
||||
|
@ -178,8 +178,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
let actual_type = ValueType::from(value);
|
||||
if actual_type != expected_type {
|
||||
return Err(format!(
|
||||
"Type mismatch on argument {} of {}. Expected {:?} but got {:?}",
|
||||
i, fn_name, expected_type, value
|
||||
"Type mismatch on argument {i} of {fn_name}. Expected {expected_type:?} but got {value:?}"
|
||||
));
|
||||
}
|
||||
self.value_store.push(value);
|
||||
|
@ -261,10 +260,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
)
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"I couldn't find a function '{}' in this WebAssembly module",
|
||||
fn_name
|
||||
)
|
||||
format!("I couldn't find a function '{fn_name}' in this WebAssembly module")
|
||||
})? as usize
|
||||
};
|
||||
|
||||
|
@ -348,7 +344,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
fn fetch_immediate_u32(&mut self, module: &WasmModule<'a>) -> u32 {
|
||||
let x = u32::parse((), &module.code.bytes, &mut self.program_counter).unwrap();
|
||||
if let Some(debug_string) = self.debug_string.as_mut() {
|
||||
write!(debug_string, "{} ", x).unwrap();
|
||||
write!(debug_string, "{x} ").unwrap();
|
||||
}
|
||||
x
|
||||
}
|
||||
|
@ -426,7 +422,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
|
||||
fn write_debug<T: fmt::Debug>(&mut self, value: T) {
|
||||
if let Some(debug_string) = self.debug_string.as_mut() {
|
||||
std::write!(debug_string, "{:?} ", value).unwrap();
|
||||
std::write!(debug_string, "{value:?} ").unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -512,8 +508,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
if let Some(expected) = expected_signature {
|
||||
assert_eq!(
|
||||
expected, signature_index,
|
||||
"Indirect function call failed. Expected signature {} but found {}",
|
||||
expected, signature_index,
|
||||
"Indirect function call failed. Expected signature {expected} but found {signature_index}",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -599,9 +594,9 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
} else {
|
||||
write!(debug_string, ", ").unwrap();
|
||||
}
|
||||
write!(debug_string, "{:x?}", arg).unwrap();
|
||||
write!(debug_string, "{arg:x?}").unwrap();
|
||||
}
|
||||
writeln!(debug_string, "] return_type={:?}", return_type).unwrap();
|
||||
writeln!(debug_string, "] return_type={return_type:?}").unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -747,15 +742,13 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
// So far, all compilers seem to be emitting MVP-compatible code. (Rust, Zig, Roc...)
|
||||
assert_eq!(
|
||||
table_index, 0,
|
||||
"Table index {} not supported at file offset {:#x}. This interpreter only supports Wasm MVP.",
|
||||
table_index, file_offset
|
||||
"Table index {table_index} not supported at file offset {file_offset:#x}. This interpreter only supports Wasm MVP."
|
||||
);
|
||||
|
||||
// Dereference the function pointer (look up the element index in the function table)
|
||||
let fn_index = module.element.lookup(element_index).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Indirect function call failed. There is no function with element index {}",
|
||||
element_index
|
||||
"Indirect function call failed. There is no function with element index {element_index}"
|
||||
)
|
||||
});
|
||||
|
||||
|
@ -1613,28 +1606,28 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
I32TRUNCSF32 => {
|
||||
let arg = self.value_store.pop_f32()?;
|
||||
if arg < i32::MIN as f32 || arg > i32::MAX as f32 {
|
||||
panic!("Cannot truncate {} from F32 to I32", arg);
|
||||
panic!("Cannot truncate {arg} from F32 to I32");
|
||||
}
|
||||
self.value_store.push(Value::I32(arg as i32));
|
||||
}
|
||||
I32TRUNCUF32 => {
|
||||
let arg = self.value_store.pop_f32()?;
|
||||
if arg < u32::MIN as f32 || arg > u32::MAX as f32 {
|
||||
panic!("Cannot truncate {} from F32 to unsigned I32", arg);
|
||||
panic!("Cannot truncate {arg} from F32 to unsigned I32");
|
||||
}
|
||||
self.value_store.push(Value::from(arg as u32));
|
||||
}
|
||||
I32TRUNCSF64 => {
|
||||
let arg = self.value_store.pop_f64()?;
|
||||
if arg < i32::MIN as f64 || arg > i32::MAX as f64 {
|
||||
panic!("Cannot truncate {} from F64 to I32", arg);
|
||||
panic!("Cannot truncate {arg} from F64 to I32");
|
||||
}
|
||||
self.value_store.push(Value::I32(arg as i32));
|
||||
}
|
||||
I32TRUNCUF64 => {
|
||||
let arg = self.value_store.pop_f64()?;
|
||||
if arg < u32::MIN as f64 || arg > u32::MAX as f64 {
|
||||
panic!("Cannot truncate {} from F64 to unsigned I32", arg);
|
||||
panic!("Cannot truncate {arg} from F64 to unsigned I32");
|
||||
}
|
||||
self.value_store.push(Value::from(arg as u32));
|
||||
}
|
||||
|
@ -1649,28 +1642,28 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
I64TRUNCSF32 => {
|
||||
let arg = self.value_store.pop_f32()?;
|
||||
if arg < i64::MIN as f32 || arg > i64::MAX as f32 {
|
||||
panic!("Cannot truncate {} from F32 to I64", arg);
|
||||
panic!("Cannot truncate {arg} from F32 to I64");
|
||||
}
|
||||
self.value_store.push(Value::I64(arg as i64));
|
||||
}
|
||||
I64TRUNCUF32 => {
|
||||
let arg = self.value_store.pop_f32()?;
|
||||
if arg < u64::MIN as f32 || arg > u64::MAX as f32 {
|
||||
panic!("Cannot truncate {} from F32 to unsigned I64", arg);
|
||||
panic!("Cannot truncate {arg} from F32 to unsigned I64");
|
||||
}
|
||||
self.value_store.push(Value::from(arg as u64));
|
||||
}
|
||||
I64TRUNCSF64 => {
|
||||
let arg = self.value_store.pop_f64()?;
|
||||
if arg < i64::MIN as f64 || arg > i64::MAX as f64 {
|
||||
panic!("Cannot truncate {} from F64 to I64", arg);
|
||||
panic!("Cannot truncate {arg} from F64 to I64");
|
||||
}
|
||||
self.value_store.push(Value::I64(arg as i64));
|
||||
}
|
||||
I64TRUNCUF64 => {
|
||||
let arg = self.value_store.pop_f64()?;
|
||||
if arg < u64::MIN as f64 || arg > u64::MAX as f64 {
|
||||
panic!("Cannot truncate {} from F64 to unsigned I64", arg);
|
||||
panic!("Cannot truncate {arg} from F64 to unsigned I64");
|
||||
}
|
||||
self.value_store.push(Value::from(arg as u64));
|
||||
}
|
||||
|
@ -1739,12 +1732,12 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
|
||||
if let Some(debug_string) = &self.debug_string {
|
||||
if matches!(op_code, CALL | CALLINDIRECT) {
|
||||
eprintln!("\n{:06x} {}", file_offset, debug_string);
|
||||
eprintln!("\n{file_offset:06x} {debug_string}");
|
||||
} else {
|
||||
// For calls, we print special debug stuff in do_call
|
||||
let base = self.current_frame.locals_start + self.current_frame.locals_count;
|
||||
let slice = self.value_store.get_slice(base);
|
||||
eprintln!("{:06x} {:17} {:x?}", file_offset, debug_string, slice);
|
||||
eprintln!("{file_offset:06x} {debug_string:17} {slice:x?}");
|
||||
}
|
||||
let is_return = op_code == RETURN || (op_code == END && implicit_return);
|
||||
let is_program_end = self.program_counter == 0;
|
||||
|
@ -1762,7 +1755,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
|
||||
#[allow(dead_code)]
|
||||
fn debug_values_and_blocks(&self, label: &str) {
|
||||
eprintln!("\n========== {} ==========", label);
|
||||
eprintln!("\n========== {label} ==========");
|
||||
|
||||
let mut block_str = String::new();
|
||||
let mut block_iter = self.blocks.iter().enumerate();
|
||||
|
@ -1774,17 +1767,17 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
if *vstack > i {
|
||||
break;
|
||||
}
|
||||
write!(block_str, "{}:{:?} ", b, ty).unwrap();
|
||||
write!(block_str, "{b}:{ty:?} ").unwrap();
|
||||
block = block_iter.next();
|
||||
}
|
||||
if !block_str.is_empty() {
|
||||
eprintln!("--------------- {}", block_str);
|
||||
eprintln!("--------------- {block_str}");
|
||||
}
|
||||
};
|
||||
|
||||
for (i, v) in self.value_store.iter().enumerate() {
|
||||
print_blocks(i);
|
||||
eprintln!("{:3} {:x?}", i, v);
|
||||
eprintln!("{i:3} {v:x?}");
|
||||
}
|
||||
print_blocks(self.value_store.depth());
|
||||
|
||||
|
@ -1801,7 +1794,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
/// --------------
|
||||
fn debug_stack_trace(&self, buffer: &mut String) -> fmt::Result {
|
||||
let divider = "-------------------";
|
||||
writeln!(buffer, "{}", divider)?;
|
||||
writeln!(buffer, "{divider}")?;
|
||||
|
||||
let frames = self.previous_frames.iter().chain(once(&self.current_frame));
|
||||
let next_frames = frames.clone().skip(1);
|
||||
|
@ -1850,7 +1843,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
.unwrap_or("");
|
||||
|
||||
// Function and address match wasm-objdump formatting, for easy copy & find
|
||||
writeln!(buffer, "func[{}] {}", fn_index, fn_name)?;
|
||||
writeln!(buffer, "func[{fn_index}] {fn_name}")?;
|
||||
writeln!(buffer, " address {:06x}", execution_addrs.next().unwrap())?;
|
||||
|
||||
write!(buffer, " args ")?;
|
||||
|
@ -1861,7 +1854,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
} else if local_index != 0 {
|
||||
write!(buffer, ", ")?;
|
||||
}
|
||||
write!(buffer, "{}: {:?}", local_index, value)?;
|
||||
write!(buffer, "{local_index}: {value:?}")?;
|
||||
}
|
||||
|
||||
write!(buffer, "\n stack [")?;
|
||||
|
@ -1874,10 +1867,10 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
|||
if i != stack_start {
|
||||
write!(buffer, ", ")?;
|
||||
}
|
||||
write!(buffer, "{:?}", value)?;
|
||||
write!(buffer, "{value:?}")?;
|
||||
}
|
||||
writeln!(buffer, "]")?;
|
||||
writeln!(buffer, "{}", divider)?;
|
||||
writeln!(buffer, "{divider}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -53,10 +53,7 @@ impl<'a> ImportDispatcher for DefaultImportDispatcher<'a> {
|
|||
if module_name == wasi::MODULE_NAME {
|
||||
self.wasi.dispatch(function_name, arguments, memory)
|
||||
} else {
|
||||
panic!(
|
||||
"DefaultImportDispatcher does not implement {}.{}",
|
||||
module_name, function_name
|
||||
);
|
||||
panic!("DefaultImportDispatcher does not implement {module_name}.{function_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,14 +73,12 @@ impl Error {
|
|||
match self {
|
||||
Error::Type(expected, actual) => {
|
||||
format!(
|
||||
"ERROR: I found a type mismatch at file offset {:#x}. Expected {:?}, but found {:?}.\n",
|
||||
file_offset, expected, actual
|
||||
"ERROR: I found a type mismatch at file offset {file_offset:#x}. Expected {expected:?}, but found {actual:?}.\n"
|
||||
)
|
||||
}
|
||||
Error::StackEmpty => {
|
||||
format!(
|
||||
"ERROR: I tried to pop a value from the stack at file offset {:#x}, but it was empty.\n",
|
||||
file_offset
|
||||
"ERROR: I tried to pop a value from the stack at file offset {file_offset:#x}, but it was empty.\n"
|
||||
)
|
||||
}
|
||||
Error::MemoryAccessOutOfBounds(addr, memory_size) => {
|
||||
|
@ -93,10 +88,7 @@ impl Error {
|
|||
)
|
||||
}
|
||||
Error::UnreachableOp => {
|
||||
format!(
|
||||
"WebAssembly `unreachable` instruction at file offset {:#x}.\n",
|
||||
file_offset
|
||||
)
|
||||
format!("WebAssembly `unreachable` instruction at file offset {file_offset:#x}.\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ fn main() -> io::Result<()> {
|
|||
let dispatcher = DefaultImportDispatcher::new(&wasi_argv);
|
||||
let mut inst =
|
||||
Instance::for_module(&arena, &module, dispatcher, is_debug_mode).unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
eprintln!("{e}");
|
||||
process::exit(2);
|
||||
});
|
||||
|
||||
|
@ -103,14 +103,14 @@ fn main() -> io::Result<()> {
|
|||
match result {
|
||||
Ok(Some(val)) => {
|
||||
if is_hex_format {
|
||||
println!("{:#x?}", val)
|
||||
println!("{val:#x?}")
|
||||
} else {
|
||||
println!("{:?}", val)
|
||||
println!("{val:?}")
|
||||
}
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
eprintln!("{e}");
|
||||
process::exit(3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ where
|
|||
|
||||
// Dump the generated module to a file (this is mainly for debugging the test itself)
|
||||
if std::env::var("DEBUG_WASM_INTERP_TEST").is_ok() {
|
||||
let filename = format!("/tmp/{:?}.wasm", op);
|
||||
let filename = format!("/tmp/{op:?}.wasm");
|
||||
println!("\nDumping test module to {}\n", &filename);
|
||||
let mut outfile_buf = Vec::new_in(&arena);
|
||||
module.serialize(&mut outfile_buf);
|
||||
|
|
|
@ -563,7 +563,7 @@ fn test_call_import() {
|
|||
module.serialize(&mut buf);
|
||||
let filename = "/tmp/roc/call-return.wasm";
|
||||
std::fs::write(filename, buf).unwrap();
|
||||
println!("Wrote to {}", filename);
|
||||
println!("Wrote to {filename}");
|
||||
}
|
||||
|
||||
let mut inst = Instance::for_module(&arena, &module, import_dispatcher, true).unwrap();
|
||||
|
@ -631,7 +631,7 @@ fn test_call_return_no_args() {
|
|||
module.serialize(&mut buf);
|
||||
let filename = "/tmp/roc/call-return.wasm";
|
||||
std::fs::write(filename, buf).unwrap();
|
||||
println!("Wrote to {}", filename);
|
||||
println!("Wrote to {filename}");
|
||||
}
|
||||
|
||||
let mut inst =
|
||||
|
@ -771,9 +771,9 @@ fn test_call_indirect_help(table_index: u32, elem_index: u32) -> Value {
|
|||
if false {
|
||||
let mut outfile_buf = Vec::new_in(&arena);
|
||||
module.serialize(&mut outfile_buf);
|
||||
let filename = format!("/tmp/roc/call_indirect_{}_{}.wasm", table_index, elem_index);
|
||||
let filename = format!("/tmp/roc/call_indirect_{table_index}_{elem_index}.wasm");
|
||||
std::fs::write(&filename, outfile_buf).unwrap();
|
||||
println!("\nWrote to {}\n", filename);
|
||||
println!("\nWrote to {filename}\n");
|
||||
}
|
||||
|
||||
let mut inst = Instance::for_module(
|
||||
|
|
|
@ -158,6 +158,6 @@ mod tests {
|
|||
stack.push(val);
|
||||
}
|
||||
|
||||
assert_eq!(format!("{:?}", VALUES), format!("{:?}", stack));
|
||||
assert_eq!(format!("{VALUES:?}"), format!("{stack:?}"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ impl<'a> WasiDispatcher<'a> {
|
|||
if fd < self.files.len() {
|
||||
success_code
|
||||
} else {
|
||||
println!("WASI warning: file descriptor {} does not exist", fd);
|
||||
println!("WASI warning: file descriptor {fd} does not exist");
|
||||
Some(Value::I32(Errno::Badf as i32))
|
||||
}
|
||||
}
|
||||
|
@ -291,8 +291,7 @@ impl<'a> WasiDispatcher<'a> {
|
|||
if negative_length_count > 0 {
|
||||
// Let's see if we ever get this message. If not, we can remove this negative-length stuff.
|
||||
eprintln!(
|
||||
"WASI DEV INFO: found {} negative-length iovecs.",
|
||||
negative_length_count
|
||||
"WASI DEV INFO: found {negative_length_count} negative-length iovecs."
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -331,7 +330,7 @@ impl<'a> WasiDispatcher<'a> {
|
|||
"sock_recv" => todo!("WASI {}({:?})", function_name, arguments),
|
||||
"sock_send" => todo!("WASI {}({:?})", function_name, arguments),
|
||||
"sock_shutdown" => todo!("WASI {}({:?})", function_name, arguments),
|
||||
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
|
||||
_ => panic!("Unknown WASI function {function_name}({arguments:?})"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue