Skip to content

Commit

Permalink
Merge pull request #613 from matthiasgoergens/matthias/clippy-fix-simple
Browse files Browse the repository at this point in the history
Automatic fixes from clippy
  • Loading branch information
grjte committed Jan 6, 2023
2 parents 91590ae + 57930e9 commit 3754f33
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 158 deletions.
31 changes: 15 additions & 16 deletions assembly/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn single_span() {
let source = "begin push.1 push.2 add end";
let program = assembler.compile(source).unwrap();
let expected = "begin span pad incr push(2) add end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand All @@ -54,7 +54,7 @@ fn span_and_simple_if() {
if.true span add end else span mul end end \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));

// if without else
let source = "begin push.2 push.3 if.true add end end";
Expand All @@ -66,7 +66,7 @@ fn span_and_simple_if() {
if.true span add end else span noop end end \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

// NESTED CONTROL BLOCKS
Expand Down Expand Up @@ -107,7 +107,7 @@ fn nested_control_blocks() {
span push(3) add end \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

// PROGRAMS WITH PROCEDURES
Expand All @@ -119,7 +119,7 @@ fn program_with_one_procedure() {
let source = "proc.foo push.3 push.7 mul end begin push.2 push.3 add exec.foo end";
let program = assembler.compile(source).unwrap();
let expected = "begin span push(2) push(3) add push(3) push(7) mul end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand All @@ -134,7 +134,7 @@ fn program_with_nested_procedure() {
span push(2) push(4) add push(3) push(7) mul \
push(11) push(5) push(3) push(7) mul add neg add \
end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand Down Expand Up @@ -164,7 +164,7 @@ fn program_with_proc_locals() {
push(18446744069414584320) fmpupdate \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand Down Expand Up @@ -227,14 +227,13 @@ fn program_with_one_import() {
let assembler = super::Assembler::default().with_library(&DummyLibrary::default()).unwrap();
let source = format!(
r#"
use.{}::{}
use.{NAMESPACE}::{MODULE}
begin
push.4 push.3
exec.u256::iszero_unsafe
end"#,
NAMESPACE, MODULE
end"#
);
let program = assembler.compile(&source).unwrap();
let program = assembler.compile(source).unwrap();
let expected = "\
begin \
span \
Expand All @@ -249,7 +248,7 @@ fn program_with_one_import() {
swap eqz and \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand Down Expand Up @@ -284,7 +283,7 @@ fn comment_simple() {
let source = "begin # simple comment \n push.1 push.2 add end";
let program = assembler.compile(source).unwrap();
let expected = "begin span pad incr push(2) add end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand Down Expand Up @@ -324,7 +323,7 @@ fn comment_in_nested_control_blocks() {
span push(3) add end \
end \
end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand All @@ -333,7 +332,7 @@ fn comment_before_program() {
let source = " # starting comment \n begin push.1 push.2 add end";
let program = assembler.compile(source).unwrap();
let expected = "begin span pad incr push(2) add end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

#[test]
Expand All @@ -342,7 +341,7 @@ fn comment_after_program() {
let source = "begin push.1 push.2 add end # closing comment";
let program = assembler.compile(source).unwrap();
let expected = "begin span pad incr push(2) add end end";
assert_eq!(expected, format!("{}", program));
assert_eq!(expected, format!("{program}"));
}

// ERRORS
Expand Down
2 changes: 1 addition & 1 deletion miden/tests/integration/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Test {
assert!(miden::verify(program.hash(), &pub_inputs, &outputs, proof).is_err());
} else {
let result = miden::verify(program.hash(), &pub_inputs, &outputs, proof);
assert!(result.is_ok(), "error: {:?}", result);
assert!(result.is_ok(), "error: {result:?}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion miden/tests/integration/operations/decorators/asmop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ fn build_vm_state(vm_state_iterator: VmStateIterator) -> Vec<VmStatePartial> {
let mut vm_state = Vec::new();
for state in vm_state_iterator {
vm_state.push(VmStatePartial {
clk: state.as_ref().unwrap().clk as u32,
clk: state.as_ref().unwrap().clk,
asmop: state.as_ref().unwrap().asmop.clone(),
op: state.as_ref().unwrap().op,
});
Expand Down
28 changes: 14 additions & 14 deletions miden/tests/integration/operations/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn add() {

#[test]
fn add_b() {
let build_asm_op = |param: u64| format!("add.{}", param);
let build_asm_op = |param: u64| format!("add.{param}");

// --- simple case ----------------------------------------------------------------------------
let test = build_op_test!(build_asm_op(2), &[1]);
Expand Down Expand Up @@ -120,7 +120,7 @@ fn sub() {

#[test]
fn sub_b() {
let build_asm_op = |param: u64| format!("sub.{}", param);
let build_asm_op = |param: u64| format!("sub.{param}");

// --- simple case ----------------------------------------------------------------------------
let test = build_op_test!(build_asm_op(2), &[3]);
Expand Down Expand Up @@ -164,7 +164,7 @@ fn mul() {

#[test]
fn mul_b() {
let build_asm_op = |param: u64| format!("mul.{}", param);
let build_asm_op = |param: u64| format!("mul.{param}");

// --- simple cases ---------------------------------------------------------------------------
let test = build_op_test!(build_asm_op(0), &[1]);
Expand Down Expand Up @@ -212,7 +212,7 @@ fn div() {

#[test]
fn div_b() {
let build_asm_op = |param: u64| format!("div.{}", param);
let build_asm_op = |param: u64| format!("div.{param}");

// --- simple cases ---------------------------------------------------------------------------
let test = build_op_test!(build_asm_op(1), &[0]);
Expand Down Expand Up @@ -331,7 +331,7 @@ fn pow2_fail() {

#[test]
fn exp_bits_length() {
let build_asm_op = |param: u64| format!("exp.u{}", param);
let build_asm_op = |param: u64| format!("exp.u{param}");

//---------------------- exp with parameter containing bits length ----------------------------

Expand All @@ -345,7 +345,7 @@ fn exp_bits_length() {

#[test]
fn exp_bits_length_fail() {
let build_asm_op = |param: u64| format!("exp.u{}", param);
let build_asm_op = |param: u64| format!("exp.u{param}");

//---------------------- exp containing more bits than specified in the parameter ------------

Expand All @@ -366,7 +366,7 @@ fn exp_bits_length_fail() {

#[test]
fn exp_small_pow() {
let build_asm_op = |param: u64| format!("exp.{}", param);
let build_asm_op = |param: u64| format!("exp.{param}");

let base = rand_value::<u64>();
let pow = 7;
Expand Down Expand Up @@ -582,7 +582,7 @@ proptest! {
test.prop_expect_stack(&[expected as u64])?;

// b provided as a parameter
let asm_op = format!("{}.{}", asm_op, b);
let asm_op = format!("{asm_op}.{b}");
let test = build_op_test!(&asm_op, &[a]);
test.prop_expect_stack(&[expected as u64])?;
}
Expand All @@ -609,12 +609,12 @@ proptest! {
test.prop_expect_stack(&[Felt::MODULUS - expected])?;

// b provided as a parameter
let asm_op_b = format!("{}.{}", asm_op, b);
let asm_op_b = format!("{asm_op}.{b}");
let test = build_op_test!(&asm_op_b, &[a]);
test.prop_expect_stack(&[expected])?;

// underflow by a provided as a parameter
let asm_op_b = format!("{}.{}", asm_op, a);
let asm_op_b = format!("{asm_op}.{a}");
let test = build_op_test!(asm_op_b, &[b]);
test.prop_expect_stack(&[Felt::MODULUS - expected])?;
}
Expand All @@ -631,7 +631,7 @@ proptest! {
test.prop_expect_stack(&[expected as u64])?;

// b provided as a parameter
let asm_op = format!("{}.{}", asm_op, b);
let asm_op = format!("{asm_op}.{b}");
let test = build_op_test!(&asm_op, &[a]);
test.prop_expect_stack(&[expected as u64])?;
}
Expand All @@ -648,7 +648,7 @@ proptest! {
test.prop_expect_stack(&[expected as u64])?;

// b provided as a parameter
let asm_op = format!("{}.{}", asm_op, b);
let asm_op = format!("{asm_op}.{b}");
let test = build_op_test!(&asm_op, &[a]);
test.prop_expect_stack(&[expected as u64])?;
}
Expand Down Expand Up @@ -682,7 +682,7 @@ proptest! {
let asm_op = "pow2";
let expected = 2_u64.wrapping_pow(b);

build_op_test!(asm_op, &[b as u64]).prop_expect_stack(&[expected as u64])?;
build_op_test!(asm_op, &[b as u64]).prop_expect_stack(&[expected])?;
}

#[test]
Expand All @@ -700,7 +700,7 @@ proptest! {

//----------------------- exp with parameter containing pow ----------------

let build_asm_op = |param: u64| format!("exp.{}", param);
let build_asm_op = |param: u64| format!("exp.{param}");
let base = a;
let pow = b;
let expected = Felt::new(base).exp(pow);
Expand Down
2 changes: 1 addition & 1 deletion miden/tests/integration/operations/io_ops/adv_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn adv_push() {
let asm_op = "adv_push";
let advice_tape = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let test_n = |n: usize| {
let source = format!("{}.{}", asm_op, n);
let source = format!("{asm_op}.{n}");
let mut final_stack = vec![0; n];
final_stack.copy_from_slice(&advice_tape[..n]);
final_stack.reverse();
Expand Down
12 changes: 6 additions & 6 deletions miden/tests/integration/operations/io_ops/constant_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ fn push_many() {
let base_op = "push";

// --- multiple values with separators --------------------------------------------------------
let asm_op = format!("{}.17.0x13.23", base_op);
let asm_op = format!("{base_op}.17.0x13.23");
let test = build_op_test!(asm_op);
test.expect_stack(&[23, 19, 17]);

// --- push the maximum number of decimal values (16) -------------------------------------
let asm_op = format!("{}.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31", base_op);
let asm_op = format!("{base_op}.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31");
let mut expected = Vec::with_capacity(16);
for i in (16..32).rev() {
expected.push(i);
Expand All @@ -43,7 +43,7 @@ fn push_many() {
test.expect_stack(&expected);

// --- push hexadecimal values with period separators between values ----------------------
let asm_op = format!("{}.0x0A.0x64.0x03E8.0x2710.0x0186A0", base_op);
let asm_op = format!("{base_op}.0x0A.0x64.0x03E8.0x2710.0x0186A0");
let mut expected = Vec::with_capacity(5);
for i in (1..=5).rev() {
expected.push(10_u64.pow(i));
Expand All @@ -53,7 +53,7 @@ fn push_many() {
test.expect_stack(&expected);

// --- push a mixture of decimal and single-element hexadecimal values --------------------
let asm_op = format!("{}.2.4.8.0x10.0x20.0x40.128.0x0100", base_op);
let asm_op = format!("{base_op}.2.4.8.0x10.0x20.0x40.128.0x0100");
let mut expected = Vec::with_capacity(8);
for i in (1_u32..=8).rev() {
expected.push(2_u64.pow(i));
Expand All @@ -68,13 +68,13 @@ fn push_without_separator() {
let base_op = "push";

// --- multiple values as a hexadecimal string ------------------------------------------------
let asm_op = format!("{}.0x0000000000004321000000000000dcba", base_op);
let asm_op = format!("{base_op}.0x0000000000004321000000000000dcba");

let test = build_op_test!(asm_op);
test.expect_stack(&[56506, 17185]);

// --- push the maximum number of hexadecimal values without separators (16) ------------------
let asm_op = format!("{}.0x0000000000000000000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000000700000000000000080000000000000009000000000000000A000000000000000B000000000000000C000000000000000D000000000000000E000000000000000F", base_op);
let asm_op = format!("{base_op}.0x0000000000000000000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000000700000000000000080000000000000009000000000000000A000000000000000B000000000000000C000000000000000D000000000000000E000000000000000F");
let mut expected = Vec::with_capacity(16);
for i in (0..16).rev() {
expected.push(i);
Expand Down
2 changes: 1 addition & 1 deletion miden/tests/integration/operations/io_ops/env_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn sdepth() {

// --- overflowed stack -----------------------------------------------------------------------
// push 2 values to increase the lenth of the stack beyond 16
let source = format!("begin push.1 push.1 {} end", test_op);
let source = format!("begin push.1 push.1 {test_op} end");
let test = build_test!(&source, &[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7]);
test.expect_stack(&[18, 1, 1, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3]);
}
Expand Down
8 changes: 4 additions & 4 deletions miden/tests/integration/operations/io_ops/mem_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn mem_load() {
test.expect_stack(&[0]);

// --- read from uninitialized memory - address provided as a parameter -----------------------
let asm_op = format!("{}.{}", asm_op, addr);
let asm_op = format!("{asm_op}.{addr}");
let test = build_op_test!(&asm_op);
test.expect_stack(&[0]);

Expand All @@ -36,7 +36,7 @@ fn mem_store() {
test.expect_stack_and_memory(&[3, 2, 1], addr, &[4, 0, 0, 0]);

// --- address provided as a parameter --------------------------------------------------------
let asm_op = format!("{}.{}", asm_op, addr);
let asm_op = format!("{asm_op}.{addr}");
let test = build_op_test!(&asm_op, &[1, 2, 3, 4]);
test.expect_stack_and_memory(&[3, 2, 1], addr, &[4, 0, 0, 0]);
}
Expand All @@ -54,7 +54,7 @@ fn mem_loadw() {
test.expect_stack(&[0, 0, 0, 0]);

// --- read from uninitialized memory - address provided as a parameter -----------------------
let asm_op = format!("{}.{}", asm_op, addr);
let asm_op = format!("{asm_op}.{addr}");

let test = build_op_test!(asm_op, &[5, 6, 7, 8]);
test.expect_stack(&[0, 0, 0, 0]);
Expand All @@ -78,7 +78,7 @@ fn mem_storew() {
test.expect_stack_and_memory(&[4, 3, 2, 1], addr, &[1, 2, 3, 4]);

// --- address provided as a parameter --------------------------------------------------------
let asm_op = format!("{}.{}", asm_op, addr);
let asm_op = format!("{asm_op}.{addr}");
let test = build_op_test!(&asm_op, &[1, 2, 3, 4]);
test.expect_stack_and_memory(&[4, 3, 2, 1], addr, &[1, 2, 3, 4]);

Expand Down

0 comments on commit 3754f33

Please sign in to comment.