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
8 changes: 4 additions & 4 deletions compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,7 @@ mod control_dependence {
loop_body():
v6 = unchecked_mul v0, v1
v7 = unchecked_mul v6, v0
call f1()
call f1(v7)
v10 = unchecked_add v2, u32 1
jmp loop(v10)
exit():
Expand All @@ -2722,7 +2722,7 @@ mod control_dependence {
v6 = lt v2, v1
jmpif v6 then: b2, else: b3
b2():
call f1()
call f1(v4)
v9 = unchecked_add v2, u32 1
jmp b1(v9)
b3():
Expand Down Expand Up @@ -2750,7 +2750,7 @@ mod control_dependence {
loop_body():
v6 = mul v0, v1
v7 = mul v6, v0
call f1()
call f1(v7)
v10 = unchecked_add v2, u32 1
jmp loop(v10)
exit():
Expand All @@ -2772,7 +2772,7 @@ mod control_dependence {
b0(v0: u32, v1: u32):
v3 = mul v0, v1
v4 = mul v3, v0
call f1()
call f1(v4)
jmp b1(u32 0)
b1(v2: u32):
v8 = lt v2, u32 4
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ mod tests {
jmp b1(v8)
}
acir(inline) fn foo f1 {
b0(v0: &mut Field):
b0(v0: &mut &mut Field):
return
}
";
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/ssa/opt/preprocess_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod tests {
let src = r#"
acir(inline) fn main f0 {
b0():
call f0()
call f0(u32 1, Field 2)
return
}
acir(inline) fn foo f0 {
Expand All @@ -116,7 +116,7 @@ mod tests {
assert_ssa_snapshot!(ssa, @r"
acir(inline) fn main f0 {
b0():
call f1()
call f1(u32 1)
return
}
acir(inline) fn foo f1 {
Expand Down
58 changes: 58 additions & 0 deletions compiler/noirc_evaluator/src/ssa/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,30 +277,30 @@
// signature: [u8; 64],
// message_hash: [u8; N],
// ) -> bool
assert_arguments_length(arguments, 4, "ecdsa_secp_256");

Check warning on line 280 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 286 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 291 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 298 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 303 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];
Expand Down Expand Up @@ -552,6 +552,28 @@
}
Value::Function(func_id) => {
let called_function = &self.ssa.functions[func_id];

let parameter_types = called_function.parameter_types();
assert_eq!(
arguments.len(),
parameter_types.len(),
"Function call to {func_id} expected {} parameters, but got {}",
parameter_types.len(),
arguments.len()
);

for (index, (argument, parameter_type)) in
arguments.iter().zip(parameter_types).enumerate()
{
let argument_type = dfg.type_of_value(*argument);
if argument_type != parameter_type {
panic!(
"Argument #{} to {func_id} has type {parameter_type}, but {argument_type} was given",
index + 1,
);
}
}

if let Some(returns) = called_function.returns() {
let instruction_results = dfg.instruction_results(instruction);
if instruction_results.len() != returns.len() {
Expand Down Expand Up @@ -1116,6 +1138,42 @@
let _ = Ssa::from_str(src).unwrap();
}

#[test]
#[should_panic(expected = "Function call to f1 expected 1 parameters, but got 0")]
fn call_has_wrong_parameter_count() {
let src = "
acir(inline) fn main f0 {
b0():
call f1()
return
}

acir(inline) fn foo f1 {
b0(v0: Field):
return
}
";
let _ = Ssa::from_str(src).unwrap();
}

#[test]
#[should_panic(expected = "Argument #1 to f1 has type Field, but u32 was given")]
fn call_has_wrong_argument_type() {
let src = "
acir(inline) fn main f0 {
b0(v0: u32):
call f1(v0)
return
}

acir(inline) fn foo f1 {
b0(v0: Field):
return
}
";
let _ = Ssa::from_str(src).unwrap();
}

#[test]
#[should_panic(expected = "Function call to f1 expected 2 return values, but got 1")]
fn call_has_wrong_return_count() {
Expand Down
5 changes: 4 additions & 1 deletion compiler/noirc_frontend/src/monomorphization/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use noirc_errors::Location;
use noirc_errors::debug_info::DebugVarId;
use noirc_printable_type::PrintableType;

use crate::ast::IntegerBitSize;
use crate::debug::{SourceFieldId, SourceVarId};
use crate::hir_def::expr::*;
use crate::node_interner::ExprId;
use crate::shared::Signedness;
use crate::signed_field::SignedField;

use super::ast::{Expression, Ident};
Expand Down Expand Up @@ -181,7 +183,8 @@ impl Monomorphizer<'_> {
let value = SignedField::positive(var_id.0);
let var_id_literal = HirLiteral::Integer(value);
let expr_id = self.interner.push_expr(HirExpression::Literal(var_id_literal));
self.interner.push_expr_type(expr_id, crate::Type::FieldElement);
let u32 = crate::Type::Integer(Signedness::Unsigned, IntegerBitSize::ThirtyTwo);
self.interner.push_expr_type(expr_id, u32);
self.interner.push_expr_location(expr_id, *location);
expr_id
}
Expand Down
Loading