Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions compiler/noirc_evaluator/src/acir/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,19 @@
.get(&value_id)
.expect("ICE: Unknown slice input to brillig")
{
AcirValue::DynamicArray(AcirDynamicArray { len, .. }) => *len,
AcirValue::Array(array) => array.len(),
AcirValue::DynamicArray(AcirDynamicArray { len, .. }) => {
// len holds the flattened length of all elements in the slice,
// so to get the no-flattened length we need to divide by the flattened
// length of a single slice entry
let sum: u32 = item_types.iter().map(|typ| typ.flattened_size()).sum();
if sum == 0 { 0 } else { *len / sum as usize }

Check warning on line 196 in compiler/noirc_evaluator/src/acir/call/mod.rs

View workflow job for this annotation

GitHub Actions / Incremental Mutation Test

Missed mutant

replace / with * in Context<'_>::gen_brillig_parameters

Check warning on line 196 in compiler/noirc_evaluator/src/acir/call/mod.rs

View workflow job for this annotation

GitHub Actions / Incremental Mutation Test

Missed mutant

replace / with % in Context<'_>::gen_brillig_parameters

Check warning on line 196 in compiler/noirc_evaluator/src/acir/call/mod.rs

View workflow job for this annotation

GitHub Actions / Incremental Mutation Test

Missed mutant

replace == with != in Context<'_>::gen_brillig_parameters
}

Check warning on line 197 in compiler/noirc_evaluator/src/acir/call/mod.rs

View workflow job for this annotation

GitHub Actions / Incremental Mutation Test

Missed mutant

delete match arm AcirValue::DynamicArray(AcirDynamicArray{len, ..}) in Context<'_>::gen_brillig_parameters
AcirValue::Array(array) => {
// len holds the non-flattened length of all elements in the slice,
// so here we need to divide by the non-flattened length of a single
// slice entry
if item_types.len() == 0 { 0 } else { array.len() / item_types.len() }

Check warning on line 202 in compiler/noirc_evaluator/src/acir/call/mod.rs

View workflow job for this annotation

GitHub Actions / Incremental Mutation Test

Missed mutant

replace == with != in Context<'_>::gen_brillig_parameters
}
_ => unreachable!("ICE: Slice value is not an array"),
};

Expand All @@ -198,7 +209,7 @@
.iter()
.map(BrilligFunctionContext::ssa_type_to_parameter)
.collect(),
len / item_types.len(),
len,
)
} else {
BrilligFunctionContext::ssa_type_to_parameter(&typ)
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/acir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(super) struct AcirDynamicArray {
/// Identification for the Acir dynamic array
/// This is essentially a ACIR pointer to the array
pub(super) block_id: BlockId,
/// Length of the array
/// Flattened length of the elements in the array
pub(super) len: usize,
/// An ACIR dynamic array is a flat structure, so we use
/// the inner structure of an `AcirType::NumericType` directly.
Expand Down
9 changes: 7 additions & 2 deletions compiler/noirc_evaluator/src/ssa/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,13 @@ impl<'a> Parser<'a> {

fn parse_types(&mut self) -> ParseResult<Vec<Type>> {
if self.eat(Token::LeftParen)? {
let types = self.parse_comma_separated_types()?;
self.eat_or_error(Token::RightParen)?;
let types = if self.eat(Token::RightParen)? {
Vec::new()
} else {
let types = self.parse_comma_separated_types()?;
self.eat_or_error(Token::RightParen)?;
types
};
Ok(types)
} else {
Ok(vec![self.parse_type()?])
Expand Down
12 changes: 12 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ fn test_make_composite_slice() {
assert_ssa_roundtrip(src);
}

#[test]
fn test_make_empty_composite_array() {
let src = "
acir(inline) fn main f0 {
b0():
v0 = make_array [] : [(); 1]
return v0
}
";
assert_ssa_roundtrip(src);
}

#[test]
fn test_make_byte_array_with_string_literal() {
let src = "
Expand Down
21 changes: 20 additions & 1 deletion compiler/noirc_evaluator/src/ssa/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@
composite_type
}
Type::Slice(composite_type) => {
if elements.len() % composite_type.len() != 0 {
if composite_type.is_empty() {
if !elements.is_empty() {
panic!(
"MakeArray slice has non-zero {} elements but composite type is empty",
elements.len(),
);
}
} else if elements.len() % composite_type.len() != 0 {
panic!(
"MakeArray slice has {} elements but composite type has {} types which don't divide the number of elements",
elements.len(),
Expand Down Expand Up @@ -673,19 +680,19 @@
// message_hash: [u8; N],
// predicate: bool,
// ) -> bool
assert_arguments_length(arguments, 5, "ecdsa_secp_256");

Check warning on line 683 in compiler/noirc_evaluator/src/ssa/validation/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (secp)

let public_key_x = arguments[0];
let public_key_x_type = dfg.type_of_value(public_key_x);
let public_key_x_length =
assert_u8_array(&public_key_x_type, "ecdsa_secp256 public_key_x");

Check warning on line 688 in compiler/noirc_evaluator/src/ssa/validation/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (secp)
assert_array_length(public_key_x_length, 32, "ecdsa_secp256 public_key_x");

Check warning on line 689 in compiler/noirc_evaluator/src/ssa/validation/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (secp)

let public_key_y = arguments[1];
let public_key_y_type = dfg.type_of_value(public_key_y);
let public_key_y_length =
assert_u8_array(&public_key_y_type, "ecdsa_secp256 public_key_y");

Check warning on line 694 in compiler/noirc_evaluator/src/ssa/validation/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (secp)
assert_array_length(public_key_y_length, 32, "ecdsa_secp256 public_key_y");

Check warning on line 695 in compiler/noirc_evaluator/src/ssa/validation/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (secp)

let signature = arguments[2];
let signature_type = dfg.type_of_value(signature);
Expand Down Expand Up @@ -1543,6 +1550,18 @@
let _ = Ssa::from_str(src).unwrap();
}

#[test]
fn make_array_slice_empty_composite_type() {
let src = "
acir(inline) fn main f0 {
b0():
v0 = make_array [] : [()]
return v0
}
";
let _ = Ssa::from_str(src).unwrap();
}

#[test]
#[should_panic(
expected = "MakeArray has incorrect element type at index 1: expected u8, got Field"
Expand Down
6 changes: 6 additions & 0 deletions test_programs/execution_success/regression_10197/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "regression_10197"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index = 1
5 changes: 5 additions & 0 deletions test_programs/execution_success/regression_10197/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main(index: u32) {
let mut slice = &[(0, [1, 2]), (3, [4, 5])];
slice[index] = (6, [7, 8]);
println(slice);
}
6 changes: 6 additions & 0 deletions test_programs/execution_success/regression_10198/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "regression_10198"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index = 1
8 changes: 8 additions & 0 deletions test_programs/execution_success/regression_10198/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main(index: u32) {
let slice: [()] = &[(), (), ()];
println(slice);

let mut slice: [()] = &[(), (), ()];
slice[index] = ();
println(slice);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading