Skip to content

Commit

Permalink
fix: correct type when simplifying derive_pedersen_generators (#6579)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Nov 21, 2024
1 parent 7658c17 commit efa5cc4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 33 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ fn simplify_derive_generators(
results.push(is_infinite);
}
let len = results.len();
let typ = Type::Array(vec![Type::field()].into(), len);
let typ =
Type::Array(vec![Type::field(), Type::field(), Type::unsigned(1)].into(), len / 3);
let result = make_array(dfg, results.into(), typ, block, call_stack);
SimplifyResult::SimplifiedTo(result)
} else {
Expand All @@ -816,3 +817,34 @@ fn simplify_derive_generators(
unreachable!("Unexpected number of arguments to derive_generators");
}
}

#[cfg(test)]
mod tests {
use crate::ssa::{opt::assert_normalized_ssa_equals, Ssa};

#[test]
fn simplify_derive_generators_has_correct_type() {
let src = "
brillig(inline) fn main f0 {
b0():
v0 = make_array [u8 68, u8 69, u8 70, u8 65, u8 85, u8 76, u8 84, u8 95, u8 68, u8 79, u8 77, u8 65, u8 73, u8 78, u8 95, u8 83, u8 69, u8 80, u8 65, u8 82, u8 65, u8 84, u8 79, u8 82] : [u8; 24]
// This call was previously incorrectly simplified to something that returned `[Field; 3]`
v2 = call derive_pedersen_generators(v0, u32 0) -> [(Field, Field, u1); 1]
return v2
}
";
let ssa = Ssa::from_str(src).unwrap();

let expected = "
brillig(inline) fn main f0 {
b0():
v15 = make_array [u8 68, u8 69, u8 70, u8 65, u8 85, u8 76, u8 84, u8 95, u8 68, u8 79, u8 77, u8 65, u8 73, u8 78, u8 95, u8 83, u8 69, u8 80, u8 65, u8 82, u8 65, u8 84, u8 79, u8 82] : [u8; 24]
v19 = make_array [Field 3728882899078719075161482178784387565366481897740339799480980287259621149274, Field -9903063709032878667290627648209915537972247634463802596148419711785767431332, u1 0] : [(Field, Field, u1); 1]
return v19
}
";
assert_normalized_ssa_equals(ssa, expected);
}
}
5 changes: 5 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ mod tests;
mod token;

impl Ssa {
/// Creates an Ssa object from the given string.
///
/// Note that the resulting Ssa might not be exactly the same as the given string.
/// This is because, internally, the Ssa is built using a `FunctionBuilder`, so
/// some instructions might be simplified while they are inserted.
pub(crate) fn from_str(src: &str) -> Result<Ssa, SsaErrorWithSource> {
let mut parser =
Parser::new(src).map_err(|err| SsaErrorWithSource::parse_error(err, src))?;
Expand Down

0 comments on commit efa5cc4

Please sign in to comment.