Skip to content

Commit

Permalink
Update build.rs
Browse files Browse the repository at this point in the history
Update comment about why both file lock and mutex are needed.
  • Loading branch information
aakoshh committed Nov 13, 2024
1 parent dd8e8a5 commit b039f8d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "brillig_loop_unroll"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sum = "6"
23 changes: 23 additions & 0 deletions test_programs/execution_success/brillig_loop_unroll/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn main(sum: u32) {
assert(loop(0, 4) == sum);
}

fn loop(from: u32, to: u32) -> u32 {
let mut sum = 0;
for i in from..to {
sum = sum + i;
}
sum
}

// fn plain_loop() -> u32 {
// let mut sum = 0;
// let mut arr = &[];
// sum = sum + 0;
// arr.push_back(sum);
// sum = sum + 1;
// arr.push_back(sum);
// sum = sum + 2;
// arr.push_back(sum);
// sum
// }
9 changes: 5 additions & 4 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ fn generate_test_cases(
}
let test_cases = test_cases.join("\n");

// Locking the Nargo.toml file in the test directory so that we can run tests exclusively.
// NB a Mutex is not enough on CI because we use `cargo nextest` which can run test cases
// in the group in different processes.
// For some reason the file lock alone doesn't seem to do the trick locally.
// We need to isolate test cases in the same group, otherwise they overwrite each other's artifacts.
// On CI we use `cargo nextest`, which runs tests in different processes; for this we use a file lock.

Check warning on line 172 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (nextest)
// Locally we might be using `cargo test`, which run tests in the same process; in this case the file lock
// wouldn't work, becuase the process itself has the lock, and it looks like it can have N instances without

Check warning on line 174 in tooling/nargo_cli/build.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (becuase)
// any problems; for this reason we also use a `Mutex`.
let mutex_name = format! {"TEST_MUTEX_{}", test_name.to_uppercase()};
write!(
test_file,
Expand Down

0 comments on commit b039f8d

Please sign in to comment.