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

fix: avoid creating unnecessary memory blocks #7114

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3709,4 +3709,38 @@ mod test {
}
}
}

#[test]
fn does_not_generate_memory_blocks_without_dynamic_accesses() {
let src = "
acir(inline) fn main f0 {
b0(v0: [Field; 2]):
v2, v3 = call as_slice(v0) -> (u32, [Field])
call f1(u32 2, v3)
v7 = array_get v0, index u32 0 -> Field
constrain v7 == Field 0
return
}

brillig(inline) fn foo f1 {
b0(v0: u32, v1: [Field]):
return
}
";
let ssa = Ssa::from_str(src).unwrap();
let brillig = ssa.to_brillig(false);

let (acir_functions, _brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

assert_eq!(acir_functions.len(), 1);

// Check that no memory opcodes were emitted.
let main = &acir_functions[0];
assert!(!main
.opcodes()
.iter()
.any(|opcode| matches!(opcode, Opcode::MemoryInit { .. } | Opcode::MemoryOp { .. })));
}
}
Loading