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!: Require types of globals to be specified #6592

Merged
merged 6 commits into from
Nov 22, 2024
Prev Previous commit
Next Next commit
add types to globals in test_programs/benchmark
michaeljklein committed Nov 22, 2024
commit 280c27fbe0cbdc5915204af9cd4809543ce89702
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash::poseidon2;

global SIZE = 100;
global SIZE: u32 = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash::poseidon2;

global SIZE = 30;
global SIZE: u32 = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash;

global SIZE = 100;
global SIZE: u32 = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash;

global SIZE = 30;
global SIZE: u32 = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash;

global SIZE = 100;
global SIZE: u32 = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hash;

global SIZE = 30;
global SIZE: u32 = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
2 changes: 1 addition & 1 deletion test_programs/benchmarks/bench_sha256_100/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global SIZE = 100;
global SIZE: u32 = 100;

fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] {
let mut results: [[u8; 32]; SIZE] = [[0; 32]; SIZE];
2 changes: 1 addition & 1 deletion test_programs/benchmarks/bench_sha256_30/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global SIZE = 30;
global SIZE: u32 = 30;

fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] {
let mut results: [[u8; 32]; SIZE] = [[0; 32]; SIZE];
2 changes: 1 addition & 1 deletion test_programs/benchmarks/bench_sha256_long/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Input size long enough that we have to compress a few times
// and then pad the last block out.
global INPUT_SIZE = 2 * 64 + 60;
global INPUT_SIZE: u32 = 2 * 64 + 60;

fn main(input: [u8; INPUT_SIZE]) -> pub [u8; 32] {
std::hash::sha256(input)

Unchanged files with check annotations Beta

Self::Public => write!(f, "pub"),
Self::Private => write!(f, "priv"),
Self::CallData(id) => write!(f, "calldata{id}"),
Self::ReturnData => write!(f, "returndata"),

Check warning on line 557 in compiler/noirc_frontend/src/ast/mod.rs

GitHub Actions / Code

Unknown word (returndata)
}
}
}
}
// TODO(https://github.com/noir-lang/noir/issues/6238):
// The EvaluatedGlobalIsntU32 warning is a stopgap

Check warning on line 2013 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (Isnt)
// (originally from https://github.com/noir-lang/noir/issues/6125)
#[test]
fn numeric_generic_field_larger_than_u32() {
assert_eq!(errors.len(), 2);
assert!(matches!(
errors[0].0,
CompilationError::TypeError(TypeCheckError::EvaluatedGlobalIsntU32 { .. }),

Check warning on line 2030 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (Isnt)
));
assert!(matches!(
errors[1].0,
}
// TODO(https://github.com/noir-lang/noir/issues/6238):
// The EvaluatedGlobalIsntU32 warning is a stopgap

Check warning on line 2039 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (Isnt)
// (originally from https://github.com/noir-lang/noir/issues/6126)
#[test]
fn numeric_generic_field_arithmetic_larger_than_u32() {
assert!(matches!(
errors[0].0,
CompilationError::TypeError(TypeCheckError::EvaluatedGlobalIsntU32 { .. }),

Check warning on line 2068 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (Isnt)
));
assert!(matches!(
assert_eq!(errors.len(), 3);
// TODO(https://github.com/noir-lang/noir/issues/6238):
// The EvaluatedGlobalIsntU32 warning is a stopgap

Check warning on line 2204 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (Isnt)
assert!(matches!(
errors[0].0,
CompilationError::TypeError(TypeCheckError::EvaluatedGlobalIsntU32 { .. }),
}
#[test]
fn dont_infer_globals_to_u32_from_type_use() {

Check warning on line 3227 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (dont)
let src = r#"
global ARRAY_LEN = 3;
global STR_LEN: _ = 2;
#[test]
fn unconditional_recursion_fail() {
let srcs = vec![

Check warning on line 3489 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
main()
"#,
];
for src in srcs {

Check warning on line 3551 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (srcs)
let errors = get_program_errors(src);
assert!(
!errors.is_empty(),
#[test]
fn unconditional_recursion_pass() {
let srcs = vec![

Check warning on line 3570 in compiler/noirc_frontend/src/tests.rs

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
if false { main(); }