Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix warnings in avm transpiler #11001

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ pub fn brillig_to_avm(brillig_bytecode: &[BrilligOpcode<FieldElement>]) -> (Vec<
fn handle_foreign_call(
avm_instrs: &mut Vec<AvmInstruction>,
function: &str,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
match function {
"avmOpcodeCall" => handle_external_call(avm_instrs, destinations, inputs, AvmOpcode::CALL),
Expand Down Expand Up @@ -452,8 +452,8 @@ fn handle_foreign_call(
// ) -> bool {}
fn handle_external_call(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
opcode: AvmOpcode,
) {
if destinations.len() != 1 || inputs.len() != 4 {
Expand Down Expand Up @@ -496,10 +496,10 @@ fn handle_external_call(
opcode,
indirect: Some(
AddressingModeBuilder::default()
.indirect_operand(&gas_offset_ptr)
.indirect_operand(gas_offset_ptr)
.direct_operand(address_offset)
.indirect_operand(&args_offset_ptr)
.direct_operand(&args_size_offset)
.indirect_operand(args_offset_ptr)
.direct_operand(args_size_offset)
.direct_operand(success_offset)
.build(),
),
Expand Down Expand Up @@ -528,10 +528,10 @@ fn handle_cast(
/// Adds the new instruction to the avm instructions list.
fn handle_note_hash_exists(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
let (note_hash_offset_operand, leaf_index_offset_operand) = match &inputs[..] {
let (note_hash_offset_operand, leaf_index_offset_operand) = match inputs {
[
ValueOrArray::MemoryAddress(nh_offset),
ValueOrArray::MemoryAddress(li_offset)
Expand All @@ -540,7 +540,7 @@ fn handle_note_hash_exists(
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 2 inputs of type MemoryAddress, got {:?}", inputs
),
};
let exists_offset_operand = match &destinations[..] {
let exists_offset_operand = match destinations {
[ValueOrArray::MemoryAddress(offset)] => offset,
_ => panic!(
"Transpiler expects ForeignCall::NOTEHASHEXISTS to have 1 output of type MemoryAddress, got {:?}", destinations
Expand All @@ -566,8 +566,8 @@ fn handle_note_hash_exists(

fn handle_emit_unencrypted_log(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
if !destinations.is_empty() || inputs.len() != 2 {
panic!(
Expand Down Expand Up @@ -606,8 +606,8 @@ fn handle_emit_unencrypted_log(
fn handle_emit_note_hash_or_nullifier(
is_nullifier: bool, // false for note hash, true for nullifier
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
let function_name = if is_nullifier { "EMITNULLIFIER" } else { "EMITNOTEHASH" };

Expand Down Expand Up @@ -639,8 +639,8 @@ fn handle_emit_note_hash_or_nullifier(
/// Adds the new instruction to the avm instructions list.
fn handle_nullifier_exists(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
if destinations.len() != 1 || inputs.len() != 2 {
panic!("Transpiler expects ForeignCall::CHECKNULLIFIEREXISTS to have 1 destinations and 2 inputs, got {} and {}", destinations.len(), inputs.len());
Expand Down Expand Up @@ -680,8 +680,8 @@ fn handle_nullifier_exists(
/// Adds the new instruction to the avm instructions list.
fn handle_l1_to_l2_msg_exists(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
if destinations.len() != 1 || inputs.len() != 2 {
panic!(
Expand Down Expand Up @@ -731,8 +731,8 @@ fn handle_l1_to_l2_msg_exists(
/// Adds the new instruction to the avm instructions list.
fn handle_send_l2_to_l1_msg(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
if !destinations.is_empty() || inputs.len() != 2 {
panic!(
Expand Down Expand Up @@ -780,9 +780,10 @@ fn handle_send_l2_to_l1_msg(
fn handle_getter_instruction(
avm_instrs: &mut Vec<AvmInstruction>,
function: &str,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
#[allow(clippy::upper_case_acronyms)]
enum EnvironmentVariable {
ADDRESS,
SENDER,
Expand Down Expand Up @@ -1161,8 +1162,8 @@ fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &B

fn handle_debug_log(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
if !destinations.is_empty() || inputs.len() != 3 {
panic!(
Expand Down Expand Up @@ -1209,8 +1210,8 @@ fn handle_debug_log(
// unconstrained fn calldata_copy_opcode<let N: u32>(cdoffset: Field) -> [Field; N] {}
fn handle_calldata_copy(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 2);
assert!(destinations.len() == 1);
Expand Down Expand Up @@ -1252,10 +1253,10 @@ fn handle_calldata_copy(
// unconstrained fn returndata_size_opcode() -> u32 {}
fn handle_returndata_size(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 0);
assert!(inputs.is_empty());
assert!(destinations.len() == 1);

let dest_offset = match destinations[0] {
Expand All @@ -1275,8 +1276,8 @@ fn handle_returndata_size(
// unconstrained fn returndata_copy_opcode(rdoffset: u32, copy_size: u32) -> [Field] {}
fn handle_returndata_copy(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 2);
assert!(destinations.len() == 2);
Expand Down Expand Up @@ -1333,11 +1334,11 @@ fn handle_returndata_copy(
// unconstrained fn return_opcode<let N: u32>(returndata: [Field; N]) {}
fn handle_return(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 2);
assert!(destinations.len() == 0);
assert!(destinations.is_empty());

// First arg is the size, which is ignored because it's redundant.
let (return_data_offset, return_data_size) = match inputs[1] {
Expand All @@ -1352,11 +1353,11 @@ fn handle_return(
// unconstrained fn revert_opcode(revertdata: [Field]) {}
fn handle_revert(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 2);
assert!(destinations.len() == 0);
assert!(destinations.is_empty());

// First arg is the size, which is ignored because it's redundant.
let (revert_data_offset, revert_data_size_offset) = match inputs[1] {
Expand All @@ -1371,8 +1372,8 @@ fn handle_revert(
/// The current implementation writes an array of values into storage ( contiguous slots in memory )
fn handle_storage_write(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 2);
assert!(destinations.is_empty());
Expand Down Expand Up @@ -1409,10 +1410,10 @@ fn handle_storage_write(
fn handle_get_contract_instance(
avm_instrs: &mut Vec<AvmInstruction>,
function: &str,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
#[allow(non_camel_case_types)]
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
enum ContractInstanceMember {
DEPLOYER,
CLASS_ID,
Expand Down Expand Up @@ -1470,8 +1471,8 @@ fn handle_get_contract_instance(
/// The current implementation reads an array of values from storage ( contiguous slots in memory )
fn handle_storage_read(
avm_instrs: &mut Vec<AvmInstruction>,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
assert!(inputs.len() == 1); // output
assert!(destinations.len() == 1); // return value
Expand Down
Loading